diff options
Diffstat (limited to 'crates/completion/src')
-rw-r--r-- | crates/completion/src/completions/unqualified_path.rs | 24 | ||||
-rw-r--r-- | crates/completion/src/config.rs | 6 | ||||
-rw-r--r-- | crates/completion/src/item.rs | 7 | ||||
-rw-r--r-- | crates/completion/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/completion/src/test_utils.rs | 3 |
5 files changed, 20 insertions, 24 deletions
diff --git a/crates/completion/src/completions/unqualified_path.rs b/crates/completion/src/completions/unqualified_path.rs index 4e4e2b36f..544886d29 100644 --- a/crates/completion/src/completions/unqualified_path.rs +++ b/crates/completion/src/completions/unqualified_path.rs | |||
@@ -45,7 +45,7 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC | |||
45 | }); | 45 | }); |
46 | 46 | ||
47 | if ctx.config.enable_autoimport_completions && ctx.config.resolve_additional_edits_lazily() { | 47 | if ctx.config.enable_autoimport_completions && ctx.config.resolve_additional_edits_lazily() { |
48 | fuzzy_completion(acc, ctx).unwrap_or_default() | 48 | fuzzy_completion(acc, ctx); |
49 | } | 49 | } |
50 | } | 50 | } |
51 | 51 | ||
@@ -100,10 +100,10 @@ fn complete_enum_variants(acc: &mut Completions, ctx: &CompletionContext, ty: &T | |||
100 | // To avoid an excessive amount of the results returned, completion input is checked for inclusion in the identifiers only | 100 | // To avoid an excessive amount of the results returned, completion input is checked for inclusion in the identifiers only |
101 | // (i.e. in `HashMap` in the `std::collections::HashMap` path), also not in the module indentifiers. | 101 | // (i.e. in `HashMap` in the `std::collections::HashMap` path), also not in the module indentifiers. |
102 | // | 102 | // |
103 | // .Merge Behaviour | 103 | // .Merge Behavior |
104 | // | 104 | // |
105 | // It is possible to configure how use-trees are merged with the `importMergeBehaviour` setting. | 105 | // It is possible to configure how use-trees are merged with the `importMergeBehavior` setting. |
106 | // Mimics the corresponding behaviour of the `Auto Import` feature. | 106 | // Mimics the corresponding behavior of the `Auto Import` feature. |
107 | // | 107 | // |
108 | // .LSP and performance implications | 108 | // .LSP and performance implications |
109 | // | 109 | // |
@@ -145,15 +145,13 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<() | |||
145 | }) | 145 | }) |
146 | .filter(|(mod_path, _)| mod_path.len() > 1) | 146 | .filter(|(mod_path, _)| mod_path.len() > 1) |
147 | .filter_map(|(import_path, definition)| { | 147 | .filter_map(|(import_path, definition)| { |
148 | render_resolution_with_import( | 148 | let ie = |
149 | RenderContext::new(ctx), | 149 | ImportEdit { import_path: import_path.clone(), import_scope: import_scope.clone() }; |
150 | ImportEdit { | 150 | { |
151 | import_path: import_path.clone(), | 151 | let _p = profile::span("totextedit"); |
152 | import_scope: import_scope.clone(), | 152 | ie.to_text_edit(ctx.config.merge); |
153 | merge_behaviour: ctx.config.merge, | 153 | } |
154 | }, | 154 | render_resolution_with_import(RenderContext::new(ctx), ie, &definition) |
155 | &definition, | ||
156 | ) | ||
157 | }); | 155 | }); |
158 | 156 | ||
159 | acc.add_all(possible_imports); | 157 | acc.add_all(possible_imports); |
diff --git a/crates/completion/src/config.rs b/crates/completion/src/config.rs index 5175b9d69..30577dc11 100644 --- a/crates/completion/src/config.rs +++ b/crates/completion/src/config.rs | |||
@@ -4,7 +4,7 @@ | |||
4 | //! module, and we use to statically check that we only produce snippet | 4 | //! module, and we use to statically check that we only produce snippet |
5 | //! completions if we are allowed to. | 5 | //! completions if we are allowed to. |
6 | 6 | ||
7 | use ide_db::helpers::insert_use::MergeBehaviour; | 7 | use ide_db::helpers::insert_use::MergeBehavior; |
8 | use rustc_hash::FxHashSet; | 8 | use rustc_hash::FxHashSet; |
9 | 9 | ||
10 | #[derive(Clone, Debug, PartialEq, Eq)] | 10 | #[derive(Clone, Debug, PartialEq, Eq)] |
@@ -14,7 +14,7 @@ pub struct CompletionConfig { | |||
14 | pub add_call_parenthesis: bool, | 14 | pub add_call_parenthesis: bool, |
15 | pub add_call_argument_snippets: bool, | 15 | pub add_call_argument_snippets: bool, |
16 | pub snippet_cap: Option<SnippetCap>, | 16 | pub snippet_cap: Option<SnippetCap>, |
17 | pub merge: Option<MergeBehaviour>, | 17 | pub merge: Option<MergeBehavior>, |
18 | /// A set of capabilities, enabled on the client and supported on the server. | 18 | /// A set of capabilities, enabled on the client and supported on the server. |
19 | pub active_resolve_capabilities: FxHashSet<CompletionResolveCapability>, | 19 | pub active_resolve_capabilities: FxHashSet<CompletionResolveCapability>, |
20 | } | 20 | } |
@@ -56,7 +56,7 @@ impl Default for CompletionConfig { | |||
56 | add_call_parenthesis: true, | 56 | add_call_parenthesis: true, |
57 | add_call_argument_snippets: true, | 57 | add_call_argument_snippets: true, |
58 | snippet_cap: Some(SnippetCap { _private: () }), | 58 | snippet_cap: Some(SnippetCap { _private: () }), |
59 | merge: Some(MergeBehaviour::Full), | 59 | merge: Some(MergeBehavior::Full), |
60 | active_resolve_capabilities: FxHashSet::default(), | 60 | active_resolve_capabilities: FxHashSet::default(), |
61 | } | 61 | } |
62 | } | 62 | } |
diff --git a/crates/completion/src/item.rs b/crates/completion/src/item.rs index bd94402d7..65f8353e7 100644 --- a/crates/completion/src/item.rs +++ b/crates/completion/src/item.rs | |||
@@ -4,7 +4,7 @@ use std::fmt; | |||
4 | 4 | ||
5 | use hir::{Documentation, ModPath, Mutability}; | 5 | use hir::{Documentation, ModPath, Mutability}; |
6 | use ide_db::helpers::{ | 6 | use ide_db::helpers::{ |
7 | insert_use::{self, ImportScope, MergeBehaviour}, | 7 | insert_use::{self, ImportScope, MergeBehavior}, |
8 | mod_path_to_ast, | 8 | mod_path_to_ast, |
9 | }; | 9 | }; |
10 | use syntax::{algo, TextRange}; | 10 | use syntax::{algo, TextRange}; |
@@ -271,19 +271,18 @@ impl CompletionItem { | |||
271 | pub struct ImportEdit { | 271 | pub struct ImportEdit { |
272 | pub import_path: ModPath, | 272 | pub import_path: ModPath, |
273 | pub import_scope: ImportScope, | 273 | pub import_scope: ImportScope, |
274 | pub merge_behaviour: Option<MergeBehaviour>, | ||
275 | } | 274 | } |
276 | 275 | ||
277 | impl ImportEdit { | 276 | impl ImportEdit { |
278 | /// Attempts to insert the import to the given scope, producing a text edit. | 277 | /// Attempts to insert the import to the given scope, producing a text edit. |
279 | /// May return no edit in edge cases, such as scope already containing the import. | 278 | /// May return no edit in edge cases, such as scope already containing the import. |
280 | pub fn to_text_edit(&self) -> Option<TextEdit> { | 279 | pub fn to_text_edit(&self, merge_behavior: Option<MergeBehavior>) -> Option<TextEdit> { |
281 | let _p = profile::span("ImportEdit::to_text_edit"); | 280 | let _p = profile::span("ImportEdit::to_text_edit"); |
282 | 281 | ||
283 | let rewriter = insert_use::insert_use( | 282 | let rewriter = insert_use::insert_use( |
284 | &self.import_scope, | 283 | &self.import_scope, |
285 | mod_path_to_ast(&self.import_path), | 284 | mod_path_to_ast(&self.import_path), |
286 | self.merge_behaviour, | 285 | merge_behavior, |
287 | ); | 286 | ); |
288 | let old_ast = rewriter.rewrite_root()?; | 287 | let old_ast = rewriter.rewrite_root()?; |
289 | let mut import_insert = TextEdit::builder(); | 288 | let mut import_insert = TextEdit::builder(); |
diff --git a/crates/completion/src/lib.rs b/crates/completion/src/lib.rs index f60f87243..8e27bb153 100644 --- a/crates/completion/src/lib.rs +++ b/crates/completion/src/lib.rs | |||
@@ -153,9 +153,7 @@ pub fn resolve_completion_edits( | |||
153 | }) | 153 | }) |
154 | .find(|mod_path| mod_path.to_string() == full_import_path)?; | 154 | .find(|mod_path| mod_path.to_string() == full_import_path)?; |
155 | 155 | ||
156 | ImportEdit { import_path, import_scope, merge_behaviour: config.merge } | 156 | ImportEdit { import_path, import_scope }.to_text_edit(config.merge).map(|edit| vec![edit]) |
157 | .to_text_edit() | ||
158 | .map(|edit| vec![edit]) | ||
159 | } | 157 | } |
160 | 158 | ||
161 | #[cfg(test)] | 159 | #[cfg(test)] |
diff --git a/crates/completion/src/test_utils.rs b/crates/completion/src/test_utils.rs index 25f5f4924..db896b2df 100644 --- a/crates/completion/src/test_utils.rs +++ b/crates/completion/src/test_utils.rs | |||
@@ -98,7 +98,8 @@ pub(crate) fn check_edit_with_config( | |||
98 | let mut actual = db.file_text(position.file_id).to_string(); | 98 | let mut actual = db.file_text(position.file_id).to_string(); |
99 | 99 | ||
100 | let mut combined_edit = completion.text_edit().to_owned(); | 100 | let mut combined_edit = completion.text_edit().to_owned(); |
101 | if let Some(import_text_edit) = completion.import_to_add().and_then(|edit| edit.to_text_edit()) | 101 | if let Some(import_text_edit) = |
102 | completion.import_to_add().and_then(|edit| edit.to_text_edit(config.merge)) | ||
102 | { | 103 | { |
103 | combined_edit.union(import_text_edit).expect( | 104 | combined_edit.union(import_text_edit).expect( |
104 | "Failed to apply completion resolve changes: change ranges overlap, but should not", | 105 | "Failed to apply completion resolve changes: change ranges overlap, but should not", |