From b29e8ed994c573273a8182efd9b74ec8c664a848 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 7 Jun 2021 19:35:24 +0200 Subject: Remove unnecessary completion::macro_in_item_position --- .../src/completions/unqualified_path.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'crates/ide_completion/src/completions/unqualified_path.rs') diff --git a/crates/ide_completion/src/completions/unqualified_path.rs b/crates/ide_completion/src/completions/unqualified_path.rs index f321ed52b..8b22933e0 100644 --- a/crates/ide_completion/src/completions/unqualified_path.rs +++ b/crates/ide_completion/src/completions/unqualified_path.rs @@ -5,26 +5,25 @@ use hir::ScopeDef; use crate::{CompletionContext, Completions}; pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionContext) { - if !ctx.is_trivial_path() { - return; - } - if ctx.is_path_disallowed() || ctx.expects_item() { + if ctx.is_path_disallowed() || !ctx.is_trivial_path() { return; } - if ctx.expects_assoc_item() { - ctx.scope.process_all_names(&mut |name, def| { - if let ScopeDef::MacroDef(macro_def) = def { - acc.add_macro(ctx, Some(name.clone()), macro_def); + if ctx.expects_item() || ctx.expects_assoc_item() { + // only show macros in {Assoc}ItemList + ctx.scope.process_all_names(&mut |name, res| { + if let hir::ScopeDef::MacroDef(mac) = res { + acc.add_macro(ctx, Some(name.clone()), mac); } - if let ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = def { - acc.add_resolution(ctx, name, &def); + if let hir::ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = res { + acc.add_resolution(ctx, name, &res); } }); return; } if ctx.expects_use_tree() { + // only show modules in a fresh UseTree cov_mark::hit!(only_completes_modules_in_import); ctx.scope.process_all_names(&mut |name, res| { if let ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = res { @@ -693,12 +692,11 @@ impl MyStruct { "#, expect![[r#" md bar - ma foo! macro_rules! foo + ma foo!(…) macro_rules! foo "#]], ) } - // FIXME: The completions here currently come from `macro_in_item_position`, but they shouldn't #[test] fn completes_in_item_list() { check( -- cgit v1.2.3