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

Hide irrelevant lines in suggestions to allow for suggestions that are far from each other to be shown #97798

Conversation

WaffleLapkin
Copy link
Member

This is an attempt to fix suggestions one part of which is 6 lines or more far from the first. I've noticed "the problem" (of not showing some parts of the suggestion) here: #97759 (comment).

I'm not sure about the implementation (this big closure is just bad and makes already complicated code even more so), but I want to at least discuss the result.

Here is an example of how this changes the output:

Before:

help: consider enclosing expression in a block
  |
3 ~     'l: { match () { () => break 'l,
4 |
5 |
6 |
7 |
8 |
...

After:

help: consider enclosing expression in a block
  |
3 ~     'l: { match () { () => break 'l,
4 |
...
31|
32~ } };
  |

r? @estebank
@rustbot label +A-diagnostics +A-suggestion-diagnostics

@rustbot rustbot added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` labels Jun 6, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 6, 2022
@rust-log-analyzer

This comment has been minimized.

@estebank
Copy link
Contributor

estebank commented Jun 6, 2022

I'm ok with the results, need to look at the impl, particularly to check that it'll be graceful when handling more than 2 suggested changes in a single suggestion.

Comment on lines 1841 to 1845
let print_line = |line_pos: usize,
line: &str,
highlight_parts: &Vec<SubstitutionHighlight>,
buffer: &mut StyledBuffer,
row_num: &mut usize| {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe moving this to its own method might help with readability.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried, but I'm not sure if it's better, there are a lot of variables / state that needs to be passed around.

@WaffleLapkin WaffleLapkin force-pushed the allow_for_suggestions_that_are_quite_far_away_from_each_other branch from e991594 to 1961d9e Compare June 13, 2022 14:31
draw_col_separator(&mut buffer, row_num, max_line_num_len + 1);
let mut unhighlighted_lines = Vec::new();
for (line_pos, (line, highlight_parts)) in lines.by_ref().zip(highlights).enumerate() {
debug!(%line_pos, %line, ?highlight_parts);
Copy link
Contributor

Choose a reason for hiding this comment

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

First time I see this, what does % do? 🤯

Copy link
Member Author

Choose a reason for hiding this comment

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

It uses Display instead of Debug :D

https://docs.rs/tracing/latest/tracing/#recording-fields

@estebank
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jun 14, 2022

📌 Commit 1961d9e has been approved by estebank

@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 Jun 14, 2022
@estebank
Copy link
Contributor

@WaffleLapkin
Add back MAX_SUGGESTION_HIGHLIGHT_LINES so clippy is happy & buildable

We can modify clippy directly from this repo as well.

@WaffleLapkin
Copy link
Member Author

We can modify clippy directly from this repo as well.

Oh, nice! Didn't know about that.

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jun 15, 2022
…that_are_quite_far_away_from_each_other, r=estebank

Hide irrelevant lines in suggestions to allow for suggestions that are far from each other to be shown

This is an attempt to fix suggestions one part of which is 6 lines or more far from the first. I've noticed "the problem" (of not showing some parts of the suggestion) here: rust-lang#97759 (comment).

I'm not sure about the implementation (this big closure is just bad and makes already complicated code even more so), but I want to at least discuss the result.

Here is an example of how this changes the output:

Before:
```text
help: consider enclosing expression in a block
  |
3 ~     'l: { match () { () => break 'l,
4 |
5 |
6 |
7 |
8 |
...
```

After:
```text
help: consider enclosing expression in a block
  |
3 ~     'l: { match () { () => break 'l,
4 |
...
31|
32~ } };
  |
```

r? `@estebank`
`@rustbot` label +A-diagnostics +A-suggestion-diagnostics
@JohnTitor
Copy link
Member

Failed in rollup: https://github.com/rust-lang/rust/runs/6897040285?check_suite_focus=true
Seems we have to bless clippy tests, @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 Jun 15, 2022
!(a & b) = !a | !b
Previously we only show at most 6 lines of suggestions and, if the
suggestions are more than 6 lines apart, we've just showed ... at the
end. This is probably fine, but quite confusing in my opinion.

This commit is an attempt to show ... in places where there is nothing
to suggest instead, for example:

Before:
```text
help: consider enclosing expression in a block
  |
3 ~     'l: { match () { () => break 'l,
4 |
5 |
6 |
7 |
8 |
...
```

After:
```text
help: consider enclosing expression in a block
  |
3 ~     'l: { match () { () => break 'l,
4 |
...
31|
32~ } };
  |
```
I'm not sure if I succeeded
@WaffleLapkin WaffleLapkin force-pushed the allow_for_suggestions_that_are_quite_far_away_from_each_other branch from 1961d9e to e502b9a Compare June 16, 2022 14:38
@WaffleLapkin
Copy link
Member Author

I think it should be fine now

@JohnTitor
Copy link
Member

@bors r=estebank

@bors
Copy link
Contributor

bors commented Jun 16, 2022

📌 Commit e502b9a has been approved by estebank

@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 Jun 16, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 17, 2022
Rollup of 5 pull requests

Successful merges:

 - rust-lang#95392 (std: Stabilize feature try_reserve_2 )
 - rust-lang#97798 (Hide irrelevant lines in suggestions to allow for suggestions that are far from each other to be shown)
 - rust-lang#97844 (Windows: No panic if function not (yet) available)
 - rust-lang#98013 (Subtype FRU fields first in `type_changing_struct_update`)
 - rust-lang#98191 (Remove the rest of unnecessary `to_string`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 74aa55b into rust-lang:master Jun 17, 2022
@rustbot rustbot added this to the 1.63.0 milestone Jun 17, 2022
@WaffleLapkin WaffleLapkin deleted the allow_for_suggestions_that_are_quite_far_away_from_each_other branch June 17, 2022 15:33
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jun 28, 2022
…suggestion_highlight_lines, r=flip1995

Remove `MAX_SUGGESTION_HIGHLIGHT_LINES`

After rust-lang#97798 the `MAX_SUGGESTION_HIGHLIGHT_LINES` constant doesn't really make sense since we always show full suggestions. This PR removes last usages of the constant and the constant itself.

r? `@flip1995` (this mostly does changes in clippy)
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jun 28, 2022
…suggestion_highlight_lines, r=flip1995

Remove `MAX_SUGGESTION_HIGHLIGHT_LINES`

After rust-lang#97798 the `MAX_SUGGESTION_HIGHLIGHT_LINES` constant doesn't really make sense since we always show full suggestions. This PR removes last usages of the constant and the constant itself.

r? ``@flip1995`` (this mostly does changes in clippy)
flip1995 pushed a commit to flip1995/rust that referenced this pull request Jun 30, 2022
…that_are_quite_far_away_from_each_other, r=estebank

Hide irrelevant lines in suggestions to allow for suggestions that are far from each other to be shown

This is an attempt to fix suggestions one part of which is 6 lines or more far from the first. I've noticed "the problem" (of not showing some parts of the suggestion) here: rust-lang#97759 (comment).

I'm not sure about the implementation (this big closure is just bad and makes already complicated code even more so), but I want to at least discuss the result.

Here is an example of how this changes the output:

Before:
```text
help: consider enclosing expression in a block
  |
3 ~     'l: { match () { () => break 'l,
4 |
5 |
6 |
7 |
8 |
...
```

After:
```text
help: consider enclosing expression in a block
  |
3 ~     'l: { match () { () => break 'l,
4 |
...
31|
32~ } };
  |
```

r? `@estebank`
`@rustbot` label +A-diagnostics +A-suggestion-diagnostics
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` 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.

7 participants