From 3360118040a84d4f387db1c1d340fcaeeede2976 Mon Sep 17 00:00:00 2001 From: Christoph Herzog Date: Tue, 7 Jul 2020 12:10:18 +0200 Subject: Refactor AssistBuilder to manage a SourceChange `AssistBuilder`` now managaes a full `SourceChange` instead of a Vec. This prepares AssistBuilder to handle creation of new files. --- crates/ra_assists/src/assist_context.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'crates/ra_assists/src') diff --git a/crates/ra_assists/src/assist_context.rs b/crates/ra_assists/src/assist_context.rs index 3640bb4d2..c33525363 100644 --- a/crates/ra_assists/src/assist_context.rs +++ b/crates/ra_assists/src/assist_context.rs @@ -176,7 +176,7 @@ pub(crate) struct AssistBuilder { edit: TextEditBuilder, file_id: FileId, is_snippet: bool, - edits: Vec, + 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 } } -- cgit v1.2.3