Skip to content

Conversation

@willothy
Copy link

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.

Not sure if this is actually the right way to do this since this is my first time working on RA, let me know if this is wrong :)

Before:
Screenshot 2025-12-16 at 3 56 13 PM

After:
Screenshot 2025-12-16 at 3 55 16 PM

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 16, 2025
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.
@willothy willothy force-pushed the willothy/fix-colliding-macro-invocation-hl branch from cdc31e9 to 5acf10c Compare December 17, 2025 00:00
@willothy willothy changed the title fix: Prefer macro namespace when classifying paths in macro invocations Fix macro invocations being highlighted as modules when names collide Dec 17, 2025
@ChayimFriedman2
Copy link
Contributor

I'd prefer asking why resolve_macro_call() fails to resolve the macro, first. Do you have a reproduction?

@willothy
Copy link
Author

I've done a bit more digging and found that it only seems to happen inside of an #[async_trait::async_trait] (or likely inside of any attribute macro invocation).

I have a consistent repro in a large private monorepo, but I'm working on a minimal repro you can test with. It's a bit inconsistent though - it sometimes works, and the appearance is dependent on scroll position in editor. I am using Neovim so not sure how it will fare in other editors.

@ChayimFriedman2
Copy link
Contributor

If its inside an attribute macro, the reason could be that some code somewhere calls NameRefClass::classify() before descending into macros (basically, the source pointer you give to resolve_macro_call() needs to be inside the expansion of the attribute, and that code is not entering it, passing it the unexpanded source instead, which will indeed fail).

@willothy
Copy link
Author

Gotcha, I'll look into places that do that and see if I can find the underlying cause

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants