diff options
author | Kirill Bulatov <[email protected]> | 2020-12-08 12:38:43 +0000 |
---|---|---|
committer | Kirill Bulatov <[email protected]> | 2020-12-08 13:05:09 +0000 |
commit | bf24cb3e8db94a84fb4a24c407797ab6ff5ee109 (patch) | |
tree | ec3e2e0696147459460950ead2bc90591a6347ce /crates/completion | |
parent | cbd3717f2c52b17aa9b15c2df4a364c62d17e4e1 (diff) |
Tweak the search query params for better lookup speed
Diffstat (limited to 'crates/completion')
-rw-r--r-- | crates/completion/src/completions/unqualified_path.rs | 60 |
1 files changed, 29 insertions, 31 deletions
diff --git a/crates/completion/src/completions/unqualified_path.rs b/crates/completion/src/completions/unqualified_path.rs index f65709adf..4e4e2b36f 100644 --- a/crates/completion/src/completions/unqualified_path.rs +++ b/crates/completion/src/completions/unqualified_path.rs | |||
@@ -99,7 +99,6 @@ fn complete_enum_variants(acc: &mut Completions, ctx: &CompletionContext, ty: &T | |||
99 | // | 99 | // |
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 | // It also avoids searching for any imports for inputs with their length less that 3 symbols. | ||
103 | // | 102 | // |
104 | // .Merge Behaviour | 103 | // .Merge Behaviour |
105 | // | 104 | // |
@@ -123,40 +122,39 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<() | |||
123 | let _p = profile::span("fuzzy_completion"); | 122 | let _p = profile::span("fuzzy_completion"); |
124 | let potential_import_name = ctx.token.to_string(); | 123 | let potential_import_name = ctx.token.to_string(); |
125 | 124 | ||
126 | if potential_import_name.len() < 3 { | ||
127 | return None; | ||
128 | } | ||
129 | |||
130 | let current_module = ctx.scope.module()?; | 125 | let current_module = ctx.scope.module()?; |
131 | let anchor = ctx.name_ref_syntax.as_ref()?; | 126 | let anchor = ctx.name_ref_syntax.as_ref()?; |
132 | let import_scope = ImportScope::find_insert_use_container(anchor.syntax(), &ctx.sema)?; | 127 | let import_scope = ImportScope::find_insert_use_container(anchor.syntax(), &ctx.sema)?; |
133 | 128 | ||
134 | let possible_imports = | 129 | let possible_imports = imports_locator::find_similar_imports( |
135 | imports_locator::find_similar_imports(&ctx.sema, ctx.krate?, &potential_import_name, true) | 130 | &ctx.sema, |
136 | .filter_map(|import_candidate| { | 131 | ctx.krate?, |
137 | Some(match import_candidate { | 132 | Some(100), |
138 | Either::Left(module_def) => ( | 133 | &potential_import_name, |
139 | current_module.find_use_path(ctx.db, module_def)?, | 134 | true, |
140 | ScopeDef::ModuleDef(module_def), | 135 | ) |
141 | ), | 136 | .filter_map(|import_candidate| { |
142 | Either::Right(macro_def) => ( | 137 | Some(match import_candidate { |
143 | current_module.find_use_path(ctx.db, macro_def)?, | 138 | Either::Left(module_def) => { |
144 | ScopeDef::MacroDef(macro_def), | 139 | (current_module.find_use_path(ctx.db, module_def)?, ScopeDef::ModuleDef(module_def)) |
145 | ), | 140 | } |
146 | }) | 141 | Either::Right(macro_def) => { |
147 | }) | 142 | (current_module.find_use_path(ctx.db, macro_def)?, ScopeDef::MacroDef(macro_def)) |
148 | .filter(|(mod_path, _)| mod_path.len() > 1) | 143 | } |
149 | .filter_map(|(import_path, definition)| { | 144 | }) |
150 | render_resolution_with_import( | 145 | }) |
151 | RenderContext::new(ctx), | 146 | .filter(|(mod_path, _)| mod_path.len() > 1) |
152 | ImportEdit { | 147 | .filter_map(|(import_path, definition)| { |
153 | import_path: import_path.clone(), | 148 | render_resolution_with_import( |
154 | import_scope: import_scope.clone(), | 149 | RenderContext::new(ctx), |
155 | merge_behaviour: ctx.config.merge, | 150 | ImportEdit { |
156 | }, | 151 | import_path: import_path.clone(), |
157 | &definition, | 152 | import_scope: import_scope.clone(), |
158 | ) | 153 | merge_behaviour: ctx.config.merge, |
159 | }); | 154 | }, |
155 | &definition, | ||
156 | ) | ||
157 | }); | ||
160 | 158 | ||
161 | acc.add_all(possible_imports); | 159 | acc.add_all(possible_imports); |
162 | Some(()) | 160 | Some(()) |