Unnamed repository; edit this file 'description' to name the repository.
Auto merge of #13476 - Veykril:prefer-shutdown, r=Veykril
fix: Don't respond with an error when requesting a shutdown while starting
bors 2022-10-24
parent 43fb956 · parent 6a00e14 · commit 98aa678
-rw-r--r--crates/rust-analyzer/src/main_loop.rs46
1 files changed, 25 insertions, 21 deletions
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 2c928a5804..7d10dc5d15 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -607,30 +607,34 @@ impl GlobalState {
/// Handles a request.
fn on_request(&mut self, req: Request) {
- if self.shutdown_requested {
- self.respond(lsp_server::Response::new_err(
- req.id,
- lsp_server::ErrorCode::InvalidRequest as i32,
- "Shutdown already requested.".to_owned(),
- ));
- return;
- }
+ let mut dispatcher = RequestDispatcher { req: Some(req), global_state: self };
+ dispatcher.on_sync_mut::<lsp_types::request::Shutdown>(|s, ()| {
+ s.shutdown_requested = true;
+ Ok(())
+ });
+
+ if let RequestDispatcher { req: Some(req), global_state: this } = &mut dispatcher {
+ if this.shutdown_requested {
+ this.respond(lsp_server::Response::new_err(
+ req.id.clone(),
+ lsp_server::ErrorCode::InvalidRequest as i32,
+ "Shutdown already requested.".to_owned(),
+ ));
+ return;
+ }
- // Avoid flashing a bunch of unresolved references during initial load.
- if self.workspaces.is_empty() && !self.is_quiescent() {
- self.respond(lsp_server::Response::new_err(
- req.id,
- lsp_server::ErrorCode::ContentModified as i32,
- "waiting for cargo metadata or cargo check".to_owned(),
- ));
- return;
+ // Avoid flashing a bunch of unresolved references during initial load.
+ if this.workspaces.is_empty() && !this.is_quiescent() {
+ this.respond(lsp_server::Response::new_err(
+ req.id.clone(),
+ lsp_server::ErrorCode::ContentModified as i32,
+ "waiting for cargo metadata or cargo check".to_owned(),
+ ));
+ return;
+ }
}
- RequestDispatcher { req: Some(req), global_state: self }
- .on_sync_mut::<lsp_types::request::Shutdown>(|s, ()| {
- s.shutdown_requested = true;
- Ok(())
- })
+ dispatcher
.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)