From f41c98342476087d0a4387e7d337ce2d897e0346 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 27 May 2021 04:34:21 +0200 Subject: Don't complete non-macro item paths in impls and modules --- crates/ide_completion/src/completions/qualified_path.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'crates/ide_completion/src/completions/qualified_path.rs') diff --git a/crates/ide_completion/src/completions/qualified_path.rs b/crates/ide_completion/src/completions/qualified_path.rs index ed48f61af..a90325e06 100644 --- a/crates/ide_completion/src/completions/qualified_path.rs +++ b/crates/ide_completion/src/completions/qualified_path.rs @@ -21,6 +21,18 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon }; let context_module = ctx.scope.module(); + if ctx.expects_item() || ctx.expects_assoc_item() { + if let PathResolution::Def(hir::ModuleDef::Module(module)) = resolution { + let module_scope = module.scope(ctx.db, context_module); + for (name, def) in module_scope { + if let ScopeDef::MacroDef(macro_def) = def { + acc.add_macro(ctx, Some(name.to_string()), macro_def); + } + } + } + return; + } + // Add associated types on type parameters and `Self`. resolution.assoc_type_shorthand_candidates(ctx.db, |_, alias| { acc.add_type_alias(ctx, alias); -- cgit v1.2.3 From 3a16950fd919f46fd879c36423810a40105b2c10 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 27 May 2021 18:15:18 +0200 Subject: Cleanup `ImmediateLocation` determination --- .../src/completions/qualified_path.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'crates/ide_completion/src/completions/qualified_path.rs') diff --git a/crates/ide_completion/src/completions/qualified_path.rs b/crates/ide_completion/src/completions/qualified_path.rs index a90325e06..c16bb215f 100644 --- a/crates/ide_completion/src/completions/qualified_path.rs +++ b/crates/ide_completion/src/completions/qualified_path.rs @@ -20,7 +20,6 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon None => return, }; let context_module = ctx.scope.module(); - if ctx.expects_item() || ctx.expects_assoc_item() { if let PathResolution::Def(hir::ModuleDef::Module(module)) = resolution { let module_scope = module.scope(ctx.db, context_module); @@ -606,7 +605,7 @@ fn main() { T::$0; } macro_rules! foo { () => {} } fn main() { let _ = crate::$0 } - "#, +"#, expect![[r##" fn main() fn() ma foo!(…) #[macro_export] macro_rules! foo @@ -614,6 +613,25 @@ fn main() { let _ = crate::$0 } ); } + #[test] + fn completes_qualified_macros_in_impl() { + check( + r#" +#[macro_export] +macro_rules! foo { () => {} } + +struct MyStruct {} + +impl MyStruct { + crate::$0 +} +"#, + expect![[r##" + ma foo! #[macro_export] macro_rules! foo + "##]], + ); + } + #[test] fn test_super_super_completion() { check( -- cgit v1.2.3