rust-lang / rust-lang/rust-analyzer
Improve code navigation in macros
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
Inspired by this forum post...
It'd be nice to provide some navigation features in macro definitions / expansions. E.g. if you navigate to the definition of println, you get
macro_rules! println {
() => ($crate::print!("\n"));
($($arg:tt)*) => ({
$crate::io::_print($crate::format_args_nl!($($arg)*));
})
}
and can't click on _print, for example.
Here are various ideas, in order of how hard I expect them to be:
- we could add a heuristic to detect $crate paths and allow navigating to them in macro definitions.
- our "expand macro" functionality could be improved to show expansions inline and allow you to use navigation features in the expanded code. There's already #5949 about this, though I think it'd be cool to overlay the expansion inline.
- it might even be possible to keep some context when using "go to definition" on a macro call, which would allow us to interpret the macro definition in the context of the original call. I think IntelliJ does something similar with type parameters already, and I seem to remember talking about this with @matklad before, but I didn't find an existing issue about this.
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 with the linked Rust forum post and compare the three proposed directions: navigating $crate paths, inline macro expansions, and preserving call-site context. Read issue #5949 for related expansion work, then define a focused scope and a clear completion criterion for navigation in macro definitions or expansions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100