Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

Commit

Permalink
Merge #43
Browse files Browse the repository at this point in the history
43: Condense output in presence of multiple suggestions r=killercup a=oli-obk

part of #41
  • Loading branch information
bors[bot] committed Nov 10, 2017
2 parents e339c48 + a601912 commit 2ef7bcc
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 429 deletions.
67 changes: 54 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "v".red(),
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,
Expand All @@ -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() {
println!("[{}]: {}", i, suggestion.replacement.trim());
i += 1;
}
continue;
}
}
for suggestion in &solution.replacements {
print!("[{}]: ", i);
prelude(&suggestion);
println!("{}", indent(4, &suggestion.replacement));
i += 1;
}
}
Expand Down
19 changes: 8 additions & 11 deletions tests/tests/libui-rs/simple/output.txt
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@


Info: transmute from a pointer type (`*mut libc::c_void`) to a reference type (`&mut std::boxed::Box<for<'r> std::ops::FnMut(&'r controls::Button)>`)
Info: transmute from a pointer type (`*mut libc::c_void`) to a reference type (`&mut std::boxed::Box<for<'r> bitflags::<unnamed>::ops::FnMut(&'r controls::Button)>`)
 --> src/controls.rs:245:17-245:78

try
[0]: Suggestion - Replace:
[0]: Replace:

mem::transmute::<*mut c_void, &mut Box<FnMut(&Button)>>(data)(&button)

with:

&mut *(data as *mut Box<FnMut(&Button)>)


==> What do you want to do? [0-9] | [r]eplace | [s]kip | save and [q]uit | [a]bort (without saving)
 > Suggestion accepted. I'll remember that and apply it later.


Info: transmute from a pointer type (`*mut libc::c_void`) to a reference type (`&mut std::boxed::Box<for<'r> std::ops::FnMut(&'r controls::Entry)>`)
Info: transmute from a pointer type (`*mut libc::c_void`) to a reference type (`&mut std::boxed::Box<for<'r> bitflags::<unnamed>::ops::FnMut(&'r controls::Entry)>`)
 --> src/controls.rs:350:17-350:77

try
[0]: Suggestion - Replace:
[0]: Replace:

mem::transmute::<*mut c_void, &mut Box<FnMut(&Entry)>>(data)(&entry);

with:

&mut *(data as *mut Box<FnMut(&Entry)>)


==> What do you want to do? [0-9] | [r]eplace | [s]kip | save and [q]uit | [a]bort (without saving)
 > Suggestion accepted. I'll remember that and apply it later.

Expand All @@ -38,11 +36,11 @@ try
 --> src/controls.rs:373:5-378:6

try this
[0]: Suggestion - Replace:
[0]: At:
vpub fn new() -> Entry {
^

pub fn new() -> Entry {

with:
insert:

impl Default for controls::Entry {
fn default() -> Self {
Expand All @@ -52,7 +50,6 @@ try this




==> What do you want to do? [0-9] | [r]eplace | [s]kip | save and [q]uit | [a]bort (without saving)
 > Thanks for playing!
Good work. Let me just apply these 2 changes!
Expand Down
19 changes: 8 additions & 11 deletions tests/tests/libui-rs/skipping/output.txt
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@


Info: transmute from a pointer type (`*mut libc::c_void`) to a reference type (`&mut std::boxed::Box<for<'r> std::ops::FnMut(&'r controls::Button)>`)
Info: transmute from a pointer type (`*mut libc::c_void`) to a reference type (`&mut std::boxed::Box<for<'r> bitflags::<unnamed>::ops::FnMut(&'r controls::Button)>`)
 --> src/controls.rs:245:17-245:78

try
[0]: Suggestion - Replace:
[0]: Replace:

mem::transmute::<*mut c_void, &mut Box<FnMut(&Button)>>(data)(&button)

with:

&mut *(data as *mut Box<FnMut(&Button)>)


==> What do you want to do? [0-9] | [r]eplace | [s]kip | save and [q]uit | [a]bort (without saving)
 > Suggestion accepted. I'll remember that and apply it later.


Info: transmute from a pointer type (`*mut libc::c_void`) to a reference type (`&mut std::boxed::Box<for<'r> std::ops::FnMut(&'r controls::Entry)>`)
Info: transmute from a pointer type (`*mut libc::c_void`) to a reference type (`&mut std::boxed::Box<for<'r> bitflags::<unnamed>::ops::FnMut(&'r controls::Entry)>`)
 --> src/controls.rs:350:17-350:77

try
[0]: Suggestion - Replace:
[0]: Replace:

mem::transmute::<*mut c_void, &mut Box<FnMut(&Entry)>>(data)(&entry);

with:

&mut *(data as *mut Box<FnMut(&Entry)>)


==> What do you want to do? [0-9] | [r]eplace | [s]kip | save and [q]uit | [a]bort (without saving)
 > Skipped.

Expand All @@ -38,11 +36,11 @@ try
 --> src/controls.rs:373:5-378:6

try this
[0]: Suggestion - Replace:
[0]: At:
vpub fn new() -> Entry {
^

pub fn new() -> Entry {

with:
insert:

impl Default for controls::Entry {
fn default() -> Self {
Expand All @@ -52,7 +50,6 @@ try this




==> What do you want to do? [0-9] | [r]eplace | [s]kip | save and [q]uit | [a]bort (without saving)
 > Thanks for playing!
Good work. Let me just apply these 1 changes!
Expand Down
Loading

0 comments on commit 2ef7bcc

Please sign in to comment.