From 4baac238a8343d7c5ced58603bf122c66cbf8c82 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Tue, 24 Nov 2020 02:26:16 +0200 Subject: Improve autoimports on completion speed * Ignore modules eaferly * Do less completion string rendering --- .../completion/src/completions/unqualified_path.rs | 54 +++++++++++----------- 1 file changed, 28 insertions(+), 26 deletions(-) (limited to 'crates/completion/src/completions') diff --git a/crates/completion/src/completions/unqualified_path.rs b/crates/completion/src/completions/unqualified_path.rs index 86c143b63..f452c98e4 100644 --- a/crates/completion/src/completions/unqualified_path.rs +++ b/crates/completion/src/completions/unqualified_path.rs @@ -79,32 +79,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(()) -- cgit v1.2.3