diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/completion/src/completions/unqualified_path.rs | 35 | ||||
-rw-r--r-- | crates/completion/src/item.rs | 24 |
2 files changed, 43 insertions, 16 deletions
diff --git a/crates/completion/src/completions/unqualified_path.rs b/crates/completion/src/completions/unqualified_path.rs index 7ce92a07b..fca8d3a72 100644 --- a/crates/completion/src/completions/unqualified_path.rs +++ b/crates/completion/src/completions/unqualified_path.rs | |||
@@ -71,7 +71,6 @@ fn complete_enum_variants(acc: &mut Completions, ctx: &CompletionContext, ty: &T | |||
71 | } | 71 | } |
72 | } | 72 | } |
73 | 73 | ||
74 | // TODO kb add a setting toggle for this feature? | ||
75 | fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> { | 74 | fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> { |
76 | let _p = profile::span("fuzzy_completion®"); | 75 | let _p = profile::span("fuzzy_completion®"); |
77 | let current_module = ctx.scope.module()?; | 76 | let current_module = ctx.scope.module()?; |
@@ -97,23 +96,35 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<() | |||
97 | }) | 96 | }) |
98 | .filter(|(mod_path, _)| mod_path.len() > 1) | 97 | .filter(|(mod_path, _)| mod_path.len() > 1) |
99 | .filter_map(|(mod_path, definition)| { | 98 | .filter_map(|(mod_path, definition)| { |
100 | let mut resolution_with_missing_import = render_resolution( | 99 | let use_to_insert = mod_path_to_ast(&mod_path); |
101 | RenderContext::new(ctx), | 100 | let mut mod_path_without_last_segment = mod_path; |
102 | mod_path.segments.last()?.to_string(), | 101 | let name_after_import = mod_path_without_last_segment.segments.pop()?.to_string(); |
103 | &definition, | 102 | |
104 | )?; | 103 | let resolution_with_missing_import = |
104 | render_resolution(RenderContext::new(ctx), name_after_import, &definition)?; | ||
105 | let lookup_string = resolution_with_missing_import.lookup().to_owned(); | ||
105 | 106 | ||
106 | let mut text_edits = | 107 | let mut text_edits = |
107 | resolution_with_missing_import.text_edit().to_owned().into_builder(); | 108 | resolution_with_missing_import.text_edit().to_owned().into_builder(); |
108 | 109 | let rewriter = insert_use(&import_scope, use_to_insert, ctx.config.merge); | |
109 | let rewriter = | ||
110 | insert_use(&import_scope, mod_path_to_ast(&mod_path), ctx.config.merge); | ||
111 | let old_ast = rewriter.rewrite_root()?; | 110 | let old_ast = rewriter.rewrite_root()?; |
112 | algo::diff(&old_ast, &rewriter.rewrite(&old_ast)).into_text_edit(&mut text_edits); | 111 | algo::diff(&old_ast, &rewriter.rewrite(&old_ast)).into_text_edit(&mut text_edits); |
113 | 112 | ||
114 | resolution_with_missing_import.update_text_edit(text_edits.finish()); | 113 | let qualifier_string = mod_path_without_last_segment.to_string(); |
115 | 114 | let qualified_label = if qualifier_string.is_empty() { | |
116 | Some(resolution_with_missing_import) | 115 | resolution_with_missing_import.label().to_owned() |
116 | } else { | ||
117 | format!("{}::{}", qualifier_string, resolution_with_missing_import.label()) | ||
118 | }; | ||
119 | |||
120 | Some( | ||
121 | resolution_with_missing_import | ||
122 | .into_builder() | ||
123 | .text_edit(text_edits.finish()) | ||
124 | .label(qualified_label) | ||
125 | .lookup_by(lookup_string) | ||
126 | .build(), | ||
127 | ) | ||
117 | }) | 128 | }) |
118 | .take(20); | 129 | .take(20); |
119 | 130 | ||
diff --git a/crates/completion/src/item.rs b/crates/completion/src/item.rs index 53a12a763..24b9d036a 100644 --- a/crates/completion/src/item.rs +++ b/crates/completion/src/item.rs | |||
@@ -202,6 +202,26 @@ impl CompletionItem { | |||
202 | ref_match: None, | 202 | ref_match: None, |
203 | } | 203 | } |
204 | } | 204 | } |
205 | |||
206 | pub(crate) fn into_builder(self) -> Builder { | ||
207 | Builder { | ||
208 | source_range: self.source_range, | ||
209 | completion_kind: self.completion_kind, | ||
210 | label: self.label, | ||
211 | insert_text: None, | ||
212 | insert_text_format: self.insert_text_format, | ||
213 | detail: self.detail, | ||
214 | documentation: self.documentation, | ||
215 | lookup: self.lookup, | ||
216 | kind: self.kind, | ||
217 | text_edit: Some(self.text_edit), | ||
218 | deprecated: Some(self.deprecated), | ||
219 | trigger_call_info: Some(self.trigger_call_info), | ||
220 | score: self.score, | ||
221 | ref_match: self.ref_match, | ||
222 | } | ||
223 | } | ||
224 | |||
205 | /// What user sees in pop-up in the UI. | 225 | /// What user sees in pop-up in the UI. |
206 | pub fn label(&self) -> &str { | 226 | pub fn label(&self) -> &str { |
207 | &self.label | 227 | &self.label |
@@ -218,10 +238,6 @@ impl CompletionItem { | |||
218 | &self.text_edit | 238 | &self.text_edit |
219 | } | 239 | } |
220 | 240 | ||
221 | pub fn update_text_edit(&mut self, new_text_edit: TextEdit) { | ||
222 | self.text_edit = new_text_edit; | ||
223 | } | ||
224 | |||
225 | /// Short one-line additional information, like a type | 241 | /// Short one-line additional information, like a type |
226 | pub fn detail(&self) -> Option<&str> { | 242 | pub fn detail(&self) -> Option<&str> { |
227 | self.detail.as_deref() | 243 | self.detail.as_deref() |