rust-lang / rust-lang/rust-analyzer

Improve code navigation in macros

Open
#7,890 1 comment 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-macro C-Architecture S-actionable
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.