From 3b0fc4d7f2b922a1b7d8d32fc0b065e4023d749b Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sat, 14 Nov 2020 01:07:03 +0200 Subject: Omit modules during autocompletion --- crates/completion/src/completions/magic.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'crates/completion/src') diff --git a/crates/completion/src/completions/magic.rs b/crates/completion/src/completions/magic.rs index 2ac6f94a9..0c4db0199 100644 --- a/crates/completion/src/completions/magic.rs +++ b/crates/completion/src/completions/magic.rs @@ -2,7 +2,7 @@ use assists::utils::{insert_use, mod_path_to_ast, ImportScope}; use either::Either; -use hir::ScopeDef; +use hir::{ModuleDef, ScopeDef}; use ide_db::imports_locator; use syntax::{algo, AstNode}; @@ -13,7 +13,6 @@ use crate::{ use super::Completions; -// TODO kb reuse auto_import assist approach to add trait completion // TODO kb add a setting toggle for this feature? pub(crate) fn complete_magic(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> { if !(ctx.is_trivial_path || ctx.is_pat_binding_or_const) { @@ -28,17 +27,18 @@ pub(crate) fn complete_magic(acc: &mut Completions, ctx: &CompletionContext) -> let possible_imports = imports_locator::find_similar_imports(&ctx.sema, ctx.krate?, &potential_import_name, 400) - .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_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_map(|(mod_path, definition)| { let mut resolution_with_missing_import = render_resolution( -- cgit v1.2.3