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

First try at replacing partials lines #7

Merged
merged 3 commits into from
Jul 11, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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