1
Fork 0

Fix suggestions rendering when the span is multiline

This commit is contained in:
CastilloDel 2023-02-04 18:52:27 +01:00
parent 4aa6afa7f8
commit cf0279991d

View file

@ -2175,17 +2175,19 @@ impl EmitterWriter {
file_lines: &FileLines, file_lines: &FileLines,
is_multiline: bool, is_multiline: bool,
) { ) {
// Print the span column to avoid confusion
buffer.puts(*row_num, 0, &self.maybe_anonymized(line_start + line_pos), Style::LineNumber);
if let DisplaySuggestion::Diff = show_code_change { if let DisplaySuggestion::Diff = show_code_change {
// Add the line number for both addition and removal to drive the point home. // Add the line number for both addition and removal to drive the point home.
// //
// N - fn foo<A: T>(bar: A) { // N - fn foo<A: T>(bar: A) {
// N + fn foo(bar: impl T) { // N + fn foo(bar: impl T) {
let number_of_lines = file_lines.lines.len();
for (index, line_to_remove) in
file_lines.lines.iter().take(number_of_lines - 1).enumerate()
{
buffer.puts( buffer.puts(
*row_num - 1, *row_num - 1,
0, 0,
&self.maybe_anonymized(line_start + line_pos), &self.maybe_anonymized(line_start + line_pos + index),
Style::LineNumber, Style::LineNumber,
); );
buffer.puts(*row_num - 1, max_line_num_len + 1, "- ", Style::Removal); buffer.puts(*row_num - 1, max_line_num_len + 1, "- ", Style::Removal);
@ -2193,12 +2195,49 @@ impl EmitterWriter {
*row_num - 1, *row_num - 1,
max_line_num_len + 3, max_line_num_len + 3,
&normalize_whitespace( &normalize_whitespace(
&file_lines.file.get_line(file_lines.lines[line_pos].line_index).unwrap(), &file_lines.file.get_line(line_to_remove.line_index).unwrap(),
), ),
Style::NoStyle, Style::NoStyle,
); );
*row_num += 1;
}
let last_line = &file_lines
.file
.get_line(file_lines.lines[number_of_lines - 1].line_index)
.unwrap();
if last_line != line {
buffer.puts(
*row_num - 1,
0,
&self.maybe_anonymized(line_start + line_pos + number_of_lines - 1),
Style::LineNumber,
);
buffer.puts(*row_num - 1, max_line_num_len + 1, "- ", Style::Removal);
buffer.puts(
*row_num - 1,
max_line_num_len + 3,
&normalize_whitespace(last_line),
Style::NoStyle,
);
buffer.puts(
*row_num,
0,
&self.maybe_anonymized(line_start + line_pos),
Style::LineNumber,
);
buffer.puts(*row_num, max_line_num_len + 1, "+ ", Style::Addition); buffer.puts(*row_num, max_line_num_len + 1, "+ ", Style::Addition);
// print the suggestion
buffer.append(*row_num, &normalize_whitespace(line), Style::NoStyle);
} else {
*row_num -= 2;
}
} else if is_multiline { } else if is_multiline {
buffer.puts(
*row_num,
0,
&self.maybe_anonymized(line_start + line_pos),
Style::LineNumber,
);
match &highlight_parts[..] { match &highlight_parts[..] {
[SubstitutionHighlight { start: 0, end }] if *end == line.len() => { [SubstitutionHighlight { start: 0, end }] if *end == line.len() => {
buffer.puts(*row_num, max_line_num_len + 1, "+ ", Style::Addition); buffer.puts(*row_num, max_line_num_len + 1, "+ ", Style::Addition);
@ -2210,12 +2249,19 @@ impl EmitterWriter {
buffer.puts(*row_num, max_line_num_len + 1, "~ ", Style::Addition); buffer.puts(*row_num, max_line_num_len + 1, "~ ", Style::Addition);
} }
} }
} else {
draw_col_separator(buffer, *row_num, max_line_num_len + 1);
}
// print the suggestion // print the suggestion
buffer.append(*row_num, &normalize_whitespace(line), Style::NoStyle); buffer.append(*row_num, &normalize_whitespace(line), Style::NoStyle);
} else {
buffer.puts(
*row_num,
0,
&self.maybe_anonymized(line_start + line_pos),
Style::LineNumber,
);
draw_col_separator(buffer, *row_num, max_line_num_len + 1);
// print the suggestion
buffer.append(*row_num, &normalize_whitespace(line), Style::NoStyle);
}
// Colorize addition/replacements with green. // Colorize addition/replacements with green.
for &SubstitutionHighlight { start, end } in highlight_parts { for &SubstitutionHighlight { start, end } in highlight_parts {