diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/assists/src/assist_context.rs | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/crates/assists/src/assist_context.rs b/crates/assists/src/assist_context.rs index d11fee196..a1c0550e4 100644 --- a/crates/assists/src/assist_context.rs +++ b/crates/assists/src/assist_context.rs | |||
@@ -205,7 +205,7 @@ pub(crate) struct AssistBuilder { | |||
205 | edit: TextEditBuilder, | 205 | edit: TextEditBuilder, |
206 | file_id: FileId, | 206 | file_id: FileId, |
207 | is_snippet: bool, | 207 | is_snippet: bool, |
208 | change: SourceChange, | 208 | source_file_edits: Vec<SourceFileEdit>, |
209 | } | 209 | } |
210 | 210 | ||
211 | impl AssistBuilder { | 211 | impl AssistBuilder { |
@@ -214,20 +214,27 @@ impl AssistBuilder { | |||
214 | edit: TextEdit::builder(), | 214 | edit: TextEdit::builder(), |
215 | file_id, | 215 | file_id, |
216 | is_snippet: false, | 216 | is_snippet: false, |
217 | change: SourceChange::default(), | 217 | source_file_edits: Vec::default(), |
218 | } | 218 | } |
219 | } | 219 | } |
220 | 220 | ||
221 | pub(crate) fn edit_file(&mut self, file_id: FileId) { | 221 | pub(crate) fn edit_file(&mut self, file_id: FileId) { |
222 | self.commit(); | ||
222 | self.file_id = file_id; | 223 | self.file_id = file_id; |
223 | } | 224 | } |
224 | 225 | ||
225 | fn commit(&mut self) { | 226 | fn commit(&mut self) { |
226 | let edit = mem::take(&mut self.edit).finish(); | 227 | let edit = mem::take(&mut self.edit).finish(); |
227 | if !edit.is_empty() { | 228 | if !edit.is_empty() { |
228 | let new_edit = SourceFileEdit { file_id: self.file_id, edit }; | 229 | match self.source_file_edits.binary_search_by_key(&self.file_id, |edit| edit.file_id) { |
229 | assert!(!self.change.source_file_edits.iter().any(|it| it.file_id == new_edit.file_id)); | 230 | Ok(idx) => self.source_file_edits[idx] |
230 | self.change.source_file_edits.push(new_edit); | 231 | .edit |
232 | .union(edit) | ||
233 | .expect("overlapping edits for same file"), | ||
234 | Err(idx) => self | ||
235 | .source_file_edits | ||
236 | .insert(idx, SourceFileEdit { file_id: self.file_id, edit }), | ||
237 | } | ||
231 | } | 238 | } |
232 | } | 239 | } |
233 | 240 | ||
@@ -280,10 +287,10 @@ impl AssistBuilder { | |||
280 | 287 | ||
281 | fn finish(mut self) -> SourceChange { | 288 | fn finish(mut self) -> SourceChange { |
282 | self.commit(); | 289 | self.commit(); |
283 | let mut change = mem::take(&mut self.change); | 290 | SourceChange { |
284 | if self.is_snippet { | 291 | source_file_edits: mem::take(&mut self.source_file_edits), |
285 | change.is_snippet = true; | 292 | file_system_edits: Default::default(), |
293 | is_snippet: self.is_snippet, | ||
286 | } | 294 | } |
287 | change | ||
288 | } | 295 | } |
289 | } | 296 | } |