rust-lang / rust-lang/rust-analyzer

Support showing proc macro generated code?

Open
#19,947 9 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

I've been working on some wasmtime code and that makes extensive use of proc macros to generate Rust code.

It means you can end up writing code like this:

    wasmtime_wasi::p2::bindings::clocks::wall_clock::add_to_linker_get_host(l, closure)?;

You ctrl-click add_to_linker_get_host() to read the code, and it takes you here:

#[proc_macro]
pub fn bindgen(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
    bindgen::expand(&parse_macro_input!(input as bindgen::Config))
        .unwrap_or_else(Error::into_compile_error)
        .into()
}

That... sucks. I think Rust-analyzer could do better though because if you hover add_to_linker_get_host it clearly knows about it:

Image

This is maybe a better example. Hovering gives you great info about this type:

Image

And you even get doc strings for members:

Image

But if you ctrl-click the type you jump to exactly the same useless definition:

#[proc_macro]
pub fn bindgen(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
    bindgen::expand(&parse_macro_input!(input as bindgen::Config))
        .unwrap_or_else(Error::into_compile_error)
        .into()
}

Would it be possible when you go-to-definition on these types to open an ephemeral editor and fill it with the generated code that the macro has written?

(Sorry if I'm not the first person to ask about this; I did try and search for duplicates but couldn't find any.)

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

Reproduce the issue using the wasmtime_wasi proc-macro example and compare hover results with go-to-definition on add_to_linker_get_host and its generated types. Start by tracing the proc_macro bindgen entry point and how rust-analyzer resolves those symbols. Done means go-to-definition can present the generated code in an ephemeral editor without losing the documented symbol information.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.