Account for removal of multiline span in suggestion#134664
Account for removal of multiline span in suggestion#134664bors merged 1 commit intorust-lang:masterfrom
Conversation
|
r? @Nadrieril rustbot has assigned @Nadrieril. Use |
This comment has been minimized.
This comment has been minimized.
|
r? jieyouxu |
f401572 to
0edaf9a
Compare
This comment has been minimized.
This comment has been minimized.
0edaf9a to
a42e529
Compare
| // too bad to begin with, so we side-step that issue here. | ||
| for (i, line) in snippet.lines().enumerate() { | ||
| let line = normalize_whitespace(line); | ||
| let row = row_num - 2 - (newlines - i - 1); |
There was a problem hiding this comment.
Question [OFFSETS 1/2]: what's the significance of row_num - 2? There's several +/- n in this region of code which are not immediately obvious (modulo the - 1 cases), but this one in particular is somewhat mysterious (at least to me).
There was a problem hiding this comment.
row_num at this point corresponds to
|
LL | CODE
| ++++ <- this row
in the buffer. When we have a diff format output, we end up with
|
LL - OLDER
LL + NEWER
| <- this row
The row_num - 2 is to select the buffer line that has the "old version of the diff" at that point. When the removal is a single line, i is 0, newlines is 1 so (newlines - i - 1) ends up being 0, so row points at LL - OLDER. When the removal corresponds to multiple lines, we end up with newlines > 1 and i being 0..newlines - 1.
|
LL - OLDER
LL - CODE
LL - BEING
LL - REMOVED
LL + NEWER
| <- this row
How should I communicate this better in a comment?
There was a problem hiding this comment.
Honestly? I can't think of any shorter explanation that's also unambiguous. I would just copy-pasta what you said as a comment, even at the risk of the comment becoming outdated. Because until you explained this to me (thank you), I don't think anyone else would've been able to interpret this without extensive local testing...
| } else { | ||
| // The removed code fits all in one line. | ||
| buffer.set_style_range( | ||
| row_num - 2, |
There was a problem hiding this comment.
Question [OFFSETS 2/2]: same here, what's the significance of row_num - 2?
There was a problem hiding this comment.
We can probably unify the two branches. Do note that this is the previously existing code being moved around.
There was a problem hiding this comment.
Yeah I see that, it's just that this one was equally mysterious lol.
| // ignore-tidy-tab | ||
| use std::collections::{HashMap, HashSet}; | ||
| fn foo() -> Vec<(bool, HashSet<u8>)> { | ||
| let mut hm = HashMap::<bool, Vec<HashSet<u8>>>::new(); |
There was a problem hiding this comment.
Question: is there a specific reason why the indents in this file use tabs?
There was a problem hiding this comment.
To ensure that the code normalization logic still kicks in correctly, given that I'm doing length calculations involving the original code. \t gets always replaced with .
There was a problem hiding this comment.
Could you add that as a comment in the test? I imagine someone else who looked at this test might notice the tabs and go "huh?" because other ui tests typically only use spaces for indent purposes.
There was a problem hiding this comment.
Remark: the svg snapshots are very nice :3 The removal span highlighting does indeed look much nicer with the changes in this PR!
|
Thanks, you can r=me after some commit nits. |
a42e529 to
d3d86a3
Compare
This comment has been minimized.
This comment has been minimized.
d3d86a3 to
5c818c3
Compare
|
Thanks! The comments made the logic much easier to follow. |
|
@bors r+ rollup |
…ouxu Account for removal of multiline span in suggestion When highlighting the removed parts of a suggestion, properly account for spans that cover more than one line. Fix rust-lang#134485. 
Rollup of 4 pull requests Successful merges: - rust-lang#134664 (Account for removal of multiline span in suggestion) - rust-lang#134774 (fix default-backtrace-ice test) - rust-lang#134781 (Add more `begin_panic` normalizations to panic backtrace tests) - rust-lang#134784 (Miri subtree update) r? `@ghost` `@rustbot` modify labels: rollup
|
FTR this does not fail locally on msvc for me... |
|
Ok nvm I know exactly what the failure is... it's #132752 that I haven't gotten around to fixing, will take a look tmrw |
|
That's a great find. I can also mark the test as linux only for now. |
When highlighting the removed parts of a suggestion, properly account for spans that cover more than one line. Fix rust-lang#134485.
5c818c3 to
12d66d9
Compare
|
@bors r=jieyouxu |
…llaumeGomez Rollup of 4 pull requests Successful merges: - rust-lang#134656 (Migrate `incr-add-rust-src-component` to rmake) - rust-lang#134664 (Account for removal of multiline span in suggestion) - rust-lang#134772 (Improve/cleanup rustdoc code) - rust-lang#134781 (Add more `begin_panic` normalizations to panic backtrace tests) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#134664 - estebank:sugg-highlighting, r=jieyouxu Account for removal of multiline span in suggestion When highlighting the removed parts of a suggestion, properly account for spans that cover more than one line. Fix rust-lang#134485. 
…ouxu Account for removal of multiline span in suggestion When highlighting the removed parts of a suggestion, properly account for spans that cover more than one line. Fix rust-lang#134485. 
…llaumeGomez Rollup of 4 pull requests Successful merges: - rust-lang#134656 (Migrate `incr-add-rust-src-component` to rmake) - rust-lang#134664 (Account for removal of multiline span in suggestion) - rust-lang#134772 (Improve/cleanup rustdoc code) - rust-lang#134781 (Add more `begin_panic` normalizations to panic backtrace tests) r? `@ghost` `@rustbot` modify labels: rollup
Actually I was wrong, because I looked at the unnormalized svg... The real reason I believe this: I believe we use different colors between Unixes and Windows (Windows have some legacy workarounds to use different bright colors and such because the cmd.exe bright colors are ass). @estebank lol |


When highlighting the removed parts of a suggestion, properly account for spans that cover more than one line.
Fix #134485.