-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Allow proc macros to expose their grammar to rust analyzer for syntax error understanding #7402
Comments
The proc macros need to be written in a way that passes through even incomplete syntax. Most proc macros (maybe all) will probably fail to expand if their input is not syntactically correct. They would instead need to try to expand as best as possible. Ideally there should be a way for proc macros to return an expansion, but also signal an error (this might be an interesting thing to prototype / think about, but would require support in the compiler); but for proc macros where parts of the input are just normal Rust syntax that's passed through to a certain place in the output, that's not really necessary (they can just pass through the invalid syntax and rely on the compiler to complain afterwards). I think it'd be interesting to look at concrete cases that aren't working right now and what it would take to make them work. (I think "exposing their grammar" is probably not necessary or the right approach, except maybe for syntax highlighting completely custom DSLs...) |
I don't think this is much of a rust-analyzer issue, the proc macro ecosystem just needs to become more IDE-friendly |
Totally agree on @jonas-schievink and @flodiebold . And one thing we could improve here is : We do not implement all span information for proc-macro (which is hard) such that error recovery is impossible in some cases. |
@ogoffart of https://sixtyfps.io came up with ingeniously simple scheme for this: I have some ideas on how rust-analyzer could use some kind of Notably, we already do the |
cc @vlad20012 |
I could imagine one case where exposing something like a gramar would make sense, and that is proc macros that use a relatively simple syntax to just accept some attributes like e.g.
|
i am writing a custom dsl macro and would love to add intellisense support for the dsl, so i found this issue. has there been any movement on this elsewhere, or is this issue still the current state? i'd really like to make the experience as good as i can get it, the dsl is actually effectively rust syntax but the things being named in the dsl aren't actually in the program. right now i'm vaguely thinking i can generate the things being named into actual syntax, then produce partially formed token streams in an effort to contort Rust and R-A into producing completions and useful errors... i'm not sure how feasible that is but it's the closest i've got |
The best info on this we have currently is #15452. |
oh awesome, thanks! sounds like the rough idea should work then! |
I have opened a discussion thread in the Rust Internals Forum related to this issue. |
My understanding of rust-analyzer - correct me if I'm wrong - is that it can partially analyze code with syntax errors as long as it doesn't use proc macros, and that this is core functionality as part of providing completions for partially written lines such as
let x =
. If that is correct, what would it take for proc macros to expose their grammar to get the same level of support as the rest of rust when code is incomplete? I'm most interested in getting tab completion for identifiers in proc macros, because I have several different proc macros I'd like to use very heavily and don't want to lose completion functionality in them.The text was updated successfully, but these errors were encountered: