diff options
Diffstat (limited to 'crates/completion/src/item.rs')
-rw-r--r-- | crates/completion/src/item.rs | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/crates/completion/src/item.rs b/crates/completion/src/item.rs index 675cef8c4..3bfee1b3f 100644 --- a/crates/completion/src/item.rs +++ b/crates/completion/src/item.rs | |||
@@ -204,7 +204,7 @@ impl CompletionItem { | |||
204 | trigger_call_info: None, | 204 | trigger_call_info: None, |
205 | score: None, | 205 | score: None, |
206 | ref_match: None, | 206 | ref_match: None, |
207 | import_data: None, | 207 | import_to_add: None, |
208 | } | 208 | } |
209 | } | 209 | } |
210 | 210 | ||
@@ -258,13 +258,21 @@ impl CompletionItem { | |||
258 | } | 258 | } |
259 | } | 259 | } |
260 | 260 | ||
261 | /// An extra import to add after the completion is applied. | ||
262 | #[derive(Clone)] | ||
263 | pub(crate) struct ImportToAdd { | ||
264 | pub(crate) import_path: ModPath, | ||
265 | pub(crate) import_scope: ImportScope, | ||
266 | pub(crate) merge_behaviour: Option<MergeBehaviour>, | ||
267 | } | ||
268 | |||
261 | /// A helper to make `CompletionItem`s. | 269 | /// A helper to make `CompletionItem`s. |
262 | #[must_use] | 270 | #[must_use] |
263 | #[derive(Clone)] | 271 | #[derive(Clone)] |
264 | pub(crate) struct Builder { | 272 | pub(crate) struct Builder { |
265 | source_range: TextRange, | 273 | source_range: TextRange, |
266 | completion_kind: CompletionKind, | 274 | completion_kind: CompletionKind, |
267 | import_data: Option<(ModPath, ImportScope, Option<MergeBehaviour>)>, | 275 | import_to_add: Option<ImportToAdd>, |
268 | label: String, | 276 | label: String, |
269 | insert_text: Option<String>, | 277 | insert_text: Option<String>, |
270 | insert_text_format: InsertTextFormat, | 278 | insert_text_format: InsertTextFormat, |
@@ -288,9 +296,9 @@ impl Builder { | |||
288 | let mut insert_text = self.insert_text; | 296 | let mut insert_text = self.insert_text; |
289 | let mut text_edits = TextEdit::builder(); | 297 | let mut text_edits = TextEdit::builder(); |
290 | 298 | ||
291 | if let Some((import_path, import_scope, merge_behaviour)) = self.import_data { | 299 | if let Some(import_data) = self.import_to_add { |
292 | let import = mod_path_to_ast(&import_path); | 300 | let import = mod_path_to_ast(&import_data.import_path); |
293 | let mut import_path_without_last_segment = import_path; | 301 | let mut import_path_without_last_segment = import_data.import_path; |
294 | let _ = import_path_without_last_segment.segments.pop(); | 302 | let _ = import_path_without_last_segment.segments.pop(); |
295 | 303 | ||
296 | if !import_path_without_last_segment.segments.is_empty() { | 304 | if !import_path_without_last_segment.segments.is_empty() { |
@@ -303,7 +311,11 @@ impl Builder { | |||
303 | label = format!("{}::{}", import_path_without_last_segment, label); | 311 | label = format!("{}::{}", import_path_without_last_segment, label); |
304 | } | 312 | } |
305 | 313 | ||
306 | let rewriter = insert_use::insert_use(&import_scope, import, merge_behaviour); | 314 | let rewriter = insert_use::insert_use( |
315 | &import_data.import_scope, | ||
316 | import, | ||
317 | import_data.merge_behaviour, | ||
318 | ); | ||
307 | if let Some(old_ast) = rewriter.rewrite_root() { | 319 | if let Some(old_ast) = rewriter.rewrite_root() { |
308 | algo::diff(&old_ast, &rewriter.rewrite(&old_ast)).into_text_edit(&mut text_edits); | 320 | algo::diff(&old_ast, &rewriter.rewrite(&old_ast)).into_text_edit(&mut text_edits); |
309 | } | 321 | } |
@@ -395,11 +407,8 @@ impl Builder { | |||
395 | self.trigger_call_info = Some(true); | 407 | self.trigger_call_info = Some(true); |
396 | self | 408 | self |
397 | } | 409 | } |
398 | pub(crate) fn import_data( | 410 | pub(crate) fn add_import(mut self, import_to_add: Option<ImportToAdd>) -> Builder { |
399 | mut self, | 411 | self.import_to_add = import_to_add; |
400 | import_data: Option<(ModPath, ImportScope, Option<MergeBehaviour>)>, | ||
401 | ) -> Builder { | ||
402 | self.import_data = import_data; | ||
403 | self | 412 | self |
404 | } | 413 | } |
405 | pub(crate) fn set_ref_match( | 414 | pub(crate) fn set_ref_match( |