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;
if let Some(doc) = editor.document(id) {
helix_event::dispatch(helix_view::events::DocumentDidOpen { doc });
};
editor.switch(id, Action::Replace);
}

@ -8,7 +8,7 @@ use crate::config::Config;
use crate::events;
use crate::handlers::auto_save::AutoSaveHandler;
use crate::handlers::completion::CompletionHandler;
use crate::handlers::diagnostics::PullDiagnosticsForLanguageServersHandler;
use crate::handlers::diagnostics::PullDiagnosticsHandler;
use crate::handlers::signature_help::SignatureHelpHandler;
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 signature_hints = SignatureHelpHandler::new().spawn();
let auto_save = AutoSaveHandler::new().spawn();
let pull_diagnostics_for_language_servers =
PullDiagnosticsForLanguageServersHandler::new().spawn();
let pull_diagnostics = PullDiagnosticsHandler::new().spawn();
let handlers = Handlers {
completions,
signature_hints,
auto_save,
pull_diagnostics_for_language_servers,
pull_diagnostics,
};
completion::register_hooks(&handlers);

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

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

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

Loading…
Cancel
Save