This repository was archived by the owner on Nov 24, 2023. It is now read-only.
File tree 1 file changed +19
-3
lines changed
1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -288,14 +288,30 @@ fn apply_suggestion(suggestion: &Suggestion) -> Result<(), ProgramError> {
288
288
. join ( "\n " ) ) ;
289
289
new_content. push_str ( "\n " ) ;
290
290
291
- // TODO(killercup): Replace sections of lines only
292
- new_content. push_str ( & indent ( ( suggestion. line_range . start . column - 1 ) as u32 ,
293
- suggestion. replacement . trim ( ) ) ) ;
291
+ // Parts of line before replacement
292
+ new_content. push_str ( & file_content. lines ( )
293
+ . nth ( suggestion. line_range . start . line - 1 )
294
+ . unwrap_or ( "" )
295
+ . chars ( )
296
+ . take ( suggestion. line_range . start . column - 1 )
297
+ . collect :: < String > ( ) ) ;
298
+
299
+ // Insert new content! Finally!
300
+ new_content. push_str ( & suggestion. replacement ) ;
294
301
302
+ // TODO(killercup): better handling of trailing semicolons
295
303
if suggestion. text . trim ( ) . ends_with ( ';' ) && !suggestion. replacement . trim ( ) . ends_with ( ';' ) {
296
304
new_content. push_str ( ";" ) ;
297
305
}
298
306
307
+ // Parts of line after replacement
308
+ new_content. push_str ( & file_content. lines ( )
309
+ . nth ( suggestion. line_range . end . line - 1 )
310
+ . unwrap_or ( "" )
311
+ . chars ( )
312
+ . skip ( suggestion. line_range . end . column )
313
+ . collect :: < String > ( ) ) ;
314
+
299
315
// Add the lines after the section we want to replace
300
316
new_content. push_str ( "\n " ) ;
301
317
new_content. push_str ( & file_content. lines ( )
You can’t perform that action at this time.
0 commit comments