Skip to content
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

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

Open
Veykril opened this issue Feb 25, 2022 · 7 comments
Open

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

Veykril opened this issue Feb 25, 2022 · 7 comments
Labels
A-ide general IDE features C-feature Category: feature request E-unknown It's unclear if the issue is E-hard or E-easy without digging in fun A technically challenging issue with high impact

Comments

@Veykril
Copy link
Member

Veykril commented Feb 25, 2022

This serves as a general bag of ideas around possible future r-a/ide tool attributes (we have this attribute now rust-lang/rust#125241)

  • #[rust_analyzer::skip]: cc #[rust_analyzer::skip] attribute #7449
  • #[rust_analyzer::macro::expands_to(kind0, kind1, ...)] where kind can be anything a macro is allowed to expand to like item, expr, pat, ... This annotation's sole purpose would be to aid completions by allowing us to filter out macros that aren't applicable.
  • #[rust_analyzer::crate_prelude] marks a crate's prelude, aids fly-import completions and auto-import features by allowing (via a config) to avoid or prefer crate preludes for imports.
  • #[rust_analyzer::rust_fixture_params(param_name1, ...)]: specify parameters of a function that are to be highlighting injected, alternatively mark the parameters with attributes directly, but that might become rather unwieldy
  • #[rust_analyzer::macro::expansion_type(path::to::type)]: unit-returning macros in statement position should be completed with a semicolon #10913
  • #[rust_analyzer::unsafe_macro]: https://www.reddit.com/r/rust/comments/vftkrm/unsafe_code_highlighting_with_rustanalyzer/icy0jlv/
  • #[rust_analyzer::render_as_impl_trait]: annotation for types to render them as impl Trait, like we do by default for std types that implement Iterator
  • #[rust_analyzer::color(args)]: Document Color support #13122
  • #[rust_analyzer::resolve_hint(path::to::something): Will make r-a attempt to resolve the given path, useful for macros to output to so that tokens they full consume can be remapped to a resolving path.
  • #[rust_analyzer::runnable(command arg arg ....)): Will make r-a recognize this as a runnable action (like fn main() or #[test] fn test), putting a runnable lens on top that executes the command with the given args
  • #[rust_analyzer::macro_expansion_token_limit(10000)]: Sets the expansion token limit for the crate or annotated macro call
  • #[rust_analyzer::enum_happy_variant]: Annotate variants to handle them like Some or Ok for assist purposes, https://github.com/rust-lang/rust-analyzer/blob/d6d735e6f20ef78b16a79886fe28bd69cf059504/crates/ide-db/src/ty_filter.rs

Note: names are of course bikesheddable

@Veykril Veykril added fun A technically challenging issue with high impact E-unknown It's unclear if the issue is E-hard or E-easy without digging in A-ide general IDE features labels Feb 25, 2022
@bjorn3
Copy link
Member

bjorn3 commented Feb 25, 2022

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
Copy link
Member Author

Veykril commented Feb 25, 2022

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

@ModProg
Copy link
Contributor

ModProg commented May 17, 2022

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
Copy link
Member Author

Veykril commented May 18, 2022

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
Copy link
Contributor

ModProg commented May 18, 2022

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 #7402 (comment)

@Veykril Veykril added the C-feature Category: feature request label Feb 9, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 20, 2024
…dtwco

Add `rust_analyzer` as a predefined tool

Given all the other rust-lang tools have it, I'd expect r-a to have it too. (we have a few ideas for using this rust-lang/rust-analyzer#11556).
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 24, 2024
…dtwco

Add `rust_analyzer` as a predefined tool

Given all the other rust-lang tools have it, I'd expect r-a to have it too. (we have a few ideas for using this rust-lang/rust-analyzer#11556).
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 24, 2024
…dtwco

Add `rust_analyzer` as a predefined tool

Given all the other rust-lang tools have it, I'd expect r-a to have it too. (we have a few ideas for using this rust-lang/rust-analyzer#11556).
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jun 24, 2024
Rollup merge of rust-lang#125241 - Veykril:tool-rust-analyzer, r=davidtwco

Add `rust_analyzer` as a predefined tool

Given all the other rust-lang tools have it, I'd expect r-a to have it too. (we have a few ideas for using this rust-lang/rust-analyzer#11556).
@ChayimFriedman2
Copy link
Contributor

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
Copy link
Member Author

Veykril commented Sep 1, 2024

No need for that actually, we have gotten the tool namespace in rust-lang/rust#125241 (forgot to update the description here)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ide general IDE features C-feature Category: feature request E-unknown It's unclear if the issue is E-hard or E-easy without digging in fun A technically challenging issue with high impact
Projects
None yet
Development

No branches or pull requests

4 participants