-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Proc Macro Expansion with a rust-project.json
Regressed with #14405
#14417
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
Comments
Ah, I know why I think. We only set the proc-macros if build scripts have run, otherwise we overwrite it for a better diagnostic which obviously causes problems in case of |
Okay there seem to be two bugs here, the id mismatch (which conveniently has a difference of 11 which is exactly the number of sysroot crates r-a knows about :) ) and us not loading proc-macros when build-scripts don't run. |
Yup! I just saw the 11 crate difference when debugging in GlobalWorkspaces. The |
Okay I found the id mismatch bug I think, will push out a PR for that |
#14419 would be great if you could check that commit. ( I still think the other issue will pop up now though, making it so we don't load proc-macros) |
It works!
Oh, I think that explains why when I add a new workspace via the temporary command, the newly added workspace doesn't have proc macros. It's always subsequent workspaces that lack proc macros. |
The relevant part there is here rust-analyzer/crates/rust-analyzer/src/reload.rs Lines 450 to 463 in b99d5eb
Note that we only call |
Resolved by #14419. |
Thanks for pointing this out—I'll play around with this bit and see if I can make this a little better in the process. |
…paces-to-have-proc-macros, r=Veykril fix: allow new, subsequent `rust-project.json`-based workspaces to get proc macro expansion As detailed in #14417 (comment), `rust-project.json` workspaces added after the initial `rust-project.json`-based workspace was already indexed by rust-analyzer would not receive procedural macro expansion despite `config.expand_proc_macros` returning true. To fix this issue: 1. I changed `reload.rs` to check which workspaces are newly added. 2. Spawned new procedural macro expansion servers based on the _new_ workspaces. 1. This is to prevent spawning duplicate procedural macro expansion servers for already existing workspaces. While the overall memory usage of duplicate procedural macro servers is minimal, this is more about the _principle_ of not leaking processes 😅. 3. Launched procedural macro expansion if any workspaces are `rust-project.json`-based _or_ `same_workspaces` is true. `same_workspaces` being true (and reachable) indicates that that build scripts have finished building (in Cargo-based projects), while the build scripts in `rust-project.json`-based projects have _already been built_ by the build system that produced the `rust-project.json`. I couldn't really think of structuring this code in a better way without engaging with #7444.
…paces-to-have-proc-macros, r=Veykril fix: allow new, subsequent `rust-project.json`-based workspaces to get proc macro expansion As detailed in #14417 (comment), `rust-project.json` workspaces added after the initial `rust-project.json`-based workspace was already indexed by rust-analyzer would not receive procedural macro expansion despite `config.expand_proc_macros` returning true. To fix this issue: 1. I changed `reload.rs` to check which workspaces are newly added. 2. Spawned new procedural macro expansion servers based on the _new_ workspaces. 1. This is to prevent spawning duplicate procedural macro expansion servers for already existing workspaces. While the overall memory usage of duplicate procedural macro servers is minimal, this is more about the _principle_ of not leaking processes 😅. 3. Launched procedural macro expansion if any workspaces are `rust-project.json`-based _or_ `same_workspaces` is true. `same_workspaces` being true (and reachable) indicates that that build scripts have finished building (in Cargo-based projects), while the build scripts in `rust-project.json`-based projects have _already been built_ by the build system that produced the `rust-project.json`. I couldn't really think of structuring this code in a better way without engaging with #7444.
rust-analyzer version: rust-analyzer version: 0.0.0 (f85fc28 2023-03-26) (I'm building from source.)
rustc version: (eg. output of
rustc -V
): rustc 1.68.1 (8460ca823 2023-03-20)relevant settings: I'm using this with a
rust-project.json
sourced from Buck. I can't provide a minimal reproduction at the moment.Hi! This is not particularly urgent issue, but I've noticed that procedural macro expansion has regressed when used with a rust-project.json since #14405 (this issue does not exist with #14404). This manifests with the error:
However, rust-analyzer still correctly identifies the source crate,
_serde_derive_1.0.152
.I haven't fully tracked down the issue, but I've noticed that in
hir-def/src/nameres/collector.rs
theCrateId
forserde_derive
indb.crate_graph()
is 27, but indb.proc_macros()
,serde_derive
has aCrateId
of 16. I'll dig into this more tomorrow.The text was updated successfully, but these errors were encountered: