From 5acf10c02e14d29fc40d1230b765c0977511b1b2 Mon Sep 17 00:00:00 2001 From: Will Hopkins Date: Tue, 16 Dec 2025 15:47:55 -0800 Subject: [PATCH] fix: Prefer macro namespace when classifying paths in macro invocations Problem: When `resolve_macro_call` fails to resolve a macro, the fallback `resolve_path_with_subst` prefers type/value namespaces over the macro namespace. This causes macro invocations to be incorrectly highlighted as `namespace` when a module with the same name exists in scope. Solution: Use `resolve_path_per_ns` to check the macro namespace first when in a MacroCall context, falling back to normal path resolution if no macro is found. --- crates/ide-db/src/defs.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/ide-db/src/defs.rs b/crates/ide-db/src/defs.rs index 788f9b73fa19..90fcaa53bc76 100644 --- a/crates/ide-db/src/defs.rs +++ b/crates/ide-db/src/defs.rs @@ -771,6 +771,14 @@ impl<'db> NameRefClass<'db> { if let Some(macro_def) = sema.resolve_macro_call(¯o_call) { return Some(NameRefClass::Definition(Definition::Macro(macro_def), None)); } + + // When in a macro call context, prefer macro namespace resolution over type/value + // namespaces. This ensures that if a macro and a module have the same name, + // we correctly classify the path as a macro when used in a macro invocation. + if let Some(res) = sema.resolve_path_per_ns(&path).and_then(|res| res.macro_ns) { + return Some(NameRefClass::Definition(res.into(), None)); + } + // Fallback to normal path resolution. } return sema .resolve_path_with_subst(&path)