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-term/src/application.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'helix-term/src/application.rs') diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 39a6532d..99d3af18 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -871,6 +871,32 @@ impl Application { Notification::ProgressMessage(_params) => { // do nothing } + Notification::Exit => { + self.editor.set_status("Language server exited"); + + // Clear any diagnostics for documents with this server open. + let urls: Vec<_> = self + .editor + .documents_mut() + .filter_map(|doc| { + if doc.language_server().map(|server| server.id()) + == Some(server_id) + { + doc.set_diagnostics(Vec::new()); + doc.url() + } else { + None + } + }) + .collect(); + + for url in urls { + self.editor.diagnostics.remove(&url); + } + + // Remove the language server from the registry. + self.editor.language_servers.remove_by_id(server_id); + } } } Call::MethodCall(helix_lsp::jsonrpc::MethodCall { -- cgit v1.2.3-70-g09d2