@@ -78,9 +78,6 @@ impl Rustfmt {
7878 NewlineStyle :: Native => native,
7979 } ;
8080
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-
8481 let output = self . format ( input, cfg) ?;
8582 let ModifiedLines { chunks } = output. parse ( ) . map_err ( |_| Error :: Failed ) ?;
8683
@@ -89,23 +86,18 @@ impl Rustfmt {
8986 . map ( |item| {
9087 // Rustfmt's line indices are 1-based
9188 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 ) ;
9990
10091 TextEdit {
10192 range : Range {
10293 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 ) ,
10795 } ,
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+ } ) ,
109101 }
110102 } )
111103 . collect ( ) )
0 commit comments