changeset 6534:5d56ee753e84

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.
author Michael Davis <mcarsondavis@gmail.com>
date Tue, 04 Feb 2025 10:05:00 -0500
parents 14c4fd7cf447
children 66ddbf70720b
files helix-view/src/handlers/lsp.rs
diffstat 1 files changed, 11 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/helix-view/src/handlers/lsp.rs	Tue Feb 04 09:54:39 2025 -0500
+++ b/helix-view/src/handlers/lsp.rs	Tue Feb 04 10:05:00 2025 -0500
@@ -281,17 +281,17 @@
         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