+
+ fn draw_code_line(
+ &self,
+ buffer: &mut StyledBuffer,
+ row_num: &mut usize,
+ highlight_parts: &Vec<SubstitutionHighlight>,
+ line_pos: usize,
+ line: &str,
+ line_start: usize,
+ show_code_change: DisplaySuggestion,
+ max_line_num_len: usize,
+ file_lines: &FileLines,
+ 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 {
+ // Add the line number for both addition and removal to drive the point home.
+ //
+ // N - fn foo<A: T>(bar: A) {
+ // N + fn foo(bar: impl T) {
+ buffer.puts(
+ *row_num - 1,
+ 0,
+ &self.maybe_anonymized(line_start + line_pos),
+ 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(
+ &*file_lines.file.get_line(file_lines.lines[line_pos].line_index).unwrap(),
+ ),
+ Style::NoStyle,
+ );
+ buffer.puts(*row_num, max_line_num_len + 1, "+ ", Style::Addition);
+ } else if is_multiline {
+ match &highlight_parts[..] {
+ [SubstitutionHighlight { start: 0, end }] if *end == line.len() => {
+ buffer.puts(*row_num, max_line_num_len + 1, "+ ", Style::Addition);
+ }
+ [] => {
+ draw_col_separator(buffer, *row_num, max_line_num_len + 1);
+ }
+ _ => {
+ 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
+ buffer.append(*row_num, &normalize_whitespace(line), Style::NoStyle);
+
+ // Colorize addition/replacements with green.
+ for &SubstitutionHighlight { start, end } in highlight_parts {
+ // Account for tabs when highlighting (#87972).
+ let tabs: usize = line
+ .chars()
+ .take(start)
+ .map(|ch| match ch {
+ '\t' => 3,
+ _ => 0,
+ })
+ .sum();
+ buffer.set_style_range(
+ *row_num,
+ max_line_num_len + 3 + start + tabs,
+ max_line_num_len + 3 + end + tabs,
+ Style::Addition,
+ true,
+ );
+ }
+ *row_num += 1;
+ }
+}
+
+#[derive(Clone, Copy)]
+enum DisplaySuggestion {
+ Underline,
+ Diff,
+ None,