@@ -78,9 +78,6 @@ impl Rustfmt {
78
78
NewlineStyle :: Native => native,
79
79
} ;
80
80
81
- let lsp_line_length = |line : & str | line. chars ( ) . map ( char:: len_utf16) . sum ( ) ;
82
- let line_cols: Vec < usize > = input. lines ( ) . map ( lsp_line_length) . collect ( ) ;
83
-
84
81
let output = self . format ( input, cfg) ?;
85
82
let ModifiedLines { chunks } = output. parse ( ) . map_err ( |_| Error :: Failed ) ?;
86
83
@@ -89,23 +86,18 @@ impl Rustfmt {
89
86
. map ( |item| {
90
87
// Rustfmt's line indices are 1-based
91
88
let start_line = u64:: from ( item. line_number_orig ) - 1 ;
92
- let end_line = {
93
- // Could underflow if we don't remove lines and there's only one
94
- let removed = u64:: from ( item. lines_removed ) . saturating_sub ( 1 ) ;
95
- start_line + removed
96
- } ;
97
- let end_col: Option < usize > = line_cols. get ( end_line as usize ) . copied ( ) ;
98
- let end_col: u64 = end_col. map ( |col| col as u64 ) . unwrap_or_else ( u64:: max_value) ;
89
+ let end_line = start_line + u64:: from ( item. lines_removed ) ;
99
90
100
91
TextEdit {
101
92
range : Range {
102
93
start : Position :: new ( start_line, 0 ) ,
103
- // We don't extend the range past the last line because
104
- // sometimes it may not exist, skewing the diff and
105
- // making us add an invalid additional trailing newline.
106
- end : Position :: new ( end_line, end_col) ,
94
+ end : Position :: new ( end_line, 0 ) ,
107
95
} ,
108
- new_text : item. lines . join ( newline) ,
96
+ new_text : item. lines . iter ( ) . fold ( String :: new ( ) , |mut acc, s| {
97
+ acc. push_str ( s) ;
98
+ acc. push_str ( newline) ;
99
+ acc
100
+ } ) ,
109
101
}
110
102
} )
111
103
. collect ( ) )
0 commit comments