rust-lang / rust-lang/rust-analyzer

Go-to-definition and auto-completion inside a macro_rules invocation

Open
#14,999 14 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-feature
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

In Pavex, there is a f! macro. It desugars to

macro_rules! f {
    ($($p:tt)*) => {{
        $crate::reflection::RawCallable {
            import_path: stringify!($($p)*),
            registered_at: ::std::env!("CARGO_PKG_NAME")
        }
    }};
}

The expectation is that the argument passed to f! is a path to a Rust type (either a method or a function).

In RA, as soon as you are writing inside the f! context (e.g. f!(crate::...)), you don't get any autocompletion.
Once the path is full spelled out (e.g. f!(crate::get_articles)), you also don't get the "go to definition" assist.

Is there a way to improve the experience here? Is there something that I can do, as the macro author, to help RA in dealing with this case?

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 by reproducing completion and go-to-definition behavior for paths such as f!(crate::...) inside a Rust project using the shown macro_rules! definition. Trace how rust-analyzer handles macro invocation arguments, then define completion and definition-navigation behavior that works for the path passed to f! and verify both cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
developer-experience, devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.