How feasible would it be for rust-analyzer to be able to autocomplete members declared from inside procedural macros?

I'm currently working on a project which relies heavily on types and functions generated within proc macros, and it can be a bit tedious to work with these due to lack of autocomplete. How feasible would it be to make autocomplete suggestions work in this case?

I would also be willing to investigate adding this, depending on complexity, if the project is looking for contributors.

Can you elaborate on this a bit? r-a is already able to complete things generated by proc-macros.

Are there any requirements for this in terms of how the proc macro is implemented or something?

So for instance I have a function style proc macro which is called like so:

my_macro! {

Which expands like so to generate some types and functions within a module:

mod foo {
    pub struct Foo { ... }
    pub struct FooHelper { ... }
    impl Foo { ... }

    pub fn generated_func(foo: Foo) { ... }

And for instance, if foo is in scope, I can type foo:: and I will not get any autocomplete results.

This should just work to my knowledge. Could you try coming up with a minimal repro maybe and report the issue on github?

Yes I can do that. Actually it's great if it should already work - it might take me a couple days to find the time.

I'm on nightly, does that matter?

It shouldn't, but sometimes it does. Namely, the proc macro ABI can change, and r-a needs to know how to call proc macros in order to expand them.

The toolchain now comes with a shim with a slightly more stable (IIRC, JSON-RPC-ish) interface that r-a knows how to use, but it's possible that your r-a isn't using it.

If you're using vscode, failure to expand proc macros is usually accompanied by an error popup. In other editors, I don't know how the error is (or isn't) reported.

I am using Zed and there is no error popup, but I can try in VSCode to see if there is some more feedback.

I know the proc macros are working at some level with RA, because I am using the diagnostics api to show localized errors within the proc macro invocations, and that is working perfectly.

Is there any way to test this independently of an editor? I.e. could I run RA from the terminal somehow and try to feed it an autocomplete request to see exactly what the output is?

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.