Unnamed repository; edit this file 'description' to name the repository.
LSP: Properly discard out-of-date diagnostics
Previously the `filter` caused the diagnostics to not be attached to the document - which is good - but the out-of-date diagnostics were still inserted into the global (editor-wide) diagnostic set. Instead we should completely discard out-of-date diagnostics.
Michael Davis 2025-02-04
parent 62625ed · commit 313a647
-rw-r--r--helix-view/src/handlers/lsp.rs22
1 files changed, 11 insertions, 11 deletions
diff --git a/helix-view/src/handlers/lsp.rs b/helix-view/src/handlers/lsp.rs
index 3f0cfbfc..dc2e1755 100644
--- a/helix-view/src/handlers/lsp.rs
+++ b/helix-view/src/handlers/lsp.rs
@@ -281,17 +281,17 @@ impl Editor {
version: Option<i32>,
mut diagnostics: Vec<lsp::Diagnostic>,
) {
- let doc = self.documents.values_mut()
- .find(|doc| doc.uri().is_some_and(|u| u == uri))
- .filter(|doc| {
- if let Some(version) = version {
- if version != doc.version() {
- log::info!("Version ({version}) is out of date for {uri:?} (expected ({}), dropping PublishDiagnostic notification", doc.version());
- return false;
- }
- }
- true
- });
+ let doc = self
+ .documents
+ .values_mut()
+ .find(|doc| doc.uri().is_some_and(|u| u == uri));
+
+ if let Some((version, doc)) = version.zip(doc.as_ref()) {
+ if version != doc.version() {
+ log::info!("Version ({version}) is out of date for {uri:?} (expected ({})), dropping PublishDiagnostic notification", doc.version());
+ return;
+ }
+ }
let mut unchanged_diag_sources = Vec::new();
if let Some((lang_conf, old_diagnostics)) = doc