Skip to content

Commit 5acf10c

Browse files
committed
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.
1 parent 2a40241 commit 5acf10c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

crates/ide-db/src/defs.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,14 @@ impl<'db> NameRefClass<'db> {
771771
if let Some(macro_def) = sema.resolve_macro_call(&macro_call) {
772772
return Some(NameRefClass::Definition(Definition::Macro(macro_def), None));
773773
}
774+
775+
// When in a macro call context, prefer macro namespace resolution over type/value
776+
// namespaces. This ensures that if a macro and a module have the same name,
777+
// we correctly classify the path as a macro when used in a macro invocation.
778+
if let Some(res) = sema.resolve_path_per_ns(&path).and_then(|res| res.macro_ns) {
779+
return Some(NameRefClass::Definition(res.into(), None));
780+
}
781+
// Fallback to normal path resolution.
774782
}
775783
return sema
776784
.resolve_path_with_subst(&path)

0 commit comments

Comments
 (0)