diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-07-07 11:25:17 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-07-07 11:25:17 +0100 |
commit | 687fb031d2b40e5bf8b0748fd855a4d7c39e979a (patch) | |
tree | 7fed2ea080e1ebc9278d29fd5baa46e2b97c7f87 /crates/ra_assists/src/assist_context.rs | |
parent | 0f5d62a3f3b33edadea50ea93c725ac36460c0d7 (diff) | |
parent | 3360118040a84d4f387db1c1d340fcaeeede2976 (diff) |
Merge #5245
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 <[email protected]>
Diffstat (limited to 'crates/ra_assists/src/assist_context.rs')
-rw-r--r-- | crates/ra_assists/src/assist_context.rs | 14 |
1 files changed, 7 insertions, 7 deletions
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 { | |||
176 | edit: TextEditBuilder, | 176 | edit: TextEditBuilder, |
177 | file_id: FileId, | 177 | file_id: FileId, |
178 | is_snippet: bool, | 178 | is_snippet: bool, |
179 | edits: Vec<SourceFileEdit>, | 179 | change: SourceChange, |
180 | } | 180 | } |
181 | 181 | ||
182 | impl AssistBuilder { | 182 | impl AssistBuilder { |
@@ -185,7 +185,7 @@ impl AssistBuilder { | |||
185 | edit: TextEditBuilder::default(), | 185 | edit: TextEditBuilder::default(), |
186 | file_id, | 186 | file_id, |
187 | is_snippet: false, | 187 | is_snippet: false, |
188 | edits: Vec::new(), | 188 | change: SourceChange::default(), |
189 | } | 189 | } |
190 | } | 190 | } |
191 | 191 | ||
@@ -197,8 +197,8 @@ impl AssistBuilder { | |||
197 | let edit = mem::take(&mut self.edit).finish(); | 197 | let edit = mem::take(&mut self.edit).finish(); |
198 | if !edit.is_empty() { | 198 | if !edit.is_empty() { |
199 | let new_edit = SourceFileEdit { file_id: self.file_id, edit }; | 199 | let new_edit = SourceFileEdit { file_id: self.file_id, edit }; |
200 | assert!(!self.edits.iter().any(|it| it.file_id == new_edit.file_id)); | 200 | assert!(!self.change.source_file_edits.iter().any(|it| it.file_id == new_edit.file_id)); |
201 | self.edits.push(new_edit); | 201 | self.change.source_file_edits.push(new_edit); |
202 | } | 202 | } |
203 | } | 203 | } |
204 | 204 | ||
@@ -265,10 +265,10 @@ impl AssistBuilder { | |||
265 | 265 | ||
266 | fn finish(mut self) -> SourceChange { | 266 | fn finish(mut self) -> SourceChange { |
267 | self.commit(); | 267 | self.commit(); |
268 | let mut res: SourceChange = mem::take(&mut self.edits).into(); | 268 | let mut change = mem::take(&mut self.change); |
269 | if self.is_snippet { | 269 | if self.is_snippet { |
270 | res.is_snippet = true; | 270 | change.is_snippet = true; |
271 | } | 271 | } |
272 | res | 272 | change |
273 | } | 273 | } |
274 | } | 274 | } |