-
Notifications
You must be signed in to change notification settings - Fork 407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Truncated view for blocks longer than 10 lines #1168
Conversation
@emillon Just to start the discussion about what will be suitable for stanzas longer than 10 lines. |
I saw that elm and bucklescript both use I had a look at how bucklescript does its formatting (see also these tests) and the main points are:
I don't think (2) and (3) are very useful for now, but (1) seems interesting. What are your thoughts on that? |
I agree about (2). I don't think extra context lines will help too much when it comes to these fields as we are able to show the exact stanza that has a problem in most cases. For (3) I'm guessing at some point we might be able to do the same thing that I like the idea of truncating the middle portions as the trailing
|
Yes, that seems right. I agree that there'll probably be a nice synergy with |
@emillon I've tried to come up with an approach to the 1st point discussed above (truncating the portions in the middle) |
3 | (libraries (a | ||
4 | b | ||
5 | c | ||
6 | d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this should be padded with one extra space so that the vertical bars line up with below (this file is a great test 👍 ).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah good catch. I think the problem was that I need to pad the first block of lines with the padding width from the last block of lines for them to line up. I hadn't handled the case that the first four lines might have less digits than the last four 😄
I've updated to take that into account
5 | c | ||
6 | d | ||
|
||
------ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's probably a bit too large, can you align it to just before the position of |
as in your comment before? I'm also curious about using ...
since that's more associated with cutting parts out (and that's what bucklescript uses).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I've updated to use ...
That indeed looks nicer. Also they should now be aligned with the |
$ dune build --root d | ||
File "dune", line 3, characters 13-192: | ||
3 | (libraries (a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I notice that the truncated view always displays 11 lines. This means that 10 lines will be displayed in full, but 11 lines will be displayed with 3 lines missing, while keeping the same number of lines. It's a bit unfortunate. I can see three things that we can do:
- increase the threshold (display more messages in full)
- remove some context lines (e.g. switch to 3)
- remove the empty lines
I think that 3 context lines would be enough, but that's up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd think that there will always be a scenario where we transition from a full stanza to truncated view where we'd see less lines in the truncated version. I think a combination of increasing the threshold and removing some context lines (I agree that 3 should be enough) will be a good start. I'll update later today
src/errors.ml
Outdated
let print_lines ?(trailing_line=false) lines padding_width = | ||
List.iter ~f:(fun (lnum, l) -> | ||
Format.fprintf pp "%*s | %s\n" padding_width lnum l) lines; | ||
if trailing_line then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That boolean parameter is control coupling. You can remove it by extracting a print_ellipsis
function and calling it between the two print_line
call sites below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch. I'll update. It's a leftover from a version I had when I wasn't passing this function the extracted lines
src/errors.ml
Outdated
let line = String.make (padding_width + 2) '.' in | ||
Format.fprintf pp "\n%s\n\n" line | ||
in | ||
if num_lines <= 10 then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about extracting this constant out of this function ? Like let maximum_lines_to_print_in_full
or something. Same goes for the 3
below, you can pull out a let context_lines = 4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point. I'll address this
src/errors.ml
Outdated
(* We need to send the padding width from the last four lines | ||
so the two blocks of lines align if they have different number | ||
of digits in their line numbers *) | ||
let first_four = file_lines path ~start:(start.pos_lnum) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these names are a bit too specific - especially if they end up being 3 lines :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I couldn't think of any better names at that point since start and stop were already taken. I'll rename this 😄
src/errors.ml
Outdated
else | ||
let get_padding lines = | ||
let last_lnum = Option.map ~f:fst (List.last lines) in | ||
Option.value_exn (Option.map ~f:String.length last_lnum) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you call value_exn
on the first option, you'll be able to remove the second Option.map
.
List.iter ~f:(fun (lnum, l) -> | ||
Format.fprintf pp "%*s: %s\n" padding_width lnum l) | ||
lines | ||
else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can solve this after the other comments, but I believe that it's the point where this function has enough logic in it. It should be possible to extract a type that determines how to print a file part:
type display_style =
| No_display
| One_line of int (* line number *)
| Block of int * int (* start, stop *)
Then it's possible to split the large function into one that determines the display style, and one function per display style. As a bonus, things like determining the padding size can be pulled out and factored a bit.
What do you think about that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea. I'll try this after I address the other comments!
Hi Anurag, just checking on this - there's no rush but is there anything that I can help you with? |
Hi! I should have replied earlier!! I had pushed some changes to address all comments apart from adding the new type. I was hoping to get some feedback on that before I refactor to create a new type! I figured you were busy so thought i'd wait 😄 |
Ah, it's good that I checked then :) The changes look good, you can have a go at the new type if you're still up for it! |
I will definitely try to refactor with a new type. I'll be on vacation for a few days so should be able to update with the new type sometime next week. Also, I can update this branch with the latest master later today if you prefer, so there can be a new PR with the refactor to a new type that should be transparent change for the implementation |
As you prefer; either we can merge this now or after, with the refactoring. |
I will update this PR later today after syncing this with master. Maybe we can merge this before to avoid conflicts? The refactor should be transparent to all tests so I can do that next week (we can have a separate issue for that, and I can pick that up) What do you think? |
That works for me! |
@emillon i've updated the PR to be in sync with the current master. |
@anuragsoni make sure to remove the WIP from the title when this is ready |
@rgrinberg done! I don't have access to a computer this weekend so I can't rebase with current master |
Great, I'll rebase and merge. Thanks! |
Signed-off-by: Anurag Soni <anuragsoni.13@gmail.com>
Signed-off-by: Anurag Soni anuragsoni.13@gmail.com