rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.26k stars 1.61k forks source link

`#[rust_analyzer::*]` tool and lint attributes #11556

Open Veykril opened 2 years ago

Veykril commented 2 years ago

This serves as a general bag of ideas around possible future r-a/ide tool attributes (we have this attribute now https://github.com/rust-lang/rust/pull/125241)

Note: names are of course bikesheddable

bjorn3 commented 2 years ago

There are a couple special cases for rust-analyzer's own code which could be migrated to an attribute I think. For example getting code highlighting inside test fixture strings.

Veykril commented 2 years ago

That's a good point, added that to the list.

ModProg commented 2 years ago

I am not sure if this fits here as well, but a way for a derive macros helper atteibutes or proc macros in general to define what their input is.

e.g. tell RA that your macro looks like this:

#[attr(param1=<usize>, param2=<syn::Path>)]

Especially proc macro devwlopers would probably be fine to go the extra step to manually define their macros input syntax (as well as maybe a way to skip expansion for a macro that could tell ra it only e.g. implements a Trait).

An this could even be delegated to parsing libraries like attribute-derive.

Veykril commented 2 years ago

We could have some very very minor grammar for specifying things here, but that won't do much for more complex cases.

I'm not sure what you mean with delegating to parsing libraries.

ModProg commented 2 years ago

I'm not sure what you mean with delegating to parsing libraries.

Generating the attribute with the gramar. So the proc macro developer would not need to write it on their own.

Of course, at that point the parsing library could also handle the completion without depending on such a grammar, if setup correctly. Using something like https://github.com/rust-lang/rust-analyzer/issues/7402#issuecomment-770196608

ChayimFriedman2 commented 2 months ago

This doesn't have to require nightly: we can pass a special RUST_ANALYZER environment variable to crates, then crates that want this will have a build script that detects this variable and set a cfg (or we can set a cfg for them instead of an environment variable), which the invocations of #[rust_analyze::] will be gated under.

Veykril commented 2 months ago

No need for that actually, we have gotten the tool namespace in https://github.com/rust-lang/rust/pull/125241 (forgot to update the description here)