Skip to content
This repository was archived by the owner on Nov 24, 2023. It is now read-only.

Commit 4eefb06

Browse files
authored
Merge pull request #7 from killercup/feature/partial-line-replacements
Better than nothing I guess
2 parents dd49d9f + 6937912 commit 4eefb06

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/main.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,24 @@ fn apply_suggestion(suggestion: &Suggestion) -> Result<(), ProgramError> {
288288
.join("\n"));
289289
new_content.push_str("\n");
290290

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>());
294298

295-
if suggestion.text.trim().ends_with(';') && !suggestion.replacement.trim().ends_with(';') {
296-
new_content.push_str(";");
297-
}
299+
// Insert new content! Finally!
300+
new_content.push_str(&suggestion.replacement);
301+
302+
// Parts of line after replacement
303+
new_content.push_str(&file_content.lines()
304+
.nth(suggestion.line_range.end.line - 1)
305+
.unwrap_or("")
306+
.chars()
307+
.skip(suggestion.line_range.end.column - 1)
308+
.collect::<String>());
298309

299310
// Add the lines after the section we want to replace
300311
new_content.push_str("\n");

0 commit comments

Comments
 (0)