Skip to content
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

Account for removal of multiline span in suggestion #134664

Merged
merged 1 commit into from
Dec 26, 2024

Conversation

estebank
Copy link
Contributor

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

Fix #134485.

Screenshot of the highlighted output

@rustbot
Copy link
Collaborator

rustbot commented Dec 22, 2024

r? @Nadrieril

rustbot has assigned @Nadrieril.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 22, 2024
@estebank estebank marked this pull request as ready for review December 22, 2024 20:21
@rust-log-analyzer

This comment has been minimized.

@jieyouxu
Copy link
Member

r? jieyouxu

@rustbot rustbot assigned jieyouxu and unassigned Nadrieril Dec 22, 2024
@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The removal highlight does indeed looks much nicer. I left a few questions, but LGTM otherwise.

// 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member

@jieyouxu jieyouxu Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question [OFFSETS 2/2]: same here, what's the significance of row_num - 2?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably unify the two branches. Do note that this is the previously existing code being moved around.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: is there a specific reason why the indents in this file use tabs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 .

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remark: the svg snapshots are very nice :3 The removal span highlighting does indeed look much nicer with the changes in this PR!

@jieyouxu jieyouxu added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. D-diagnostic-infra Diagnostics: Issues that affect all diagnostics, or relate to the diagnostic machinery itself. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 23, 2024
@jieyouxu
Copy link
Member

Thanks, you can r=me after some commit nits.
@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 24, 2024
@rust-log-analyzer

This comment has been minimized.

@jieyouxu
Copy link
Member

Thanks! The comments made the logic much easier to follow.

@jieyouxu
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Dec 26, 2024

📌 Commit 5c818c3 has been approved by jieyouxu

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 26, 2024
jieyouxu added a commit to jieyouxu/rust that referenced this pull request Dec 26, 2024
…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.

![Screenshot of the highlighted output](https://github.com/user-attachments/assets/18bcd9bc-3bec-4b79-a9d7-e4ea4e6289ad)
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 26, 2024
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
@jieyouxu
Copy link
Member

Failed on msvc in rollup.
@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Dec 26, 2024
@jieyouxu
Copy link
Member

FTR this does not fail locally on msvc for me...

@jieyouxu
Copy link
Member

jieyouxu commented Dec 26, 2024

Ok nvm I know exactly what the failure is...

{closure@C:\a\rust\rust\tests\ui\error-emitter\multiline-removal-suggestion.rs:30:10: 30:13}

it's #132752 that I haven't gotten around to fixing, will take a look tmrw

@jieyouxu jieyouxu added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 26, 2024
@estebank
Copy link
Contributor Author

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.
@estebank
Copy link
Contributor Author

@bors r=jieyouxu

@bors
Copy link
Contributor

bors commented Dec 26, 2024

📌 Commit 12d66d9 has been approved by jieyouxu

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 26, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 26, 2024
…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
@bors bors merged commit 88687d4 into rust-lang:master Dec 26, 2024
6 checks passed
@rustbot rustbot added this to the 1.85.0 milestone Dec 26, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Dec 26, 2024
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.

![Screenshot of the highlighted output](https://github.com/user-attachments/assets/18bcd9bc-3bec-4b79-a9d7-e4ea4e6289ad)
poliorcetics pushed a commit to poliorcetics/rust that referenced this pull request Dec 28, 2024
…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.

![Screenshot of the highlighted output](https://github.com/user-attachments/assets/18bcd9bc-3bec-4b79-a9d7-e4ea4e6289ad)
poliorcetics pushed a commit to poliorcetics/rust that referenced this pull request Dec 28, 2024
…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
@jieyouxu
Copy link
Member

jieyouxu commented Jan 8, 2025

Ok nvm I know exactly what the failure is...

Actually I was wrong, because I looked at the unnormalized svg... The real reason I believe this:

Screenshot 2025-01-09 060739

Screenshot 2025-01-09 060749

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
D-diagnostic-infra Diagnostics: Issues that affect all diagnostics, or relate to the diagnostic machinery itself. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong coloring on "consider removing this method call"
6 participants