rust-lang / rust-lang/rust-analyzer
"Go to Definition" and intra-doc links don't work properly for macro-generated code
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
Possible labels: A-macro, A-hover, A-goto-def, C-bug
Description
This issue builds upon the excellent work done in #503 and #4873 for resolving intra-doc links in hover documentation. While those changes successfully made intra-doc links work in cargo doc output, there are still significant limitations when working with macro-generated code in the IDE.
Current Problems
1. Go to Definition leads to macro instead of generated code
When using "Go to Definition" (F12) on symbols from macro-generated code, rust-analyzer navigates to the macro definition rather than showing the actual generated implementation. This makes it impossible to inspect the generated code directly in the IDE.
2. Intra-doc links in hover tooltips are not clickable
Even though intra-doc links are properly resolved and work in cargo doc, they appear as plain text in VS Code hover tooltips and cannot be clicked to navigate to the referenced items.
Current Workaround and Its Problems
To provide some visibility into the generated code, I've implemented an add_impl_doc function that includes the generated implementation as a code block in the documentation. However, this leads to extremely verbose documentation since the same implementation appears:
- In the trait-level documentation
- In the method-level documentation
- As the actual implementation
This makes the documentation unwieldy and hard to read.
Expected Behavior
1. "Go to Definition" should work with generated code
- When using "Go to Definition" on macro-generated symbols, it should show the actual generated code, not just the macro
- Similar to how "Go to Definition" works with regular code, but for macro expansions
- Could be implemented as:
- Direct navigation to generated code
- An option in the "Go to Definition" context menu to choose between macro and generated code
- Integration with the existing macro expansion features
2. Intra-doc links should be clickable in hover tooltips
- Intra-doc links in hover documentation should be clickable and functional
- When clicked, they should navigate to the referenced symbol (whether generated or not)
- This should provide the same navigation experience as
cargo docbut within the IDE
3. Better macro code inspection
- Hover tooltips should show relevant generated code information
- Provide a way to inspect generated implementations without cluttering documentation
Technical Details
rust-analyzer version: (latest as of July 2025)
rustc version: 1.80+
editor: VS Code with rust-analyzer extension
repository: https://github.com/tamaro-skaljic/SpacetimeDSL
Related Issues
- #503 - "Clickable links in markdown don't do anything" (partially resolved)
- #4873 - "Resolve links in hover documentation" (merged, but doesn't address IDE navigation)
Impact
This enhancement would significantly improve the developer experience for:
- Procedural macro authors who generate complex APIs
- Users of macro-generated code who need to understand the generated implementations
- Any project using extensive macro-generated code with documentation
The current limitations force developers to either:
- Use
cargo doc --openconstantly (breaking IDE workflow) - Include verbose implementation details in documentation (cluttering docs)
- Work without proper code navigation (reducing productivity)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the existing work in #503 and #4873 on intra-doc links and hover documentation, then trace the macro expansion and navigation features involved in rust-analyzer. Compare Go to Definition and hover-link behavior for macro-generated symbols with regular code. Done means generated implementations can be inspected or selected and intra-doc links are clickable in VS Code hovers without requiring verbose workaround documentation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- developer-experience
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100