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

Tokio's attribute macros are not IDE friendly #4154

Closed
Veykril opened this issue Oct 6, 2021 · 1 comment · Fixed by #4162
Closed

Tokio's attribute macros are not IDE friendly #4154

Veykril opened this issue Oct 6, 2021 · 1 comment · Fixed by #4162
Labels
A-tokio-macros Area: The tokio-macros crate C-feature-request Category: A feature request.

Comments

@Veykril
Copy link
Contributor

Veykril commented Oct 6, 2021

Is your feature request related to a problem? Please describe.
In short this is a problem with how syn and attributes using syn implement failure, as these crates tend to just discard the entire attributed item on a parsing failure, replacing it with a compile_error! invocation. This has the side effect that when typing inside an item, a user may momentarily create invalid syntax causing the item to be fully discarded resulting in loss of IDE features as the item now effectively does not exist in the file until this syntax error has been fixed.

Describe the solution you'd like
A simple solution to this problem is to change the attributes such that when they error, they re-emit the original item with the compile_error! invocation, that way IDEs will still see the item even if the attribute fails causing IDE features to continue to function.

Sidenote: This will fix the general problem, but if the attribute introduces new usable items inside the item they will of course not always be visible in completions with just this fix. An ideal fix would be to make the attribute do parsing with recovery in such cases if required.

Additional context
This is becoming a bigger problem now as Rust-Analyzer enabled attribute expansion by default starting this week.

Note that rust-analyzer currently does not resolve tokio's macros unless tokio-macros has been added to the rust-analyzer.cargo.unsetTest list due to the #[cfg(not(test))] // Work around for rust-lang/rust#62127 workarounds.

See a relevant RA issue rust-lang/rust-analyzer#10468

@Veykril Veykril added A-tokio Area: The main tokio crate C-feature-request Category: A feature request. labels Oct 6, 2021
@Darksonn Darksonn added A-tokio-macros Area: The tokio-macros crate and removed A-tokio Area: The main tokio crate labels Oct 6, 2021
@Darksonn
Copy link
Contributor

Darksonn commented Oct 6, 2021

We are certainly open to changing how the macro works to make it work better together with rust-analyzer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio-macros Area: The tokio-macros crate C-feature-request Category: A feature request.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants