Skip to content

Support showing proc macro generated code? #19947

Open
@Timmmm

Description

@Timmmm

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-featureCategory: feature request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions