fix: Don't respond with an error when requesting a shutdown while starting

This commit is contained in:
Lukas Wirth 2022-10-24 14:56:58 +02:00
parent 43fb9563b2
commit 6a00e14c7a

View File

@ -607,30 +607,34 @@ impl GlobalState {
/// Handles a request. /// Handles a request.
fn on_request(&mut self, req: Request) { fn on_request(&mut self, req: Request) {
if self.shutdown_requested { let mut dispatcher = RequestDispatcher { req: Some(req), global_state: self };
self.respond(lsp_server::Response::new_err( dispatcher.on_sync_mut::<lsp_types::request::Shutdown>(|s, ()| {
req.id, s.shutdown_requested = true;
lsp_server::ErrorCode::InvalidRequest as i32, Ok(())
"Shutdown already requested.".to_owned(), });
));
return; 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 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;
}
} }
// Avoid flashing a bunch of unresolved references during initial load. dispatcher
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;
}
RequestDispatcher { req: Some(req), global_state: self }
.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::ReloadWorkspace>(handlers::handle_workspace_reload)
.on_sync_mut::<lsp_ext::MemoryUsage>(handlers::handle_memory_usage) .on_sync_mut::<lsp_ext::MemoryUsage>(handlers::handle_memory_usage)
.on_sync_mut::<lsp_ext::ShuffleCrateGraph>(handlers::handle_shuffle_crate_graph) .on_sync_mut::<lsp_ext::ShuffleCrateGraph>(handlers::handle_shuffle_crate_graph)