-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Set RUST_IDE_PROC_MACRO_COMPLETION
and RUST_IDE_PROC_MACRO_COMPLETION_DUMMY_IDENTIFIER
for proc macros
#13731
Comments
The way this is done I think will break for r-a due to how our completions work 😕 We expand proc-macros twice, once properly and once speculatively(this is where we would set the env vars), but the infra falls down if the expansions start to differ in structure too much I believe. We also would need to re-expand the non-speculative one for completions which seems not necessarily ideal. |
Yeah, gating error resilience behind a special flag is the opposite of helpful :/ The dummy identifier thing we can do though. |
Btw in IntelliJ Rust we also expand proc-macros twice, but use for completion purposes only speculatively run (with dummy identifier inserted). I think we could use both as well, but I'd anyway set environment variables only during the speculative run. |
The problem is we can't use the speculative one for semantic analysis due to how salsa works, thats where the original expansion comes in. And therefor if the two expansions differ too much we run into problems (which tbf already happens in some scenarios where in the original expansion an identifier is missing) |
Could you explain this a little more? I think this is absolutely not a problem for IntelliJ Rust, in out case they can differ in any way. |
I don't understand the notion that error resilience is only necessary for completion anyway. We also want e.g. go to definition to work in an incomplete macro. |
The main idea behind it is custom completion, not error resilience. For example, standard tag name completion in yew (div, span, etc), or attribute names completion in yew ( |
Also,
|
We're all for supporting custom completions, but that only requires
I don't know if that's true. But "for IDE" and "for completions" are still different; I can somewhat see the point of letting the proc macro know it's running in an IDE, but then we would set the variable all the time and not just for completions. Which might be what ends up happening if enough macros do gate error resilience on the variable.
I don't know how the |
imo this is a design flaw of syn it works great for the compiler, but not for IDEs even if the IDE fixes up syntax errors in attribute inputs.
Here I agree with what flodiebold said, if the IDE is expanding a proc-macro it should unconditionally set this env var, not just when completing. There are more features where I can think of a proc-macro helping out the IDE (like re-mapping spans for input tokens that usually disappear in the expansion, think (non-derive) helper attributes of attributes like salsa uses). I don't think setting this solely for completions is more beneficial than always setting it when the IDE does an expansion opposed to the compiler (ignoring the fact that r-a has trouble with the completion only var or not). Also just a general aside, I like that you are exploring ways to make proc-macros help out IDEs :) This has been something I've been thinking about for a while as well, but never tackled since r-a's token map needs a rewrite before we can do any of the ideas properly I had so far in mind. |
Glad to hear! Thank you, guys!
Well, strictly speaking, just the presence of
You can compare my approach in yew (yewstack/yew#2972) and your approach in tokio (tokio-rs/tokio#4162). The difference is that during completion you shouldn't care about returning
To be honest, we set such a variable since the very beginning, but its name is not very generic 🥶. At least we could just start with completion, it looks like the least controversial place. |
As mentioned, RA mainly uses the results from expanding the macro as written without the dummy identifier for analysis during completion (scope, types etc); the dummy identifier is only used to get the syntactic context. We can't currently do semantic analysis on a "fake" (speculative) file where the dummy identifier is inserted (because that would involve changing the salsa inputs, potentially blowing up all caches, and then changing them back). Which also means that if there are further macro calls inside the speculative expansion, we can only resolve them if they also exist inside the normal expansion; those are the problems Veykril was referring to when the two expansions differ too much, I think. |
CC intellij-rust/intellij-rust#9711, yewstack/yew#2972
The text was updated successfully, but these errors were encountered: