summaryrefslogtreecommitdiff
path: root/helix-lsp/src
diff options
context:
space:
mode:
authorMichael Davis2022-11-19 04:14:36 +0000
committerGitHub2022-11-19 04:14:36 +0000
commit8be2d1dcbfeff88f47b8bfb9685f2ab45a72efb5 (patch)
tree4526d557af97febb6b52f2b9676581eb2fae549a /helix-lsp/src
parent598bd8bf11b0f6ee6cf8b59c3415fa0d5d6cd1ff (diff)
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.
Diffstat (limited to 'helix-lsp/src')
-rw-r--r--helix-lsp/src/lib.rs7
-rw-r--r--helix-lsp/src/transport.rs20
2 files changed, 27 insertions, 0 deletions
diff --git a/helix-lsp/src/lib.rs b/helix-lsp/src/lib.rs
index feeedc96..5de76c6c 100644
--- a/helix-lsp/src/lib.rs
+++ b/helix-lsp/src/lib.rs
@@ -282,6 +282,8 @@ impl MethodCall {
pub enum Notification {
// we inject this notification to signal the LSP is ready
Initialized,
+ // and this notification to signal that the LSP exited
+ Exit,
PublishDiagnostics(lsp::PublishDiagnosticsParams),
ShowMessage(lsp::ShowMessageParams),
LogMessage(lsp::LogMessageParams),
@@ -294,6 +296,7 @@ impl Notification {
let notification = match method {
lsp::notification::Initialized::METHOD => Self::Initialized,
+ lsp::notification::Exit::METHOD => Self::Exit,
lsp::notification::PublishDiagnostics::METHOD => {
let params: lsp::PublishDiagnosticsParams = params.parse()?;
Self::PublishDiagnostics(params)
@@ -350,6 +353,10 @@ impl Registry {
.map(|(_, client)| client.as_ref())
}
+ pub fn remove_by_id(&mut self, id: usize) {
+ self.inner.retain(|_, (client_id, _)| client_id != &id)
+ }
+
pub fn restart(
&mut self,
language_config: &LanguageConfiguration,
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;