Skip to content

Improve code navigation in macros #7890

@flodiebold

Description

@flodiebold

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 Refactor and improve macro debugging/general utilities #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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macromacro expansionC-ArchitectureBig architectural things which we need to figure up-front (or suggestions for rewrites :0) )S-actionableSomeone could pick this issue up and work on it right now

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions