From ba17c69217faabff0ca0c0a6a66548562774607b Mon Sep 17 00:00:00 2001 From: Pascal Kuthe Date: Sat, 20 May 2023 21:29:23 +0200 Subject: [PATCH] consistent diagnostic sorting --- helix-term/src/application.rs | 4 +++- helix-view/src/document.rs | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index f8140f986cdd3..1aec7fa2ebbd3 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -928,7 +928,9 @@ impl Application { // Sort diagnostics first by severity and then by line numbers. // Note: The `lsp::DiagnosticSeverity` enum is already defined in decreasing order - diagnostics.sort_unstable_by_key(|(d, _)| (d.severity, d.range.start)); + diagnostics.sort_unstable_by_key(|(d, server_id)| { + (d.severity, d.range.start, *server_id) + }); } Notification::ShowMessage(params) => { log::warn!("unhandled window/showMessage: {:?}", params); diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 654e726d3161d..0e6d3f977c311 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -1203,6 +1203,14 @@ impl Document { self.diagnostics .sort_unstable_by_key(|diagnostic| diagnostic.range); + } + self.diagnostics.sort_unstable_by_key(|diagnostic| { + ( + diagnostic.range, + diagnostic.severity, + diagnostic.language_server_id, + ) + }); // Update the inlay hint annotations' positions, helping ensure they are displayed in the proper place let apply_inlay_hint_changes = |annotations: &mut Rc<[InlineAnnotation]>| { @@ -1699,8 +1707,13 @@ impl Document { }); } self.diagnostics.extend(diagnostics); - self.diagnostics - .sort_unstable_by_key(|diagnostic| diagnostic.range); + self.diagnostics.sort_unstable_by_key(|diagnostic| { + ( + diagnostic.range, + diagnostic.severity, + diagnostic.language_server_id, + ) + }); } pub fn clear_diagnostics(&mut self, language_server_id: usize) {