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

macros: Improve IDE support #6968

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

nurmohammed840
Copy link
Contributor

@nurmohammed840 nurmohammed840 commented Nov 12, 2024

This refectory improve performance and enhance better compatibility with IDEs.

Here is two examples,

Screenshot 2024-11-13 013504
Before: Note that there is no inlay hints for function arguments.

Screenshot 2024-11-13 013208
After: Fixed inlay hint hints problem. channel(buffer: .., tokio::spawn(future: ..


Screenshot 2024-11-13 013429
Before: On syntax error. Run Test | Debug button dissipated. which is frustrating because the editor toggles back and forth while typing.

Screenshot 2024-11-13 013319
After: It fix that.


It introduce two changes:

  1. Remove spaned, Because as it's not meant to be used here.
  2. The function body is preserved as is.

@nurmohammed840
Copy link
Contributor Author

I will send a fix tomorrow.

@Darksonn Darksonn added the A-tokio-macros Area: The tokio-macros crate label Nov 12, 2024
@nurmohammed840
Copy link
Contributor Author

What’s really blocking the CI is that,

Current changes preserved async body as-is:

#[tokio::main]
async fn test_with_semicolon_without_return_type() {
    #![deny(clippy::semicolon_if_nothing_returned)]
    #[deny(clippy::semicolon_if_nothing_returned)]
    0;
}

So would convert into:

fn test_with_semicolon_without_return_type() {
    let body = async {
        #![deny(clippy::semicolon_if_nothing_returned)] // ❌
        #[deny(clippy::semicolon_if_nothing_returned)]
        0;
    };
    ...
}

I didn’t realize this, The previous implementation moved global inner attributes outside:

#[deny(clippy::semicolon_if_nothing_returned)]
fn test_with_semicolon_without_return_type() {
    let body = async {
        #[deny(clippy::semicolon_if_nothing_returned)]
        0;
    };
    ...
}

There are many ways to address this issue.
@Darksonn, The real question is, is it worth this fix? The documentation doesn’t mention this behavior.

@Darksonn
Copy link
Contributor

If you believe the output changes are acceptable, you can update the outputs to make the tests pass. See tests-build/README.md for instructions. Then we will review whether the changes are important.

But keep in mind that just because something is not explained in the documentation, that doesn't mean we can just change it. We don't want to break existing users of the macro.

@davidbarsky
Copy link
Member

Speaking as a person who works on rust-analyzer:

  • I think the span changes are probably good?
  • From a hygiene perspective, I worry about the type inference breakage. I think it's important to those to avoid breaking users.
  • From a general "how does this this macro work does it work for IDEs" perspective, having the macro return the original tokens such that the expanded (but incorrect!) macro looks mostly correct would go a long way in terms of providing a good IDE experience.

@nurmohammed840
Copy link
Contributor Author

Oh! It turns out span is used for type suggestion in return or end statements, so I'll revert the previous change.

Seems like it also fix some code suggestion: #3766

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants