Handle multiple documents in pull diagnostics event

pull/11315/head
Sofus Addington 3 months ago
parent 131574983a
commit 131f0b366d

@ -1036,7 +1036,6 @@ impl Application {
} }
Ok(MethodCall::WorkspaceDiagnosticRefresh) => { Ok(MethodCall::WorkspaceDiagnosticRefresh) => {
log::warn!("Sofus refresh");
for document in self.editor.documents() { for document in self.editor.documents() {
let language_server = language_server!(); let language_server = language_server!();
handlers::diagnostics::pull_diagnostics_for_document( handlers::diagnostics::pull_diagnostics_for_document(

@ -1,4 +1,4 @@
use std::collections::HashMap; use std::collections::{HashMap, HashSet};
use std::time::Duration; use std::time::Duration;
use helix_core::syntax::LanguageServerFeature; use helix_core::syntax::LanguageServerFeature;
@ -71,12 +71,14 @@ pub(super) fn register_hooks(handlers: &Handlers) {
#[derive(Debug)] #[derive(Debug)]
pub(super) struct PullDiagnosticsHandler { pub(super) struct PullDiagnosticsHandler {
document_id: Option<DocumentId>, document_ids: HashSet<DocumentId>,
} }
impl PullDiagnosticsHandler { impl PullDiagnosticsHandler {
pub fn new() -> PullDiagnosticsHandler { pub fn new() -> PullDiagnosticsHandler {
PullDiagnosticsHandler { document_id: None } PullDiagnosticsHandler {
document_ids: [].into(),
}
} }
} }
@ -88,17 +90,13 @@ impl helix_event::AsyncHook for PullDiagnosticsHandler {
event: Self::Event, event: Self::Event,
_: Option<tokio::time::Instant>, _: Option<tokio::time::Instant>,
) -> Option<tokio::time::Instant> { ) -> Option<tokio::time::Instant> {
self.document_id = Some(event.document_id); self.document_ids.insert(event.document_id);
Some(Instant::now() + Duration::from_millis(120)) Some(Instant::now() + Duration::from_millis(120))
} }
fn finish_debounce(&mut self) { fn finish_debounce(&mut self) {
let document_id = self.document_id; for document_id in self.document_ids.clone() {
job::dispatch_blocking(move |editor, _| { job::dispatch_blocking(move |editor, _| {
let Some(document_id) = document_id else {
return;
};
let doc = editor.document(document_id); let doc = editor.document(document_id);
let Some(doc) = doc else { let Some(doc) = doc else {
return; return;
@ -113,6 +111,7 @@ impl helix_event::AsyncHook for PullDiagnosticsHandler {
}) })
} }
} }
}
pub fn pull_diagnostics_for_document( pub fn pull_diagnostics_for_document(
doc: &helix_view::Document, doc: &helix_view::Document,

Loading…
Cancel
Save