5245: Refactor AssistBuilder to manage a SourceChange r=matklad a=theduke

`AssistBuilder` now managaes a full `SourceChange` instead of a
`Vec<SourceFileEdit>`.

This prepares AssistBuilder to handle creation of new files.


Co-authored-by: Christoph Herzog <chris@theduke.at>
This commit is contained in:
bors[bot] 2020-07-07 10:25:17 +00:00 committed by GitHub
commit 687fb031d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 8 deletions

View file

@ -176,7 +176,7 @@ pub(crate) struct AssistBuilder {
edit: TextEditBuilder,
file_id: FileId,
is_snippet: bool,
edits: Vec<SourceFileEdit>,
change: SourceChange,
}
impl AssistBuilder {
@ -185,7 +185,7 @@ impl AssistBuilder {
edit: TextEditBuilder::default(),
file_id,
is_snippet: false,
edits: Vec::new(),
change: SourceChange::default(),
}
}
@ -197,8 +197,8 @@ impl AssistBuilder {
let edit = mem::take(&mut self.edit).finish();
if !edit.is_empty() {
let new_edit = SourceFileEdit { file_id: self.file_id, edit };
assert!(!self.edits.iter().any(|it| it.file_id == new_edit.file_id));
self.edits.push(new_edit);
assert!(!self.change.source_file_edits.iter().any(|it| it.file_id == new_edit.file_id));
self.change.source_file_edits.push(new_edit);
}
}
@ -265,10 +265,10 @@ impl AssistBuilder {
fn finish(mut self) -> SourceChange {
self.commit();
let mut res: SourceChange = mem::take(&mut self.edits).into();
let mut change = mem::take(&mut self.change);
if self.is_snippet {
res.is_snippet = true;
change.is_snippet = true;
}
res
change
}
}

View file

@ -6,7 +6,7 @@
use ra_db::FileId;
use ra_text_edit::TextEdit;
#[derive(Debug, Clone)]
#[derive(Default, Debug, Clone)]
pub struct SourceChange {
pub source_file_edits: Vec<SourceFileEdit>,
pub file_system_edits: Vec<FileSystemEdit>,