aboutsummaryrefslogtreecommitdiff
path: root/crates/completion
diff options
context:
space:
mode:
Diffstat (limited to 'crates/completion')
-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