From d64b42e87c7877bf445b631df6b3a4b3a1f8b1bf Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 17 Dec 2020 19:42:19 +0300 Subject: [PATCH] Tighten up auto-complete thresholds for better perf * don't even start auto-complete if fewer than 3 chars * look for 100 fuzzy matched symbols, but *stop* at the first ten actually importable. --- crates/completion/src/completions/unqualified_path.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/completion/src/completions/unqualified_path.rs b/crates/completion/src/completions/unqualified_path.rs index b9315f6c0497..f225637c5cb8 100644 --- a/crates/completion/src/completions/unqualified_path.rs +++ b/crates/completion/src/completions/unqualified_path.rs @@ -98,7 +98,9 @@ fn complete_enum_variants(acc: &mut Completions, ctx: &CompletionContext, ty: &T // .Fuzzy search details // // To avoid an excessive amount of the results returned, completion input is checked for inclusion in the identifiers only -// (i.e. in `HashMap` in the `std::collections::HashMap` path), also not in the module indentifiers. +// (i.e. in `HashMap` in the `std::collections::HashMap` path), also not in the module identifiers. +// +// It also avoids searching for any imports for inputs with their length less that 3 symbols. // // .Merge Behavior // @@ -122,6 +124,10 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<() let _p = profile::span("fuzzy_completion"); let potential_import_name = ctx.token.to_string(); + if potential_import_name.len() < 3 { + return None; + } + let current_module = ctx.scope.module()?; let anchor = ctx.name_ref_syntax.as_ref()?; let import_scope = ImportScope::find_insert_use_container(anchor.syntax(), &ctx.sema)?; @@ -144,6 +150,7 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<() }) }) .filter(|(mod_path, _)| mod_path.len() > 1) + .take(10) .filter_map(|(import_path, definition)| { render_resolution_with_import( RenderContext::new(ctx),