on master help sign in
Update diagnostics correctly on LSP exit (#7111)

* chore: avoid format! call with argument when useless * feat: also clear diagnostics for unopened documents when exiting an LSP * feat: we already worked on `self.editor.diagnostics` no need to redo the checks

commit8e2660b5cc86266f90926aefe1470f48c801f8bc authorPoliorcetics <poliorcetics@users.noreply.github.com> dateTue 23 May 2023, 12:33 (3 years ago) parent6043c3c
2 files changed+12−16
helix-term/src/application.rs+11−15 helix-term/src/ui/statusline.rs+1−1
helix-term/src/application.rs+11−15
@@ -964,22 +964,18 @@ impl Application {
964964 Notification::Exit => {
965965 self.editor.set_status("Language server exited");
966966
967− // Clear any diagnostics for documents with this server open.
968− let urls: Vec<_> = self
969− .editor
970− .documents_mut()
971− .filter_map(|doc| {
972− if doc.supports_language_server(server_id) {
973− doc.clear_diagnostics(server_id);
974− doc.url()
975− } else {
976− None
977− }
978− })
979− .collect();
967+ // LSPs may produce diagnostics for files that haven't been opened in helix,
968+ // we need to clear those and remove the entries from the list if this leads to
969+ // an empty diagnostic list for said files
970+ for diags in self.editor.diagnostics.values_mut() {
971+ diags.retain(|(_, lsp_id)| *lsp_id != server_id);
972+ }
980973
981− for url in urls {
982− self.editor.diagnostics.remove(&url);
974+ self.editor.diagnostics.retain(|_, diags| !diags.is_empty());
975+
976+ // Clear any diagnostics for documents with this server open.
977+ for doc in self.editor.documents_mut() {
978+ doc.clear_diagnostics(server_id);
983979 }
984980
985981 // Remove the language server from the registry.
helix-term/src/ui/statusline.rs+1−1
@@ -275,7 +275,7 @@ where
275275 });
276276
277277 if warnings > 0 || errors > 0 {
278− write(context, format!(" {} ", "W"), None);
278+ write(context, " W ".into(), None);
279279 }
280280
281281 if warnings > 0 {