diff options
author | Kirill Bulatov <[email protected]> | 2020-11-16 21:16:41 +0000 |
---|---|---|
committer | Kirill Bulatov <[email protected]> | 2020-11-16 21:16:41 +0000 |
commit | d4128beb3d8c647674ae43407d0ed6edd71ff420 (patch) | |
tree | 635a26e7266d155f2638360a022adc8b6d7b617c /crates/completion/src/completions | |
parent | 410996893489f6c64b472e6128f099f1de229806 (diff) |
Avoid turning completion objects into builders
Diffstat (limited to 'crates/completion/src/completions')
-rw-r--r-- | crates/completion/src/completions/unqualified_path.rs | 42 |
1 files changed, 10 insertions, 32 deletions
diff --git a/crates/completion/src/completions/unqualified_path.rs b/crates/completion/src/completions/unqualified_path.rs index 4f8ec1e67..86c143b63 100644 --- a/crates/completion/src/completions/unqualified_path.rs +++ b/crates/completion/src/completions/unqualified_path.rs | |||
@@ -1,14 +1,14 @@ | |||
1 | //! Completion of names from the current scope, e.g. locals and imported items. | 1 | //! Completion of names from the current scope, e.g. locals and imported items. |
2 | 2 | ||
3 | use assists::utils::{insert_use, mod_path_to_ast, ImportScope}; | 3 | use assists::utils::ImportScope; |
4 | use either::Either; | 4 | use either::Either; |
5 | use hir::{Adt, ModuleDef, ScopeDef, Type}; | 5 | use hir::{Adt, ModuleDef, ScopeDef, Type}; |
6 | use ide_db::imports_locator; | 6 | use ide_db::imports_locator; |
7 | use syntax::{algo, AstNode}; | 7 | use syntax::AstNode; |
8 | use test_utils::mark; | 8 | use test_utils::mark; |
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{ |
11 | render::{render_resolution, RenderContext}, | 11 | render::{render_resolution_with_import, RenderContext}, |
12 | CompletionContext, Completions, | 12 | CompletionContext, Completions, |
13 | }; | 13 | }; |
14 | 14 | ||
@@ -95,35 +95,13 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<() | |||
95 | )), | 95 | )), |
96 | }) | 96 | }) |
97 | .filter(|(mod_path, _)| mod_path.len() > 1) | 97 | .filter(|(mod_path, _)| mod_path.len() > 1) |
98 | .filter_map(|(mod_path, definition)| { | 98 | .filter_map(|(import_path, definition)| { |
99 | let use_to_insert = mod_path_to_ast(&mod_path); | 99 | render_resolution_with_import( |
100 | let mut mod_path_without_last_segment = mod_path; | 100 | RenderContext::new(ctx), |
101 | let name_after_import = mod_path_without_last_segment.segments.pop()?.to_string(); | 101 | import_path.clone(), |
102 | 102 | import_scope.clone(), | |
103 | let resolution_with_missing_import = | 103 | ctx.config.merge, |
104 | render_resolution(RenderContext::new(ctx), name_after_import, &definition)?; | 104 | &definition, |
105 | let lookup_string = resolution_with_missing_import.lookup().to_owned(); | ||
106 | |||
107 | let mut text_edits = | ||
108 | resolution_with_missing_import.text_edit().to_owned().into_builder(); | ||
109 | let rewriter = insert_use(&import_scope, use_to_insert, ctx.config.merge); | ||
110 | let old_ast = rewriter.rewrite_root()?; | ||
111 | algo::diff(&old_ast, &rewriter.rewrite(&old_ast)).into_text_edit(&mut text_edits); | ||
112 | |||
113 | let qualifier_string = mod_path_without_last_segment.to_string(); | ||
114 | let qualified_label = if qualifier_string.is_empty() { | ||
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 | ) | 105 | ) |
128 | }) | 106 | }) |
129 | .take(20); | 107 | .take(20); |