Pull diagnostics on go to buffer instead

pull/11315/head
Sofus Addington 3 months ago
parent dcfceb5059
commit 760c5a8105

@ -885,6 +885,10 @@ fn goto_buffer(editor: &mut Editor, direction: Direction, count: usize) {
let id = *id; let id = *id;
if let Some(doc) = editor.document(id) {
helix_event::dispatch(helix_view::events::DocumentDidOpen { doc });
};
editor.switch(id, Action::Replace); editor.switch(id, Action::Replace);
} }

@ -8,7 +8,7 @@ use crate::config::Config;
use crate::events; use crate::events;
use crate::handlers::auto_save::AutoSaveHandler; use crate::handlers::auto_save::AutoSaveHandler;
use crate::handlers::completion::CompletionHandler; use crate::handlers::completion::CompletionHandler;
use crate::handlers::diagnostics::PullDiagnosticsForLanguageServersHandler; use crate::handlers::diagnostics::PullDiagnosticsHandler;
use crate::handlers::signature_help::SignatureHelpHandler; use crate::handlers::signature_help::SignatureHelpHandler;
pub use completion::trigger_auto_completion; pub use completion::trigger_auto_completion;
@ -25,14 +25,13 @@ pub fn setup(config: Arc<ArcSwap<Config>>) -> Handlers {
let completions = CompletionHandler::new(config).spawn(); let completions = CompletionHandler::new(config).spawn();
let signature_hints = SignatureHelpHandler::new().spawn(); let signature_hints = SignatureHelpHandler::new().spawn();
let auto_save = AutoSaveHandler::new().spawn(); let auto_save = AutoSaveHandler::new().spawn();
let pull_diagnostics_for_language_servers = let pull_diagnostics = PullDiagnosticsHandler::new().spawn();
PullDiagnosticsForLanguageServersHandler::new().spawn();
let handlers = Handlers { let handlers = Handlers {
completions, completions,
signature_hints, signature_hints,
auto_save, auto_save,
pull_diagnostics_for_language_servers, pull_diagnostics,
}; };
completion::register_hooks(&handlers); completion::register_hooks(&handlers);

@ -1,4 +1,4 @@
use std::collections::{HashMap, HashSet}; use std::collections::HashMap;
use std::time::Duration; use std::time::Duration;
use helix_core::syntax::LanguageServerFeature; use helix_core::syntax::LanguageServerFeature;
@ -9,7 +9,7 @@ use helix_lsp::LanguageServerId;
use helix_view::document::Mode; use helix_view::document::Mode;
use helix_view::events::{DiagnosticsDidChange, DocumentDidChange, DocumentDidOpen}; use helix_view::events::{DiagnosticsDidChange, DocumentDidChange, DocumentDidOpen};
use helix_view::handlers::diagnostics::DiagnosticEvent; use helix_view::handlers::diagnostics::DiagnosticEvent;
use helix_view::handlers::lsp::PullDiagnosticsForLanguageServersEvent; use helix_view::handlers::lsp::PullDiagnosticsEvent;
use helix_view::handlers::Handlers; use helix_view::handlers::Handlers;
use helix_view::{DocumentId, Editor}; use helix_view::{DocumentId, Editor};
use tokio::time::Instant; use tokio::time::Instant;
@ -33,21 +33,14 @@ pub(super) fn register_hooks(handlers: &Handlers) {
Ok(()) Ok(())
}); });
let tx = handlers.pull_diagnostics_for_language_servers.clone(); let tx = handlers.pull_diagnostics.clone();
register_hook!(move |event: &mut DocumentDidChange<'_>| { register_hook!(move |event: &mut DocumentDidChange<'_>| {
let language_server_ids: HashSet<_> = event if event
.doc .doc
.language_servers_with_feature(LanguageServerFeature::PullDiagnostics) .has_language_server_with_feature(LanguageServerFeature::PullDiagnostics)
.map(|x| x.id()) {
.collect(); let document_id = event.doc.id();
send_blocking(&tx, PullDiagnosticsEvent { document_id });
if !language_server_ids.is_empty() {
send_blocking(
&tx,
PullDiagnosticsForLanguageServersEvent {
language_server_ids,
},
);
} }
Ok(()) Ok(())
}); });
@ -59,7 +52,7 @@ pub(super) fn register_hooks(handlers: &Handlers) {
{ {
let document_id = event.doc.id(); let document_id = event.doc.id();
job::dispatch_blocking(move |editor, _| { job::dispatch_blocking(move |editor, _| {
let Some(doc) = editor.document_mut(document_id) else { let Some(doc) = editor.document(document_id) else {
return; return;
}; };
@ -77,56 +70,47 @@ pub(super) fn register_hooks(handlers: &Handlers) {
} }
#[derive(Debug)] #[derive(Debug)]
pub(super) struct PullDiagnosticsForLanguageServersHandler { pub(super) struct PullDiagnosticsHandler {
language_server_ids: HashSet<LanguageServerId>, document_id: Option<DocumentId>,
} }
impl PullDiagnosticsForLanguageServersHandler { impl PullDiagnosticsHandler {
pub fn new() -> PullDiagnosticsForLanguageServersHandler { pub fn new() -> PullDiagnosticsHandler {
PullDiagnosticsForLanguageServersHandler { PullDiagnosticsHandler { document_id: None }
language_server_ids: [].into(),
}
} }
} }
impl helix_event::AsyncHook for PullDiagnosticsForLanguageServersHandler { impl helix_event::AsyncHook for PullDiagnosticsHandler {
type Event = PullDiagnosticsForLanguageServersEvent; type Event = PullDiagnosticsEvent;
fn handle_event( fn handle_event(
&mut self, &mut self,
event: Self::Event, event: Self::Event,
_: Option<tokio::time::Instant>, _: Option<tokio::time::Instant>,
) -> Option<tokio::time::Instant> { ) -> Option<tokio::time::Instant> {
self.language_server_ids = event.language_server_ids; self.document_id = Some(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 language_servers = self.language_server_ids.clone(); let document_id = self.document_id;
job::dispatch_blocking(move |editor, _| { job::dispatch_blocking(move |editor, _| {
pull_diagnostic_for_language_servers(editor, language_servers) let Some(document_id) = document_id else {
}) return;
} };
}
fn pull_diagnostic_for_language_servers(
editor: &mut Editor,
language_server_ids: HashSet<LanguageServerId>,
) {
let document_ids: Vec<_> = editor.documents().map(|x| x.id()).collect();
for document_id in document_ids { let doc = editor.document(document_id);
let Some(doc) = editor.document_mut(document_id) else { let Some(doc) = doc else {
return; return;
}; };
let language_servers = doc let language_servers =
.language_servers() doc.language_servers_with_feature(LanguageServerFeature::PullDiagnostics);
.filter(|x| language_server_ids.contains(&x.id()));
for language_server in language_servers { for language_server in language_servers {
pull_diagnostics_for_document(doc, language_server); pull_diagnostics_for_document(doc, language_server);
} }
})
} }
} }

@ -19,7 +19,7 @@ pub struct Handlers {
pub completions: Sender<lsp::CompletionEvent>, pub completions: Sender<lsp::CompletionEvent>,
pub signature_hints: Sender<lsp::SignatureHelpEvent>, pub signature_hints: Sender<lsp::SignatureHelpEvent>,
pub auto_save: Sender<AutoSaveEvent>, pub auto_save: Sender<AutoSaveEvent>,
pub pull_diagnostics_for_language_servers: Sender<lsp::PullDiagnosticsForLanguageServersEvent>, pub pull_diagnostics: Sender<lsp::PullDiagnosticsEvent>,
} }
impl Handlers { impl Handlers {

@ -1,4 +1,3 @@
use std::collections::HashSet;
use std::fmt::Display; use std::fmt::Display;
use crate::editor::Action; use crate::editor::Action;
@ -48,8 +47,8 @@ pub enum SignatureHelpEvent {
RequestComplete { open: bool }, RequestComplete { open: bool },
} }
pub struct PullDiagnosticsForLanguageServersEvent { pub struct PullDiagnosticsEvent {
pub language_server_ids: HashSet<helix_lsp::LanguageServerId>, pub document_id: DocumentId,
} }
#[derive(Debug)] #[derive(Debug)]

Loading…
Cancel
Save