Skip to content

Account for tabs when highlighting multiline code suggestions - #87976

Merged
bors merged 5 commits into
rust-lang:masterfrom
estebank:fix-suggestion-span-coloring
Aug 23, 2021
Merged

Account for tabs when highlighting multiline code suggestions#87976
bors merged 5 commits into
rust-lang:masterfrom
estebank:fix-suggestion-span-coloring

Conversation

@estebank

@estebankestebank commented Aug 12, 2021

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

r? @cjgillot

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

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 12, 2021
Comment threadcompiler/rustc_errors/src/emitter.rs Outdated

@m-ou-sem-ou-seAug 12, 2021

Copy link
Copy Markdown
Member

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

@estebankestebankAug 12, 2021

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

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
Copy Markdown
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
estebankforce-pushed the fix-suggestion-span-coloring branch from 655a555 to 1a519ffCompareAugust 12, 2021 18:32
@rust-log-analyzer

This comment has been minimized.

@estebank
estebankforce-pushed the fix-suggestion-span-coloring branch 2 times, most recently from d8fc003 to e86547eCompareAugust 13, 2021 13:44
@cjgillot

Copy link
Copy Markdown
Contributor

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

@m-ou-sem-ou-se assigned m-ou-se and unassigned cjgillotAug 14, 2021
Comment threadcompiler/rustc_errors/src/lib.rs Outdated
@estebank
estebankforce-pushed the fix-suggestion-span-coloring branch from e86547e to 1cfe7c0CompareAugust 17, 2021 15:46
@estebank

Copy link
Copy Markdown
ContributorAuthor

@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-sem-ou-se added the P-high High priority label Aug 19, 2021
@m-ou-sem-ou-se added this to the 1.56.0 milestone Aug 19, 2021

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

Copy link
Copy Markdown
Member

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

Comment threadcompiler/rustc_errors/src/lib.rs Outdated
Comment threadcompiler/rustc_errors/src/emitter.rs Outdated
Comment on lines 1692 to 1693

@m-ou-sem-ou-seAug 19, 2021

Copy link
Copy Markdown
Member

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
Copy Markdown
ContributorAuthor

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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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.

@m-ou-sem-ou-seAug 23, 2021

Copy link
Copy Markdown
Member

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
Copy Markdown
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 {pubconstA:String = String::new();}fnmain(){
a
::A;//^ TAB here}

Copy link
Copy Markdown
ContributorAuthor

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-sem-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
estebankforce-pushed the fix-suggestion-span-coloring branch from 5398b6b to 8f746d2CompareAugust 23, 2021 12:42
@estebank

This comment has been minimized.

@bors

This comment has been minimized.

@borsbors 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
@borsbors 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
estebankforce-pushed the fix-suggestion-span-coloring branch from 8f746d2 to 955e913CompareAugust 23, 2021 14:32
@rust-log-analyzer

This comment has been minimized.

@estebank

Copy link
Copy Markdown
ContributorAuthor

@bors r=m-ou-se

@bors

bors commented Aug 23, 2021

Copy link
Copy Markdown
Collaborator

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

@m-ou-sem-ou-se mentioned this pull request Aug 23, 2021
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:masterAug 23, 2021
@camsteffen

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

@camsteffen it sounds like there might be a malformed Span involved, where the end is earlier than the end orlen 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
Copy Markdown
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
Copy Markdown
ContributorAuthor

I wasn't able to reproduce this :-/

@camsteffen

Copy link
Copy Markdown
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.

@apirainoapiraino removed the P-high High priority label Feb 8, 2022
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant 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

@estebank@rust-highfive@rust-log-analyzer@cjgillot@bors@camsteffen@m-ou-se@apiraino