From 131f0b366d170c7526e5e47c3ec0625acab4a87f Mon Sep 17 00:00:00 2001 From: Sofus Addington Date: Sun, 1 Sep 2024 21:15:01 +0200 Subject: [PATCH] Handle multiple documents in pull diagnostics event --- helix-term/src/application.rs | 1 - helix-term/src/handlers/diagnostics.rs | 43 +++++++++++++------------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 0f514e271..3aec6c5c5 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -1036,7 +1036,6 @@ impl Application { } Ok(MethodCall::WorkspaceDiagnosticRefresh) => { - log::warn!("Sofus refresh"); for document in self.editor.documents() { let language_server = language_server!(); handlers::diagnostics::pull_diagnostics_for_document( diff --git a/helix-term/src/handlers/diagnostics.rs b/helix-term/src/handlers/diagnostics.rs index 516c57579..a1af4ff93 100644 --- a/helix-term/src/handlers/diagnostics.rs +++ b/helix-term/src/handlers/diagnostics.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use std::time::Duration; use helix_core::syntax::LanguageServerFeature; @@ -71,12 +71,14 @@ pub(super) fn register_hooks(handlers: &Handlers) { #[derive(Debug)] pub(super) struct PullDiagnosticsHandler { - document_id: Option, + document_ids: HashSet, } impl PullDiagnosticsHandler { pub fn new() -> PullDiagnosticsHandler { - PullDiagnosticsHandler { document_id: None } + PullDiagnosticsHandler { + document_ids: [].into(), + } } } @@ -88,29 +90,26 @@ impl helix_event::AsyncHook for PullDiagnosticsHandler { event: Self::Event, _: Option, ) -> Option { - self.document_id = Some(event.document_id); + self.document_ids.insert(event.document_id); Some(Instant::now() + Duration::from_millis(120)) } fn finish_debounce(&mut self) { - let document_id = self.document_id; - job::dispatch_blocking(move |editor, _| { - let Some(document_id) = document_id else { - return; - }; - - let doc = editor.document(document_id); - let Some(doc) = doc else { - return; - }; - - let language_servers = - doc.language_servers_with_feature(LanguageServerFeature::PullDiagnostics); - - for language_server in language_servers { - pull_diagnostics_for_document(doc, language_server); - } - }) + for document_id in self.document_ids.clone() { + job::dispatch_blocking(move |editor, _| { + let doc = editor.document(document_id); + let Some(doc) = doc else { + return; + }; + + let language_servers = + doc.language_servers_with_feature(LanguageServerFeature::PullDiagnostics); + + for language_server in language_servers { + pull_diagnostics_for_document(doc, language_server); + } + }) + } } }