Properly handle removal suggestion rendering

Do not leave a `+ ` line with only whitespace. In reality, the user will want to remove the entire line.
This commit is contained in:
Esteban Küber 2024-07-03 21:03:37 +00:00
parent 9344779f71
commit a06a18a47f
5 changed files with 20 additions and 18 deletions

View File

@ -2273,9 +2273,26 @@ impl HumanEmitter {
&normalize_whitespace(last_line),
Style::NoStyle,
);
buffer.puts(*row_num, 0, &self.maybe_anonymized(line_num), Style::LineNumber);
buffer.puts(*row_num, max_line_num_len + 1, "+ ", Style::Addition);
buffer.append(*row_num, &normalize_whitespace(line_to_add), Style::NoStyle);
if !line_to_add.trim().is_empty() {
// Check if after the removal, the line is left with only whitespace. If so, we
// will not show an "addition" line, as removing the whole line is what the user
// would really want.
// For example, for the following:
// |
// 2 - .await
// 2 + (note the left over whitepsace)
// |
// We really want
// |
// 2 - .await
// |
// *row_num -= 1;
buffer.puts(*row_num, 0, &self.maybe_anonymized(line_num), Style::LineNumber);
buffer.puts(*row_num, max_line_num_len + 1, "+ ", Style::Addition);
buffer.append(*row_num, &normalize_whitespace(line_to_add), Style::NoStyle);
} else {
*row_num -= 1;
}
} else {
*row_num -= 2;
}

View File

@ -86,7 +86,6 @@ LL | dbg!();
help: remove the invocation before committing it to a version control system
|
LL - dbg!();
LL +
|
error: the `dbg!` macro is intended as a debugging tool
@ -146,7 +145,6 @@ LL | expand_to_dbg!();
help: remove the invocation before committing it to a version control system
|
LL - dbg!();
LL +
|
error: the `dbg!` macro is intended as a debugging tool

View File

@ -9,7 +9,6 @@ LL | dbg!();
help: remove the invocation before committing it to a version control system
|
LL - dbg!();
LL +
|
error: the `dbg!` macro is intended as a debugging tool

View File

@ -96,12 +96,10 @@ LL | let (l, r) = "a.b.c".split_once('.').unwrap();
help: remove the `iter` usages
|
LL - let l = iter.next().unwrap();
LL +
|
help: remove the `iter` usages
|
LL - let r = iter.next().unwrap();
LL +
|
error: manual implementation of `split_once`
@ -121,12 +119,10 @@ LL | let (l, r) = "a.b.c".split_once('.')?;
help: remove the `iter` usages
|
LL - let l = iter.next()?;
LL +
|
help: remove the `iter` usages
|
LL - let r = iter.next()?;
LL +
|
error: manual implementation of `rsplit_once`
@ -146,12 +142,10 @@ LL | let (l, r) = "a.b.c".rsplit_once('.').unwrap();
help: remove the `iter` usages
|
LL - let r = iter.next().unwrap();
LL +
|
help: remove the `iter` usages
|
LL - let l = iter.next().unwrap();
LL +
|
error: manual implementation of `rsplit_once`
@ -171,12 +165,10 @@ LL | let (l, r) = "a.b.c".rsplit_once('.')?;
help: remove the `iter` usages
|
LL - let r = iter.next()?;
LL +
|
help: remove the `iter` usages
|
LL - let l = iter.next()?;
LL +
|
error: manual implementation of `split_once`
@ -202,12 +194,10 @@ LL | let (a, b) = "a.b.c".split_once('.').unwrap();
help: remove the `iter` usages
|
LL - let a = iter.next().unwrap();
LL +
|
help: remove the `iter` usages
|
LL - let b = iter.next().unwrap();
LL +
|
error: aborting due to 19 previous errors

View File

@ -64,7 +64,6 @@ LL + let rslt0 = mutex.lock().unwrap().abs();
help: remove separated single usage
|
LL - let rslt0 = lock.abs();
LL +
|
error: temporary with significant `Drop` can be early dropped
@ -88,7 +87,6 @@ LL + mutex.lock().unwrap().clear();
help: remove separated single usage
|
LL - lock.clear();
LL +
|
error: aborting due to 4 previous errors