Skip to content

Commit a7f4ee1

Browse files
poliorceticsaotarola
authored andcommitted
Update diagnostics correctly on LSP exit (helix-editor#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
1 parent b6a3afb commit a7f4ee1

2 files changed

Lines changed: 12 additions & 16 deletions

File tree

helix-term/src/application.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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 {

0 commit comments

Comments
 (0)