Skip to content

Commit

Permalink
Auto merge of rust-lang#12007 - edwin0cheng:restart-proc-macro-reload…
Browse files Browse the repository at this point in the history
…, r=jonas-schievink

Restart proc-macro client when server reload

Fix rust-lang#10719
  • Loading branch information
bors committed Apr 25, 2022
2 parents 1d2bd0e + 8f616a6 commit 60c4f07
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
7 changes: 7 additions & 0 deletions crates/rust-analyzer/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ use crate::{
to_proto, LspError, Result,
};

pub(crate) fn handle_workspace_reload(state: &mut GlobalState, _: ()) -> Result<()> {
state.proc_macro_client = None;
state.fetch_workspaces_queue.request_op("reload workspace request".to_string());
state.fetch_build_data_queue.request_op("reload workspace request".to_string());
Ok(())
}

pub(crate) fn handle_analyzer_status(
snap: GlobalStateSnapshot,
params: lsp_ext::AnalyzerStatusParams,
Expand Down
13 changes: 7 additions & 6 deletions crates/rust-analyzer/src/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,13 @@ impl GlobalState {
self.fetch_workspaces(cause);
}
}
if let Some(cause) = self.fetch_build_data_queue.should_start_op() {
self.fetch_build_data(cause);

if !self.fetch_workspaces_queue.op_in_progress() {
if let Some(cause) = self.fetch_build_data_queue.should_start_op() {
self.fetch_build_data(cause);
}
}

if let Some(cause) = self.prime_caches_queue.should_start_op() {
tracing::debug!(%cause, "will prime caches");
let num_worker_threads = self.config.prime_caches_num_threads();
Expand Down Expand Up @@ -571,14 +575,11 @@ impl GlobalState {
}

RequestDispatcher { req: Some(req), global_state: self }
.on_sync_mut::<lsp_ext::ReloadWorkspace>(|s, ()| {
s.fetch_workspaces_queue.request_op("reload workspace request".to_string());
Ok(())
})?
.on_sync_mut::<lsp_types::request::Shutdown>(|s, ()| {
s.shutdown_requested = true;
Ok(())
})?
.on_sync_mut::<lsp_ext::ReloadWorkspace>(handlers::handle_workspace_reload)?
.on_sync_mut::<lsp_ext::MemoryUsage>(handlers::handle_memory_usage)?
.on_sync_mut::<lsp_ext::ShuffleCrateGraph>(handlers::handle_shuffle_crate_graph)?
.on_sync::<lsp_ext::JoinLines>(handlers::handle_join_lines)?
Expand Down

0 comments on commit 60c4f07

Please sign in to comment.