Skip to content

Commit

Permalink
Merge pull request #7 from killercup/feature/partial-line-replacements
Browse files Browse the repository at this point in the history
Better than nothing I guess
  • Loading branch information
killercup authored Jul 11, 2016
2 parents dd49d9f + 6937912 commit 4eefb06
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,24 @@ fn apply_suggestion(suggestion: &Suggestion) -> Result<(), ProgramError> {
.join("\n"));
new_content.push_str("\n");

// TODO(killercup): Replace sections of lines only
new_content.push_str(&indent((suggestion.line_range.start.column - 1) as u32,
suggestion.replacement.trim()));
// Parts of line before replacement
new_content.push_str(&file_content.lines()
.nth(suggestion.line_range.start.line - 1)
.unwrap_or("")
.chars()
.take(suggestion.line_range.start.column - 1)
.collect::<String>());

if suggestion.text.trim().ends_with(';') && !suggestion.replacement.trim().ends_with(';') {
new_content.push_str(";");
}
// Insert new content! Finally!
new_content.push_str(&suggestion.replacement);

// Parts of line after replacement
new_content.push_str(&file_content.lines()
.nth(suggestion.line_range.end.line - 1)
.unwrap_or("")
.chars()
.skip(suggestion.line_range.end.column - 1)
.collect::<String>());

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

0 comments on commit 4eefb06

Please sign in to comment.