@@ -713,8 +713,7 @@ impl HumanEmitter {
713
713
Style :: LineNumber ,
714
714
) ;
715
715
}
716
- buffer. puts ( line_offset, 0 , & self . maybe_anonymized ( line_index) , Style :: LineNumber ) ;
717
-
716
+ self . draw_line_num ( buffer, line_index, line_offset, width_offset - 3 ) ;
718
717
self . draw_col_separator_no_space ( buffer, line_offset, width_offset - 2 ) ;
719
718
left
720
719
}
@@ -2128,11 +2127,11 @@ impl HumanEmitter {
2128
2127
// Account for a suggestion to completely remove a line(s) with whitespace (#94192).
2129
2128
let line_end = sm. lookup_char_pos ( parts[ 0 ] . span . hi ( ) ) . line ;
2130
2129
for line in line_start..=line_end {
2131
- buffer. puts (
2130
+ self . draw_line_num (
2131
+ & mut buffer,
2132
+ line,
2132
2133
row_num - 1 + line - line_start,
2133
- 0 ,
2134
- & self . maybe_anonymized ( line) ,
2135
- Style :: LineNumber ,
2134
+ max_line_num_len,
2136
2135
) ;
2137
2136
buffer. puts (
2138
2137
row_num - 1 + line - line_start,
@@ -2612,12 +2611,7 @@ impl HumanEmitter {
2612
2611
// For more info: https://github.com/rust-lang/rust/issues/92741
2613
2612
let lines_to_remove = file_lines. lines . iter ( ) . take ( file_lines. lines . len ( ) - 1 ) ;
2614
2613
for ( index, line_to_remove) in lines_to_remove. enumerate ( ) {
2615
- buffer. puts (
2616
- * row_num - 1 ,
2617
- 0 ,
2618
- & self . maybe_anonymized ( line_num + index) ,
2619
- Style :: LineNumber ,
2620
- ) ;
2614
+ self . draw_line_num ( buffer, line_num + index, * row_num - 1 , max_line_num_len) ;
2621
2615
buffer. puts ( * row_num - 1 , max_line_num_len + 1 , "- " , Style :: Removal ) ;
2622
2616
let line = normalize_whitespace (
2623
2617
& file_lines. file . get_line ( line_to_remove. line_index ) . unwrap ( ) ,
@@ -2634,11 +2628,11 @@ impl HumanEmitter {
2634
2628
let last_line_index = file_lines. lines [ file_lines. lines . len ( ) - 1 ] . line_index ;
2635
2629
let last_line = & file_lines. file . get_line ( last_line_index) . unwrap ( ) ;
2636
2630
if last_line != line_to_add {
2637
- buffer. puts (
2631
+ self . draw_line_num (
2632
+ buffer,
2633
+ line_num + file_lines. lines . len ( ) - 1 ,
2638
2634
* row_num - 1 ,
2639
- 0 ,
2640
- & self . maybe_anonymized ( line_num + file_lines. lines . len ( ) - 1 ) ,
2641
- Style :: LineNumber ,
2635
+ max_line_num_len,
2642
2636
) ;
2643
2637
buffer. puts ( * row_num - 1 , max_line_num_len + 1 , "- " , Style :: Removal ) ;
2644
2638
buffer. puts (
@@ -2661,7 +2655,7 @@ impl HumanEmitter {
2661
2655
// 2 - .await
2662
2656
// |
2663
2657
// *row_num -= 1;
2664
- buffer . puts ( * row_num , 0 , & self . maybe_anonymized ( line_num ) , Style :: LineNumber ) ;
2658
+ self . draw_line_num ( buffer , line_num , * row_num , max_line_num_len ) ;
2665
2659
buffer. puts ( * row_num, max_line_num_len + 1 , "+ " , Style :: Addition ) ;
2666
2660
buffer. append ( * row_num, & normalize_whitespace ( line_to_add) , Style :: NoStyle ) ;
2667
2661
} else {
@@ -2671,7 +2665,7 @@ impl HumanEmitter {
2671
2665
* row_num -= 2 ;
2672
2666
}
2673
2667
} else if is_multiline {
2674
- buffer . puts ( * row_num , 0 , & self . maybe_anonymized ( line_num ) , Style :: LineNumber ) ;
2668
+ self . draw_line_num ( buffer , line_num , * row_num , max_line_num_len ) ;
2675
2669
match & highlight_parts {
2676
2670
[ SubstitutionHighlight { start : 0 , end } ] if * end == line_to_add. len ( ) => {
2677
2671
buffer. puts ( * row_num, max_line_num_len + 1 , "+ " , Style :: Addition ) ;
@@ -2702,11 +2696,11 @@ impl HumanEmitter {
2702
2696
Style :: NoStyle ,
2703
2697
) ;
2704
2698
} else if let DisplaySuggestion :: Add = show_code_change {
2705
- buffer . puts ( * row_num , 0 , & self . maybe_anonymized ( line_num ) , Style :: LineNumber ) ;
2699
+ self . draw_line_num ( buffer , line_num , * row_num , max_line_num_len ) ;
2706
2700
buffer. puts ( * row_num, max_line_num_len + 1 , "+ " , Style :: Addition ) ;
2707
2701
buffer. append ( * row_num, & normalize_whitespace ( line_to_add) , Style :: NoStyle ) ;
2708
2702
} else {
2709
- buffer . puts ( * row_num , 0 , & self . maybe_anonymized ( line_num ) , Style :: LineNumber ) ;
2703
+ self . draw_line_num ( buffer , line_num , * row_num , max_line_num_len ) ;
2710
2704
self . draw_col_separator ( buffer, * row_num, max_line_num_len + 1 ) ;
2711
2705
buffer. append ( * row_num, & normalize_whitespace ( line_to_add) , Style :: NoStyle ) ;
2712
2706
}
@@ -3016,6 +3010,22 @@ impl HumanEmitter {
3016
3010
OutputTheme :: Unicode => "…" ,
3017
3011
}
3018
3012
}
3013
+
3014
+ fn draw_line_num (
3015
+ & self ,
3016
+ buffer : & mut StyledBuffer ,
3017
+ line_num : usize ,
3018
+ line_offset : usize ,
3019
+ max_line_num_len : usize ,
3020
+ ) {
3021
+ let line_num = self . maybe_anonymized ( line_num) ;
3022
+ buffer. puts (
3023
+ line_offset,
3024
+ max_line_num_len. saturating_sub ( str_width ( & line_num) ) ,
3025
+ & line_num,
3026
+ Style :: LineNumber ,
3027
+ ) ;
3028
+ }
3019
3029
}
3020
3030
3021
3031
#[ derive( Debug , Clone , Copy ) ]
0 commit comments