fix: Spawn proc-macro servers on requests clearing the client cache - #22865
Merged
Conversation
Contributor
Veykril
approved these changes
Jul 19, 2026
Veykril
enabled auto-merge
July 19, 2026 15:51
Wilfred
added a commit
to Wilfred/rust-analyzer
that referenced
this pull request
Aug 10, 2026
fetch_proc_macros() zips proc_macro_clients with a per-workspace vec. We therefore require proc_macro_clients to have an item for every workspace, or we get "proc-macro-srv is not running" and no macro expansion for some workspaces. This issue is more noticeable when using a discovery command, where it's common to have have several workspaces, but it can occur in plain cargo repositories too. The logic was essentially `if !same_workspaces`, but this doesn't actually work. When a new workspace is added, switch_workspaces() updates self.workspaces, pushes to fetch_build_data_queue, and returns early. When we actually check the proc macro clients, on the second invocation, we're seeing the *new* self.workspaces already and it looks like nothing has changed! This was broken in rust-lang#22766, and only partially fixed in rust-lang#22865. Revert the code, and expand the doc comments. A better solution would be to track proc macro initialisation state properly, but this fixes r-a on the >1 workspaces case today. AI disclosure: Bisected with help by AI.
Wilfred
added a commit
to Wilfred/rust-analyzer
that referenced
this pull request
Aug 10, 2026
fetch_proc_macros() zips proc_macro_clients with a per-workspace vec. We therefore require proc_macro_clients to have an item for every workspace, or we get "proc-macro-srv is not running" and no macro expansion for some workspaces. This issue is more noticeable when using a discovery command, where it's common to have have several workspaces, but it can occur in plain cargo repositories too. The logic was essentially `if !same_workspaces`, but this doesn't actually work. When a new workspace is added, switch_workspaces() updates self.workspaces, pushes to fetch_build_data_queue, and returns early. When we actually check the proc macro clients, on the second invocation, we're seeing the *new* self.workspaces already and it looks like nothing has changed! This was broken in rust-lang#22766, and only partially fixed in rust-lang#22865. Revert the code, and expand the doc comments. A better solution would be to track proc macro initialisation state properly, but this fixes r-a on the >1 workspaces case today. AI disclosure: Bisected with help by AI.
lnicola
pushed a commit
to lnicola/rust
that referenced
this pull request
Aug 17, 2026
fetch_proc_macros() zips proc_macro_clients with a per-workspace vec. We therefore require proc_macro_clients to have an item for every workspace, or we get "proc-macro-srv is not running" and no macro expansion for some workspaces. This issue is more noticeable when using a discovery command, where it's common to have have several workspaces, but it can occur in plain cargo repositories too. The logic was essentially `if !same_workspaces`, but this doesn't actually work. When a new workspace is added, switch_workspaces() updates self.workspaces, pushes to fetch_build_data_queue, and returns early. When we actually check the proc macro clients, on the second invocation, we're seeing the *new* self.workspaces already and it looks like nothing has changed! This was broken in rust-lang/rust-analyzer#22766, and only partially fixed in rust-lang/rust-analyzer#22865. Revert the code, and expand the doc comments. A better solution would be to track proc macro initialisation state properly, but this fixes r-a on the >1 workspaces case today. AI disclosure: Bisected with help by AI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes the
proc-macro-srv is not runningerror that occurs on Rebuild proc-macros operation.The
proc_macro_clientscache is cleared inhandle_workspace_reloadandhandle_workspace_rebuild, thus requiring an additional check to spawn new clients.Error is thrown here
rust-analyzer/crates/rust-analyzer/src/reload.rs
Lines 454 to 456 in 3eaae41
Cause
proc_macro_clientsis cleared in the following two places:rust-analyzer/crates/rust-analyzer/src/handlers/request.rs
Lines 60 to 62 in 3eaae41
and
rust-analyzer/crates/rust-analyzer/src/handlers/request.rs
Lines 69 to 71 in 3eaae41
Resolution
Add
is_emptycheck to the previously removed length check.