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 tabs when highlighting multiline code suggestions #87976

Merged
merged 5 commits into from
Aug 23, 2021

Conversation

estebank
Copy link
Contributor

@estebank estebank commented Aug 12, 2021

Address '\t' case in #87972.

Before:

Screen Shot 2021-08-12 at 8 52 27 AM

After:

Screen Shot 2021-08-12 at 8 52 15 AM

@rust-highfive
Copy link
Collaborator

r? @cjgillot

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 12, 2021
.take(*start)
.map(|ch| match ch {
'\t' => 4,
_ => unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1),
Copy link
Member

@m-ou-se m-ou-se Aug 12, 2021

Choose a reason for hiding this comment

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

I think this should just be 1. Counted in chars and not in columns.

Current nightly:
image

This PR:
image

(The second 'A' is a double-width 'A'.)

Copy link
Contributor Author

@estebank estebank Aug 12, 2021

Choose a reason for hiding this comment

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

Can you verify the current version of the PR against your test cases? Sadly, we don't currently have regression tests for the coloring of the output in our tests :-/

This is what I'm seeing in my local tests:

Screen Shot 2021-08-12 at 12 31 28 PM

Copy link
Member

Choose a reason for hiding this comment

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

Yup, the highlighting looks good now!

Screenshot 2021-08-12 at 21 38 57

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In particular, I want to confirm that the output of the terminal without emoji support you showed here is reasonable (as I fully expect it to be, because it relies on what we were doing for the multiline case, which looks ok in that screenshot).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sadly, now I'm seeing other issues :(

Copy link
Member

Choose a reason for hiding this comment

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

Here's the output in four more terminals:

image

@estebank estebank force-pushed the fix-suggestion-span-coloring branch from 655a555 to 1a519ff Compare August 12, 2021 18:32
@rust-log-analyzer

This comment has been minimized.

@estebank estebank force-pushed the fix-suggestion-span-coloring branch 2 times, most recently from d8fc003 to e86547e Compare August 13, 2021 13:44
@cjgillot
Copy link
Contributor

Can you take care of this PR @m-ou-se?

@m-ou-se m-ou-se assigned m-ou-se and unassigned cjgillot Aug 14, 2021
@estebank estebank force-pushed the fix-suggestion-span-coloring branch from e86547e to 1cfe7c0 Compare August 17, 2021 15:46
@estebank
Copy link
Contributor Author

@m-ou-se do let me know if there's anything left here. I want to avoid this not reaching master before the next beta cutoff.

@m-ou-se m-ou-se added the P-high High priority label Aug 19, 2021
@m-ou-se m-ou-se added this to the 1.56.0 milestone Aug 19, 2021
Copy link
Member

@m-ou-se m-ou-se left a comment

Choose a reason for hiding this comment

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

I found one more (unlikely) edge case (which is not very important, but not hard to fix), and a have a small comment on the code.

r=me either way

compiler/rustc_errors/src/lib.rs Outdated Show resolved Hide resolved
Comment on lines +1692 to +1693
max_line_num_len + 3 + start + tabs,
max_line_num_len + 3 + end + tabs,
Copy link
Member

@m-ou-se m-ou-se Aug 19, 2021

Choose a reason for hiding this comment

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

This assumes the addition/replacement doesn't contain tabs itself. It rarely happens, but it can occur:

image

Here, the entire closure body up to and including the final } is supposed to be highlighted, but i put some tabs in the string literal which broke it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, yes. I assumed that we didn't have tabs in the suggestion because I didn't account for cases where snippets from the user include them :-/

Copy link
Member

Choose a reason for hiding this comment

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

I suppose all cases where user snippets are included should be replaced by multispan suggestions. (This specific one is already fixed by #87958, but I think there's quite a few places left where this happens.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you give me the repro case? I think I fixed this, but the suggestions seem to be doing the right thing for me.

Copy link
Member

@m-ou-se m-ou-se Aug 23, 2021

Choose a reason for hiding this comment

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

With #87958 merged, the test case in the screenshot above doesn't trigger the problem anymore. We'll have to find another case where a bunch of user code gets put verbatim in the suggestion. Grepping for span_to_snippet now. ^^

Copy link
Member

Choose a reason for hiding this comment

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

Found one:

Screenshot 2021-08-23 at 15 59 26

mod a {
    pub const A: String = String::new();
}

fn main() {
    a
    ::	A;
    //^ TAB here
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The current code handles this correctly:

@m-ou-se m-ou-se added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. C-bug Category: This is a bug. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 19, 2021
@estebank estebank force-pushed the fix-suggestion-span-coloring branch from 5398b6b to 8f746d2 Compare August 23, 2021 12:42
@estebank

This comment has been minimized.

@bors

This comment has been minimized.

@bors bors removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Aug 23, 2021
@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Aug 23, 2021
@bors

This comment has been minimized.

@estebank estebank force-pushed the fix-suggestion-span-coloring branch from 8f746d2 to 955e913 Compare August 23, 2021 14:32
@rust-log-analyzer

This comment has been minimized.

@estebank
Copy link
Contributor Author

@bors r=m-ou-se

@bors
Copy link
Contributor

bors commented Aug 23, 2021

📌 Commit 955e913 has been approved by m-ou-se

bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 23, 2021
Rollup of 6 pull requests

Successful merges:

 - rust-lang#87976 (Account for tabs when highlighting multiline code suggestions)
 - rust-lang#88174 (Clarify some wording in Rust 2021 lint docs)
 - rust-lang#88188 (Greatly improve limitation handling on parallel rustdoc GUI test run)
 - rust-lang#88230 (Fix typos “a”→“an”)
 - rust-lang#88232 (Add notes to macro-not-found diagnostics to point out how things with the same name were not a match.)
 - rust-lang#88259 (Do not mark `-Z thir-unsafeck` as unsound anymore)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 70aec8d into rust-lang:master Aug 23, 2021
@camsteffen
Copy link
Contributor

I'm getting this when I run ./x.py test src/tools/clippy (line 345 in this PR diff)

thread 'rustc' panicked at 'attempt to subtract with overflow', compiler/rustc_errors/src/lib.rs:347:47

@estebank
Copy link
Contributor Author

estebank commented Sep 5, 2021

@camsteffen it sounds like there might be a malformed Span involved, where the end is earlier than the end or len is smaller than the Span... Although now that I see it the if might be incorrect (we compare prev_hi and cur_lo but then calculate using cur_hi and cur_lo. What are the steps to reproduce this, just running that command?

@camsteffen
Copy link
Contributor

Yes I am seeing that error on multiple Clippy UI tests just running that command on 4878034 (and probably current master).

@estebank
Copy link
Contributor Author

I wasn't able to reproduce this :-/

@camsteffen
Copy link
Contributor

Well shoot. Must've been an artifact of my local setup. I'm not seeing it either and it hasn't shown up in CI.

@apiraino apiraino removed the P-high High priority label Feb 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. C-bug Category: This is a bug. 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.

8 participants