Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upShow multiline spans in full if short enough #37369
Conversation
rust-highfive
assigned
arielb1
Oct 24, 2016
This comment has been minimized.
This comment has been minimized.
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @arielb1 (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
estebank
reviewed
Oct 24, 2016
| // If the span is multi-line, simplify down to the span of one character | ||
| if lo.line != hi.line { | ||
| // If the span is long multi-line, simplify down to the span of one character | ||
| let max_multiline_span_length = 20; |
This comment has been minimized.
This comment has been minimized.
estebank
Oct 24, 2016
Author
Contributor
This will need to be much lower. I propose a value between 5 and 10.
estebank
force-pushed the
estebank:multiline-span
branch
2 times, most recently
from
af0d31c
to
5a81d01
Oct 24, 2016
estebank
referenced this pull request
Oct 24, 2016
Merged
Include type of missing trait methods in error #37370
estebank
force-pushed the
estebank:multiline-span
branch
from
5a81d01
to
3ff63dd
Oct 24, 2016
This comment has been minimized.
This comment has been minimized.
|
Hi there! I think this is nice work but I am unsure if this is the right way. I would suggest to use the box-drawing characters for the lines. This would result in a cleaner look. Like this
|
This comment has been minimized.
This comment has been minimized.
|
@dawirstejeck as per @nikomatsakis in the original PR:
I think it'd be neat if there were a way to probe for unicode awareness and use ascii safe characters or unicode accordingly, but that's beyond the scope of this PR :) |
estebank
force-pushed the
estebank:multiline-span
branch
4 times, most recently
from
6f80da2
to
41c9950
Oct 25, 2016
eddyb
added a commit
to eddyb/rust
that referenced
this pull request
Nov 9, 2016
This comment has been minimized.
This comment has been minimized.
|
Carrying over reviewer from the original PR. Looks like the conclusion there was to close in favor of an internals thread and open up a new one upon reaching consensus. With my reading of the internals thread it looks like we haven't quite reached consensus yet, but @nikomatsakis seems to have been following more closely than I and may know more! @jonathandturner you were also interested in the first PR so you're likely to be interested in this one :) |
rust-highfive
assigned
nikomatsakis
and unassigned
arielb1
Nov 10, 2016
alexcrichton
added
the
T-compiler
label
Nov 10, 2016
This comment has been minimized.
This comment has been minimized.
|
Neat feature! |
nikomatsakis
reviewed
Nov 11, 2016
|
Hmm, so I see that the Let me poke around a bit. I'd love to land this PR and don't want to block it on extensive work to build up a nice unit-testing infrastructure -- on the other hand, I'd feel a lot more comfortable if we could just write down tests for various edge cases (even if they don't occur in rustc...yet). The code seems pretty clean but oveall this formatting logic is easier to verify as a block-box, frankly. |
|
|
||
| // Find overlapping multiline annotations, put them at different depths | ||
| multiline_annotations.sort_by(|a, b| a.1.start_col.cmp(&b.1.start_col)); | ||
| for item in multiline_annotations.clone() { |
This comment has been minimized.
This comment has been minimized.
nikomatsakis
Nov 11, 2016
Contributor
This code confuses me a bit -- why doesn't it have to consider lines at all?
What if the input was like
X0
...
X1
Y0
...
Y1With two multi-line spans stretching from X0..X1 and Y0..Y1... wouldn't that cause it to indent the Y case even though they do not in fact overlap?
I think I would expect this indentation to be done on the basis not of start_col and end_col but rather a (line, col) pair, or something like that.
This comment has been minimized.
This comment has been minimized.
estebank
Nov 15, 2016
Author
Contributor
Only the line needs to be taken into account. I probably just made a mistake here that, as I didn't have any overlapping example to test against, I didn't catch.
This comment has been minimized.
This comment has been minimized.
|
|
||
| let mut max_depth = 0; // max overlapping multiline spans | ||
| for (file, ann) in multiline_annotations { | ||
| if let AnnotationType::Multiline {line_start, line_end, depth} = ann.annotation_type { |
This comment has been minimized.
This comment has been minimized.
nikomatsakis
Nov 11, 2016
Contributor
all the annotations in this vector should be multiline, right? If so, can you add else { panic!("non-multiline annotation inmultiline_annotations!"); } to make this clearer?
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Bah, I didn't get time to finish implementing that test harness. =( The basic idea was just going to be adding some |
This comment has been minimized.
This comment has been minimized.
|
OK, so, I'm sorry I've been letting the perfect be the enemy of the good here. Let's land this PR and hack on a test harness separately. I've been toying with some stuff locally but the setup is kind of a pain so I don't want to block things on it. @bors r+ |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@bors r- Actually, I'd still like to know the answer to this question and have this nit addressed. @estebank, you around? |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis sure thing. I'll update the PR this afternoon. |
This comment has been minimized.
This comment has been minimized.
If you publish branch I can use as a base to help, please let me know. Also, #12182 covers exactly that work, I believe. |
This comment has been minimized.
This comment has been minimized.
|
@estebank ok I got something working in this branch: https://github.com/nikomatsakis/rust/tree/multiline-span In particular, you can just cherry-pick this commit: The tests are all calls to this To run the tests, do |
This comment has been minimized.
This comment has been minimized.
Awesome!
It actually looks exactly how I expected it to look, as in, failing in the exact ways I expected it to be failing :)
I would like to arrive with you to what the appropriate output for this case would be, where the multispans start (or end) both on the same line. I'm thinking something along the lines of:
or
Both cases seem a bit messy, to honest. This might be not as accurate but more composable:
Which for the PR's example would look like:
|
This comment has been minimized.
This comment has been minimized.
Yes, but this is an extreme case. I mostly want us to do "something sensible". I wonder if we can provide a bit of extra info, though, to help people disambiguate, like a number. Something like this (riffing on my preferred variant):
Maybe we only show these if things overlap? |
This comment has been minimized.
This comment has been minimized.
|
Oh, and I removed the |
This comment has been minimized.
This comment has been minimized.
|
I wouldn't worry about the numbers. |
estebank
force-pushed the
estebank:multiline-span
branch
3 times, most recently
from
2dc9cfc
to
935c0df
Nov 22, 2016
estebank
force-pushed the
estebank:multiline-span
branch
from
935c0df
to
eb53ca3
Nov 22, 2016
nikomatsakis
requested changes
Nov 22, 2016
|
Left one suggestion. One other thing I'd like: can you give a test with two disjoint ranges (touching distinct lines)? I confess I didn't read the actual code in detail, but your comments gave me confidence that I could read it if ever I had to. =) The tests seem quite good though. Basically r=me modulo the suggested refactoring and test (and feel free to tell me if you think my suggestion is not a good one). |
| } | ||
|
|
||
| // Find overlapping multiline annotations, put them at different depths | ||
| multiline_annotations.sort_by(|a, b| { |
This comment has been minimized.
This comment has been minimized.
nikomatsakis
Nov 22, 2016
Contributor
Nit: this code might be cleaner if you made a struct for MultilineAnnotation, and then adjusted the enum to wrap the struct. Something like:
enum Annotation {
...
Multiline(MultilineAnnotation),
...
}
struct MultilineAnnotation {
depth: usize,
line_start: usize,
line_end: usize,
}in that case, the type of multiline_annotations can be Vec<MultilineAnnotation>.
| // on a different line as the underline. | ||
| // | ||
| // After this we will have: | ||
| // |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There's some duplication of fields now for this to work, but I don't think it'll make the code any harder to follow.
Other than the issue mentioned above, the suggestion makes sense. |
estebank
force-pushed the
estebank:multiline-span
branch
2 times, most recently
from
1ef8ede
to
d9c370e
Nov 24, 2016
estebank
force-pushed the
estebank:multiline-span
branch
from
d9c370e
to
b7982bb
Nov 24, 2016
nikomatsakis
approved these changes
Nov 29, 2016
This comment has been minimized.
This comment has been minimized.
|
@bors r+ Very nice. |
This comment has been minimized.
This comment has been minimized.
|
|
estebank commentedOct 24, 2016
•
edited
When dealing with multiline spans that span few lines, show the complete span instead of restricting to the first character of the first line.
For example, instead of:
show
The proposal in internals outlines the reasoning behind this.