diff options
Diffstat (limited to 'crates/ide_completion')
-rw-r--r-- | crates/ide_completion/src/item.rs | 11 | ||||
-rw-r--r-- | crates/ide_completion/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ide_completion/src/test_utils.rs | 3 |
3 files changed, 7 insertions, 9 deletions
diff --git a/crates/ide_completion/src/item.rs b/crates/ide_completion/src/item.rs index 884711f11..9b2435c4b 100644 --- a/crates/ide_completion/src/item.rs +++ b/crates/ide_completion/src/item.rs | |||
@@ -5,7 +5,7 @@ use std::fmt; | |||
5 | use hir::{Documentation, ModPath, Mutability}; | 5 | use hir::{Documentation, ModPath, Mutability}; |
6 | use ide_db::{ | 6 | use ide_db::{ |
7 | helpers::{ | 7 | helpers::{ |
8 | insert_use::{self, ImportScope, MergeBehavior}, | 8 | insert_use::{self, ImportScope, InsertUseConfig}, |
9 | mod_path_to_ast, SnippetCap, | 9 | mod_path_to_ast, SnippetCap, |
10 | }, | 10 | }, |
11 | SymbolKind, | 11 | SymbolKind, |
@@ -280,14 +280,11 @@ pub struct ImportEdit { | |||
280 | impl ImportEdit { | 280 | impl ImportEdit { |
281 | /// Attempts to insert the import to the given scope, producing a text edit. | 281 | /// Attempts to insert the import to the given scope, producing a text edit. |
282 | /// May return no edit in edge cases, such as scope already containing the import. | 282 | /// May return no edit in edge cases, such as scope already containing the import. |
283 | pub fn to_text_edit(&self, merge_behavior: Option<MergeBehavior>) -> Option<TextEdit> { | 283 | pub fn to_text_edit(&self, cfg: InsertUseConfig) -> Option<TextEdit> { |
284 | let _p = profile::span("ImportEdit::to_text_edit"); | 284 | let _p = profile::span("ImportEdit::to_text_edit"); |
285 | 285 | ||
286 | let rewriter = insert_use::insert_use( | 286 | let rewriter = |
287 | &self.import_scope, | 287 | insert_use::insert_use(&self.import_scope, mod_path_to_ast(&self.import_path), cfg); |
288 | mod_path_to_ast(&self.import_path), | ||
289 | merge_behavior, | ||
290 | ); | ||
291 | let old_ast = rewriter.rewrite_root()?; | 288 | let old_ast = rewriter.rewrite_root()?; |
292 | let mut import_insert = TextEdit::builder(); | 289 | let mut import_insert = TextEdit::builder(); |
293 | algo::diff(&old_ast, &rewriter.rewrite(&old_ast)).into_text_edit(&mut import_insert); | 290 | algo::diff(&old_ast, &rewriter.rewrite(&old_ast)).into_text_edit(&mut import_insert); |
diff --git a/crates/ide_completion/src/lib.rs b/crates/ide_completion/src/lib.rs index 76f31de9e..b0b809791 100644 --- a/crates/ide_completion/src/lib.rs +++ b/crates/ide_completion/src/lib.rs | |||
@@ -156,7 +156,7 @@ pub fn resolve_completion_edits( | |||
156 | .find(|mod_path| mod_path.to_string() == full_import_path)?; | 156 | .find(|mod_path| mod_path.to_string() == full_import_path)?; |
157 | 157 | ||
158 | ImportEdit { import_path, import_scope, import_for_trait_assoc_item } | 158 | ImportEdit { import_path, import_scope, import_for_trait_assoc_item } |
159 | .to_text_edit(config.insert_use.merge) | 159 | .to_text_edit(config.insert_use) |
160 | .map(|edit| vec![edit]) | 160 | .map(|edit| vec![edit]) |
161 | } | 161 | } |
162 | 162 | ||
diff --git a/crates/ide_completion/src/test_utils.rs b/crates/ide_completion/src/test_utils.rs index baff83305..9da844031 100644 --- a/crates/ide_completion/src/test_utils.rs +++ b/crates/ide_completion/src/test_utils.rs | |||
@@ -25,6 +25,7 @@ pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig { | |||
25 | insert_use: InsertUseConfig { | 25 | insert_use: InsertUseConfig { |
26 | merge: Some(MergeBehavior::Full), | 26 | merge: Some(MergeBehavior::Full), |
27 | prefix_kind: PrefixKind::Plain, | 27 | prefix_kind: PrefixKind::Plain, |
28 | group: true, | ||
28 | }, | 29 | }, |
29 | }; | 30 | }; |
30 | 31 | ||
@@ -119,7 +120,7 @@ pub(crate) fn check_edit_with_config( | |||
119 | 120 | ||
120 | let mut combined_edit = completion.text_edit().to_owned(); | 121 | let mut combined_edit = completion.text_edit().to_owned(); |
121 | if let Some(import_text_edit) = | 122 | if let Some(import_text_edit) = |
122 | completion.import_to_add().and_then(|edit| edit.to_text_edit(config.insert_use.merge)) | 123 | completion.import_to_add().and_then(|edit| edit.to_text_edit(config.insert_use)) |
123 | { | 124 | { |
124 | combined_edit.union(import_text_edit).expect( | 125 | combined_edit.union(import_text_edit).expect( |
125 | "Failed to apply completion resolve changes: change ranges overlap, but should not", | 126 | "Failed to apply completion resolve changes: change ranges overlap, but should not", |