mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
6614: Improve autoimports on completion speed r=matklad a=SomeoneToIgnore Presumably closes https://github.com/rust-analyzer/rust-analyzer/issues/6594 May help https://github.com/rust-analyzer/rust-analyzer/issues/6612 * Ignore modules eaferly * Do less completion string rendering 6632: Pin cargo_metadata r=matklad a=kjeremy See: https://github.com/oli-obk/cargo_metadata/pull/142#issuecomment-733653275 Co-authored-by: Kirill Bulatov <mail4score@gmail.com> Co-authored-by: kjeremy <kjeremy@gmail.com>
This commit is contained in:
commit
db6988d4e7
7 changed files with 117 additions and 35 deletions
|
@ -81,32 +81,34 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<()
|
|||
|
||||
let potential_import_name = ctx.token.to_string();
|
||||
|
||||
let possible_imports =
|
||||
imports_locator::find_similar_imports(&ctx.sema, ctx.krate?, &potential_import_name, 400)
|
||||
.filter_map(|import_candidate| match import_candidate {
|
||||
// when completing outside the use declaration, modules are pretty useless
|
||||
// and tend to bloat the completion suggestions a lot
|
||||
Either::Left(ModuleDef::Module(_)) => None,
|
||||
Either::Left(module_def) => Some((
|
||||
current_module.find_use_path(ctx.db, module_def)?,
|
||||
ScopeDef::ModuleDef(module_def),
|
||||
)),
|
||||
Either::Right(macro_def) => Some((
|
||||
current_module.find_use_path(ctx.db, macro_def)?,
|
||||
ScopeDef::MacroDef(macro_def),
|
||||
)),
|
||||
})
|
||||
.filter(|(mod_path, _)| mod_path.len() > 1)
|
||||
.filter_map(|(import_path, definition)| {
|
||||
render_resolution_with_import(
|
||||
RenderContext::new(ctx),
|
||||
import_path.clone(),
|
||||
import_scope.clone(),
|
||||
ctx.config.merge,
|
||||
&definition,
|
||||
)
|
||||
})
|
||||
.take(20);
|
||||
let possible_imports = imports_locator::find_similar_imports(
|
||||
&ctx.sema,
|
||||
ctx.krate?,
|
||||
&potential_import_name,
|
||||
50,
|
||||
true,
|
||||
)
|
||||
.filter_map(|import_candidate| {
|
||||
Some(match import_candidate {
|
||||
Either::Left(module_def) => {
|
||||
(current_module.find_use_path(ctx.db, module_def)?, ScopeDef::ModuleDef(module_def))
|
||||
}
|
||||
Either::Right(macro_def) => {
|
||||
(current_module.find_use_path(ctx.db, macro_def)?, ScopeDef::MacroDef(macro_def))
|
||||
}
|
||||
})
|
||||
})
|
||||
.filter(|(mod_path, _)| mod_path.len() > 1)
|
||||
.take(20)
|
||||
.filter_map(|(import_path, definition)| {
|
||||
render_resolution_with_import(
|
||||
RenderContext::new(ctx),
|
||||
import_path.clone(),
|
||||
import_scope.clone(),
|
||||
ctx.config.merge,
|
||||
&definition,
|
||||
)
|
||||
});
|
||||
|
||||
acc.add_all(possible_imports);
|
||||
Some(())
|
||||
|
|
|
@ -150,6 +150,7 @@ impl<'a> Render<'a> {
|
|||
import_data: Option<(ModPath, ImportScope, Option<MergeBehaviour>)>,
|
||||
resolution: &ScopeDef,
|
||||
) -> Option<CompletionItem> {
|
||||
let _p = profile::span("render_resolution");
|
||||
use hir::ModuleDef::*;
|
||||
|
||||
let completion_kind = match resolution {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue