aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2020-12-17 21:10:10 +0000
committerKirill Bulatov <[email protected]>2020-12-17 21:10:18 +0000
commit9d2cbf05e31535cc35d9cd4e8f773f0d78ec3473 (patch)
tree977f6be6da7e8b1f5ee668884732a630e0a13fba
parentb55cb897e5104ef30a3d13fe36cb97d6bf6a3597 (diff)
Show first fuzzy completions fully containing the input
-rw-r--r--crates/completion/src/completions/unqualified_path.rs19
1 files changed, 14 insertions, 5 deletions
diff --git a/crates/completion/src/completions/unqualified_path.rs b/crates/completion/src/completions/unqualified_path.rs
index b9315f6c0..93869f92e 100644
--- a/crates/completion/src/completions/unqualified_path.rs
+++ b/crates/completion/src/completions/unqualified_path.rs
@@ -126,7 +126,7 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<()
126 let anchor = ctx.name_ref_syntax.as_ref()?; 126 let anchor = ctx.name_ref_syntax.as_ref()?;
127 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)?;
128 128
129 let possible_imports = imports_locator::find_similar_imports( 129 let mut all_mod_paths = imports_locator::find_similar_imports(
130 &ctx.sema, 130 &ctx.sema,
131 ctx.krate?, 131 ctx.krate?,
132 Some(100), 132 Some(100),
@@ -144,15 +144,24 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<()
144 }) 144 })
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 .collect::<Vec<_>>();
148
149 all_mod_paths.sort_by_cached_key(|(mod_path, _)| {
150 if let Some(name) = mod_path.segments.last().map(|name| name.to_string().to_lowercase()) {
151 if name.contains(&potential_import_name.to_lowercase()) {
152 return 0;
153 }
154 }
155 1
156 });
157
158 acc.add_all(all_mod_paths.into_iter().filter_map(|(import_path, definition)| {
148 render_resolution_with_import( 159 render_resolution_with_import(
149 RenderContext::new(ctx), 160 RenderContext::new(ctx),
150 ImportEdit { import_path, import_scope: import_scope.clone() }, 161 ImportEdit { import_path, import_scope: import_scope.clone() },
151 &definition, 162 &definition,
152 ) 163 )
153 }); 164 }));
154
155 acc.add_all(possible_imports);
156 Some(()) 165 Some(())
157} 166}
158 167