-
Notifications
You must be signed in to change notification settings - Fork 62
Condense output in presence of multiple suggestions #43
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,6 +139,38 @@ enum AutofixMode { | |
Yolo, | ||
} | ||
|
||
fn prelude(suggestion: &Replacement) { | ||
let snippet = &suggestion.snippet; | ||
if snippet.text.1.is_empty() { | ||
// Check whether this suggestion wants to be inserted before or after another line | ||
let wants_to_be_on_own_line = suggestion.replacement.ends_with('\n') | ||
|| suggestion.replacement.starts_with('\n'); | ||
if wants_to_be_on_own_line { | ||
println!("{}", "Insert line:".yellow().bold()); | ||
} else { | ||
println!("{}", "At:".yellow().bold()); | ||
println!( | ||
"{lead}{text}{tail}", | ||
lead = indent(4, &snippet.text.0), | ||
text = "⍉".red(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's up with the apl functional symbol circle backslash here? Do you mean to convey that the text is empty here? Then: Did you mean to use the empty set—or actually ε? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just wanted a pretty symbol. I would have preferred something like the google maps "you are here" marker. You know. with the pointy bottom and the round top. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. like, ▲ or ▼? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. idc. If you have sth you like, I'll use it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's probably best to use something people actually have in their terminal font… so, v or ^? I don't mind either way There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you want to change it, go ahead, otherwise i'm fine with merging with backslashed circle. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll change it when I get back to a PC. Github web editing on mobile is a pain and would produce many commits ;) |
||
tail = snippet.text.2, | ||
); | ||
println!("{}\n", indent(snippet.text.0.len() as u32, "^").red()); | ||
println!("{}\n", "insert:".yellow().bold()); | ||
} | ||
} else { | ||
println!("{}\n", "Replace:".yellow().bold()); | ||
println!( | ||
"{lead}{text}{tail}\n\n\ | ||
{with}\n", | ||
with = "with:".yellow().bold(), | ||
lead = indent(4, &snippet.text.0), | ||
text = snippet.text.1.red(), | ||
tail = snippet.text.2, | ||
); | ||
} | ||
} | ||
|
||
fn handle_suggestions( | ||
suggestions: Vec<Suggestion>, | ||
mode: AutofixMode, | ||
|
@@ -164,19 +196,28 @@ fn handle_suggestions( | |
let mut i = 0; | ||
for solution in suggestion.solutions.iter() { | ||
println!("\n{}", solution.message); | ||
for suggestion in solution.replacements.iter() { | ||
let snippet = &suggestion.snippet; | ||
println!("[{id}]: {suggestion}\n\n\ | ||
{lead}{text}{tail}\n\n\ | ||
{with}\n\n\ | ||
{replacement}\n", | ||
id = i, | ||
suggestion = "Suggestion - Replace:".yellow().bold(), | ||
lead = indent(4, &snippet.text.0), | ||
text = snippet.text.1.red(), | ||
tail = snippet.text.2, | ||
with = "with:".yellow().bold(), | ||
replacement = indent(4, &suggestion.replacement)); | ||
|
||
// check whether we can squash all suggestions into a list | ||
if solution.replacements.len() > 1 { | ||
let first = solution.replacements[0].clone(); | ||
let all_suggestions_replace_the_same_span = solution | ||
.replacements | ||
.iter() | ||
.all(|s| first.snippet.file_name == s.snippet.file_name | ||
&& first.snippet.line_range == s.snippet.line_range); | ||
if all_suggestions_replace_the_same_span { | ||
prelude(&first); | ||
for suggestion in solution.replacements.iter() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't clippy suggest There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think clippy throws up all kinds of things when used on rustfix. I never used it ;) I should. And I should feel bad for not having it done yet. ... Ah now I remember I wanted to fix rustfix with rustfix, but some clippy suggestions were breaking it. So I wanted to fix those first. I'm probably trapped in a loop |
||
println!("[{}]: {}", i, suggestion.replacement.trim()); | ||
i += 1; | ||
} | ||
continue; | ||
} | ||
} | ||
for suggestion in &solution.replacements { | ||
print!("[{}]: ", i); | ||
prelude(&suggestion); | ||
println!("{}", indent(4, &suggestion.replacement)); | ||
i += 1; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,15 +4,14 @@ | |
[1;34m -->[0m src/controls.rs:245:17-245:78 | ||
|
||
try | ||
[0]: [1;33mSuggestion - Replace:[0m | ||
[0]: [1;33mReplace:[0m | ||
|
||
[31mmem::transmute::<*mut c_void, &mut Box<FnMut(&Button)>>(data)[0m(&button) | ||
|
||
[1;33mwith:[0m | ||
|
||
&mut *(data as *mut Box<FnMut(&Button)>) | ||
|
||
|
||
[1;32m==>[0m [32mWhat do you want to do? [0-9] | [r]eplace | [s]kip | save and [q]uit | [a]bort (without saving)[0m | ||
[1;32m >[0m Suggestion accepted. I'll remember that and apply it later. | ||
|
||
|
@@ -21,15 +20,14 @@ try | |
[1;34m -->[0m src/controls.rs:350:17-350:77 | ||
|
||
try | ||
[0]: [1;33mSuggestion - Replace:[0m | ||
[0]: [1;33mReplace:[0m | ||
|
||
[31mmem::transmute::<*mut c_void, &mut Box<FnMut(&Entry)>>(data)[0m(&entry); | ||
|
||
[1;33mwith:[0m | ||
|
||
&mut *(data as *mut Box<FnMut(&Entry)>) | ||
|
||
|
||
[1;32m==>[0m [32mWhat do you want to do? [0-9] | [r]eplace | [s]kip | save and [q]uit | [a]bort (without saving)[0m | ||
[1;32m >[0m Suggestion accepted. I'll remember that and apply it later. | ||
|
||
|
@@ -38,11 +36,11 @@ try | |
[1;34m -->[0m src/controls.rs:373:5-378:6 | ||
|
||
try this | ||
[0]: [1;33mSuggestion - Replace:[0m | ||
[0]: [1;33mAt:[0m | ||
[31m⍉[0mpub fn new() -> Entry { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fun bug, but this is a clippy bug, so I won't fix it here. Clippy should be placing this suggestion properly. |
||
[31m^[0m | ||
|
||
[31m[0mpub fn new() -> Entry { | ||
|
||
[1;33mwith:[0m | ||
[1;33minsert:[0m | ||
|
||
impl Default for controls::Entry { | ||
fn default() -> Self { | ||
|
@@ -52,7 +50,6 @@ try this | |
|
||
|
||
|
||
|
||
[1;32m==>[0m [32mWhat do you want to do? [0-9] | [r]eplace | [s]kip | save and [q]uit | [a]bort (without saving)[0m | ||
[1;32m >[0m Thanks for playing! | ||
Good work. Let me just apply these 2 changes! | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Memo for later refactoring: Turn
text
from(String, String, String)
intostruct ReplacementText { leading: String, content: String, trailing: String, }