-
Notifications
You must be signed in to change notification settings - Fork 1.8k
How to make attribute proc macros more user-friendly with RA #11859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
After doing a bit more research myself, I came across #11014, and there I found #11193. Adding my attribute macro to the "ignore" map in my settings seems to do the trick. However, I can't expect all of my users to enable that workaround locally. I suspect there's something I can improve on my end: Many attribute macros work work just fine nowadays without that workaround. And, as the author, I'm more than willing to slightly adapt the definition to make it more IDE-friendly, I just don't know how 😄 Is there a better way to let rust-analyzer know that my attribute macro is not going to change the input function? |
So, since you said that it works fine for another proc-macro that basically does the same as the one you are writing, I assume you are testing yours while you are modifying the proc-macro itself right now? What I assume you are running into here is that r-a does not reload proc-macros while you edit them, so r-a is expanding the macro in your testing with an older version of the macro. Restarting your editor session should update the macro being used in that case. (Basically r-a asks cargo to build the proc-macros once on start up, but not after edits). |
Hey! Thanks for the quick response 👍
This is indeed something I've experienced, but I don't think it's related to the issue I'm currently facing. I'm already used to restarting the editor often when developing proc macros 😄 It seems the issue persists even if I restart the editor. As I mentioned there seems to be some degree of functionality inside the function (auto-completion is there, just not quite, but starting to type a half-parsed line highlights all the function in red). |
|
After #11444, auto completion should work properly in attribute macros except in a) cases that we don't handle in the syntax fixup logic yet, which if you see them please report them, or b) edge cases where the attribute macro has some particular expectations or checks for the code it gets passed, in which case the macro has to cooperate better. So please report specific cases where you encounter problems (including the exact code inside the function and where you're trying to triggering completion). (Also make sure that you're using a recent version of rust-analyzer.)
I wouldn't recommend that in general, it shouldn't be necessary and isn't really the right thing to do either. |
Just to leave a note, I got the same issue, in this case is using leptos component attribute macro. This doesn't happen in all projects, but this one is getting complex and as a few dependencies and feature gate flags. If I have some time I will try to understand where it's failing inside RA proc server. |
Uh oh!
There was an error while loading. Please reload this page.
I am working on an attribute-like proc macro, which is intended to annotate functions, as such:
The thing is, even though my attribute is only meant to do some semantic checks and is not even modifying the function body, once I annotate the function with my attribute, rust analyzer gives up and stops doing most of its usual tasks:
.
after an identifier.Attribute-like proc macros seem to be supported in RA to some extent. For instance, I use often use the
profiling
(https://crates.io/crates/profiling) crate and I don't seem to encounter those issues when using their#[profiling::function]
attribute macro. I had a look at the implementation here and I can't see any difference with my implementation.How does the mechanism in RA that expands proc macros work? Is there a way I can improve the user experience of my macro so that RA behaves just like when writing a regular function?
The text was updated successfully, but these errors were encountered: