From 39b3d81abf4cc3aede4b739e9aaf6a83899cb22c Mon Sep 17 00:00:00 2001 From: Pascal Kuthe Date: Mon, 29 Jan 2024 17:07:16 +0100 Subject: [PATCH] stable sort diagnostics to avoid flickering --- helix-term/src/application.rs | 7 +++---- helix-view/src/document.rs | 8 +++----- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 3d10862d1..4c305f6ac 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -771,7 +771,7 @@ impl Application { // Note: The `lsp::DiagnosticSeverity` enum is already defined in decreasing order params .diagnostics - .sort_unstable_by_key(|d| (d.severity, d.range.start)); + .sort_by_key(|d| (d.severity, d.range.start)); } for source in &lang_conf.persistent_diagnostic_sources { let new_diagnostics = params @@ -812,9 +812,8 @@ 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, server_id)| { - (d.severity, d.range.start, *server_id) - }); + diagnostics + .sort_by_key(|(d, server_id)| (d.severity, d.range.start, *server_id)); if let Some(doc) = doc { let diagnostic_of_language_server_and_not_in_unchanged_sources = diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 412f79fa2..f3ace89e5 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -99,7 +99,6 @@ impl Serialize for Mode { serializer.collect_str(self) } } - /// A snapshot of the text of a document that we want to write out to disk #[derive(Debug, Clone)] pub struct DocumentSavedEvent { @@ -1321,7 +1320,7 @@ impl Document { true }); - self.diagnostics.sort_unstable_by_key(|diagnostic| { + self.diagnostics.sort_by_key(|diagnostic| { (diagnostic.range, diagnostic.severity, diagnostic.provider) }); @@ -1911,9 +1910,8 @@ impl Document { }); } self.diagnostics.extend(diagnostics); - self.diagnostics.sort_unstable_by_key(|diagnostic| { - (diagnostic.range, diagnostic.severity, diagnostic.provider) - }); + self.diagnostics + .sort_by_key(|diagnostic| (diagnostic.range, diagnostic.severity, diagnostic.provider)); } /// clears diagnostics for a given language server id if set, otherwise all diagnostics are cleared