aboutsummaryrefslogtreecommitdiff
path: root/crates/assists
diff options
context:
space:
mode:
Diffstat (limited to 'crates/assists')
-rw-r--r--crates/assists/src/assist_context.rs16
-rw-r--r--crates/assists/src/tests.rs19
2 files changed, 12 insertions, 23 deletions
diff --git a/crates/assists/src/assist_context.rs b/crates/assists/src/assist_context.rs
index 91cc63427..de4b32573 100644
--- a/crates/assists/src/assist_context.rs
+++ b/crates/assists/src/assist_context.rs
@@ -10,7 +10,7 @@ use ide_db::{
10}; 10};
11use ide_db::{ 11use ide_db::{
12 label::Label, 12 label::Label,
13 source_change::{FileSystemEdit, SourceChange, SourceFileEdit}, 13 source_change::{FileSystemEdit, SourceChange, SourceFileEdits},
14 RootDatabase, 14 RootDatabase,
15}; 15};
16use syntax::{ 16use syntax::{
@@ -181,7 +181,7 @@ pub(crate) struct AssistBuilder {
181 edit: TextEditBuilder, 181 edit: TextEditBuilder,
182 file_id: FileId, 182 file_id: FileId,
183 is_snippet: bool, 183 is_snippet: bool,
184 source_file_edits: Vec<SourceFileEdit>, 184 source_file_edits: SourceFileEdits,
185 file_system_edits: Vec<FileSystemEdit>, 185 file_system_edits: Vec<FileSystemEdit>,
186} 186}
187 187
@@ -191,7 +191,7 @@ impl AssistBuilder {
191 edit: TextEdit::builder(), 191 edit: TextEdit::builder(),
192 file_id, 192 file_id,
193 is_snippet: false, 193 is_snippet: false,
194 source_file_edits: Vec::default(), 194 source_file_edits: SourceFileEdits::default(),
195 file_system_edits: Vec::default(), 195 file_system_edits: Vec::default(),
196 } 196 }
197 } 197 }
@@ -204,15 +204,7 @@ impl AssistBuilder {
204 fn commit(&mut self) { 204 fn commit(&mut self) {
205 let edit = mem::take(&mut self.edit).finish(); 205 let edit = mem::take(&mut self.edit).finish();
206 if !edit.is_empty() { 206 if !edit.is_empty() {
207 match self.source_file_edits.binary_search_by_key(&self.file_id, |edit| edit.file_id) { 207 self.source_file_edits.insert(self.file_id, edit);
208 Ok(idx) => self.source_file_edits[idx]
209 .edit
210 .union(edit)
211 .expect("overlapping edits for same file"),
212 Err(idx) => self
213 .source_file_edits
214 .insert(idx, SourceFileEdit { file_id: self.file_id, edit }),
215 }
216 } 208 }
217 } 209 }
218 210
diff --git a/crates/assists/src/tests.rs b/crates/assists/src/tests.rs
index fef29a0b8..d13d6ad31 100644
--- a/crates/assists/src/tests.rs
+++ b/crates/assists/src/tests.rs
@@ -80,10 +80,8 @@ fn check_doc_test(assist_id: &str, before: &str, after: &str) {
80 let actual = { 80 let actual = {
81 let source_change = assist.source_change.unwrap(); 81 let source_change = assist.source_change.unwrap();
82 let mut actual = before; 82 let mut actual = before;
83 for source_file_edit in source_change.source_file_edits { 83 if let Some(source_file_edit) = source_change.source_file_edits.edits.get(&file_id) {
84 if source_file_edit.file_id == file_id { 84 source_file_edit.apply(&mut actual);
85 source_file_edit.edit.apply(&mut actual)
86 }
87 } 85 }
88 actual 86 actual
89 }; 87 };
@@ -116,20 +114,19 @@ fn check(handler: Handler, before: &str, expected: ExpectedResult, assist_label:
116 114
117 match (assist, expected) { 115 match (assist, expected) {
118 (Some(assist), ExpectedResult::After(after)) => { 116 (Some(assist), ExpectedResult::After(after)) => {
119 let mut source_change = assist.source_change.unwrap(); 117 let source_change = assist.source_change.unwrap();
120 assert!(!source_change.source_file_edits.is_empty()); 118 assert!(!source_change.source_file_edits.is_empty());
121 let skip_header = source_change.source_file_edits.len() == 1 119 let skip_header = source_change.source_file_edits.len() == 1
122 && source_change.file_system_edits.len() == 0; 120 && source_change.file_system_edits.len() == 0;
123 source_change.source_file_edits.sort_by_key(|it| it.file_id);
124 121
125 let mut buf = String::new(); 122 let mut buf = String::new();
126 for source_file_edit in source_change.source_file_edits { 123 for (file_id, edit) in source_change.source_file_edits.edits {
127 let mut text = db.file_text(source_file_edit.file_id).as_ref().to_owned(); 124 let mut text = db.file_text(file_id).as_ref().to_owned();
128 source_file_edit.edit.apply(&mut text); 125 edit.apply(&mut text);
129 if !skip_header { 126 if !skip_header {
130 let sr = db.file_source_root(source_file_edit.file_id); 127 let sr = db.file_source_root(file_id);
131 let sr = db.source_root(sr); 128 let sr = db.source_root(sr);
132 let path = sr.path_for_file(&source_file_edit.file_id).unwrap(); 129 let path = sr.path_for_file(&file_id).unwrap();
133 format_to!(buf, "//- {}\n", path) 130 format_to!(buf, "//- {}\n", path)
134 } 131 }
135 buf.push_str(&text); 132 buf.push_str(&text);