-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
I am working on an attribute-like proc macro, which is intended to annotate functions, as such:
#[my_attribute]
pub fn(arg1: T1, arg2: T2) {
// User code here
}
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:
- Auto-completion works, but semi-consistently. Sometimes completions do not load until after I've written a large part of the call, whereas typically I can get a list of completion candidates simply by typing a
.after an identifier. - Syntax errors are not highlighted at the place where they occur, and I instead get large parts of the function marked as a syntax error.
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?