mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-28 12:55:11 +00:00
Merge #6922
6922: Show first fuzzy completions fully containing the input r=matklad a=SomeoneToIgnore Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
This commit is contained in:
commit
a4e17a5a96
1 changed files with 14 additions and 5 deletions
|
@ -126,7 +126,7 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<()
|
||||||
let anchor = ctx.name_ref_syntax.as_ref()?;
|
let anchor = ctx.name_ref_syntax.as_ref()?;
|
||||||
let import_scope = ImportScope::find_insert_use_container(anchor.syntax(), &ctx.sema)?;
|
let import_scope = ImportScope::find_insert_use_container(anchor.syntax(), &ctx.sema)?;
|
||||||
|
|
||||||
let possible_imports = imports_locator::find_similar_imports(
|
let mut all_mod_paths = imports_locator::find_similar_imports(
|
||||||
&ctx.sema,
|
&ctx.sema,
|
||||||
ctx.krate?,
|
ctx.krate?,
|
||||||
Some(100),
|
Some(100),
|
||||||
|
@ -144,15 +144,24 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.filter(|(mod_path, _)| mod_path.len() > 1)
|
.filter(|(mod_path, _)| mod_path.len() > 1)
|
||||||
.filter_map(|(import_path, definition)| {
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
all_mod_paths.sort_by_cached_key(|(mod_path, _)| {
|
||||||
|
if let Some(name) = mod_path.segments.last().map(|name| name.to_string().to_lowercase()) {
|
||||||
|
if name.contains(&potential_import_name.to_lowercase()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
1
|
||||||
|
});
|
||||||
|
|
||||||
|
acc.add_all(all_mod_paths.into_iter().filter_map(|(import_path, definition)| {
|
||||||
render_resolution_with_import(
|
render_resolution_with_import(
|
||||||
RenderContext::new(ctx),
|
RenderContext::new(ctx),
|
||||||
ImportEdit { import_path, import_scope: import_scope.clone() },
|
ImportEdit { import_path, import_scope: import_scope.clone() },
|
||||||
&definition,
|
&definition,
|
||||||
)
|
)
|
||||||
});
|
}));
|
||||||
|
|
||||||
acc.add_all(possible_imports);
|
|
||||||
Some(())
|
Some(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue