From 8be2d1dcbfeff88f47b8bfb9685f2ab45a72efb5 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Fri, 18 Nov 2022 22:14:36 -0600 Subject: Handle language server termination (#4797) This change handles a language server exiting. This was a UX sore-spot: if a language server crashed, Helix did not recognize the exit and continued to send requests to it. All requests would timeout since they would not receive responses. This would also hold-up Helix closing itself down since it would try to gracefully shutdown the server which is implemented in the LSP spec as a request. We could attempt to automatically restart the language server on crash. I left this for future work since that change will need to be slightly complicated: it will need to cover the case of a language server repeatedly crashing.--- helix-lsp/src/transport.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'helix-lsp/src/transport.rs') diff --git a/helix-lsp/src/transport.rs b/helix-lsp/src/transport.rs index 8aaeae3d..68b3d15e 100644 --- a/helix-lsp/src/transport.rs +++ b/helix-lsp/src/transport.rs @@ -250,6 +250,26 @@ impl Transport { } }; } + Err(Error::StreamClosed) => { + // Hack: inject a terminated notification so we trigger code that needs to happen after exit + use lsp_types::notification::Notification as _; + let notification = + ServerMessage::Call(jsonrpc::Call::Notification(jsonrpc::Notification { + jsonrpc: None, + method: lsp_types::notification::Exit::METHOD.to_string(), + params: jsonrpc::Params::None, + })); + match transport + .process_server_message(&client_tx, notification) + .await + { + Ok(_) => {} + Err(err) => { + error!("err: <- {:?}", err); + } + } + break; + } Err(err) => { error!("err: <- {:?}", err); break; -- cgit v1.2.3-70-g09d2