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

async-std's attribute macros are not IDE(rust-analyzer) friendly #998

Closed
Veykril opened this issue Nov 18, 2021 · 1 comment
Closed

async-std's attribute macros are not IDE(rust-analyzer) friendly #998

Veykril opened this issue Nov 18, 2021 · 1 comment

Comments

@Veykril
Copy link

Veykril commented Nov 18, 2021

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.

This problem can be observed here:

#[async_std::test]
async fn buggy_autocomplete() {
    let x = 0;
    x.
    //^ cursor right after the dot, then try and request completions (ctrl + space in VSCode)
    // No completions will be suggested, while without the attribute there will
}

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.

Relevant r-a issues rust-lang/rust-analyzer#10468, rust-lang/rust-analyzer#10788 (comment)

Example PR that tokio received as a fix tokio-rs/tokio#4162

@Veykril
Copy link
Author

Veykril commented Dec 14, 2021

Closing this, as we most likely will change our plans which will hopefully no longer require these workarounds rust-lang/rust-analyzer#11014

@Veykril Veykril closed this as completed Dec 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant