Skip to content

Auto-complete didn't work inside proc macro . #15122

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

Closed
nurmohammed840 opened this issue Jun 24, 2023 · 4 comments
Closed

Auto-complete didn't work inside proc macro . #15122

nurmohammed840 opened this issue Jun 24, 2023 · 4 comments
Labels
C-bug Category: bug

Comments

@nurmohammed840
Copy link

See: dtolnay/syn#1472

@nurmohammed840 nurmohammed840 added the C-bug Category: bug label Jun 24, 2023
@flodiebold
Copy link
Member

With a function-like proc macro, rust-analyzer has no idea that the tokens inside are supposed to be code, so it can't do any error recovery. And syn will just fail to parse the incomplete code num., and the proc macro won't return anything, so rust-analyzer has no way of knowing what to do with it. See also #7402. You can make this proc macro work by not parsing the input, and just passing it through. Or if you need to analyze it somehow, you need an error-resilient parser.

@flodiebold flodiebold closed this as not planned Won't fix, can't repro, duplicate, stale Jun 24, 2023
@nurmohammed840
Copy link
Author

nurmohammed840 commented Jun 24, 2023

I think you misunderstood, The code is not incomplete, and the proc macro do return valid code, with code span preserved.

@flodiebold
Copy link
Member

flodiebold commented Jun 24, 2023

When you're writing

fn main() {
    code!({
        let num = 42;
        num.  // No code completion ☹️
    });
}

the code is incomplete and not a valid expression, so syn::parse_macro_input!(input) fails and the proc macro returns an error.

@nurmohammed840
Copy link
Author

I re-implemented my proc-macro with a more IDE friendly, which solved this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants