Skip to content

Commit 9d2cbf0

Browse files
Show first fuzzy completions fully containing the input
1 parent b55cb89 commit 9d2cbf0

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

crates/completion/src/completions/unqualified_path.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<()
126126
let anchor = ctx.name_ref_syntax.as_ref()?;
127127
let import_scope = ImportScope::find_insert_use_container(anchor.syntax(), &ctx.sema)?;
128128

129-
let possible_imports = imports_locator::find_similar_imports(
129+
let mut all_mod_paths = imports_locator::find_similar_imports(
130130
&ctx.sema,
131131
ctx.krate?,
132132
Some(100),
@@ -144,15 +144,24 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<()
144144
})
145145
})
146146
.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)| {
148159
render_resolution_with_import(
149160
RenderContext::new(ctx),
150161
ImportEdit { import_path, import_scope: import_scope.clone() },
151162
&definition,
152163
)
153-
});
154-
155-
acc.add_all(possible_imports);
164+
}));
156165
Some(())
157166
}
158167

0 commit comments

Comments
 (0)