diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 9ccd8ea10..c3d7b8459 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -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); } diff --git a/helix-term/src/handlers.rs b/helix-term/src/handlers.rs index e77f8ea35..b32b9e2ff 100644 --- a/helix-term/src/handlers.rs +++ b/helix-term/src/handlers.rs @@ -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>) -> 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); diff --git a/helix-term/src/handlers/diagnostics.rs b/helix-term/src/handlers/diagnostics.rs index 211dc119f..d51385e82 100644 --- a/helix-term/src/handlers/diagnostics.rs +++ b/helix-term/src/handlers/diagnostics.rs @@ -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, +pub(super) struct PullDiagnosticsHandler { + document_id: Option, } -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, ) -> Option { - 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, -) { - 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 { - return; - }; + 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); - } + for language_server in language_servers { + pull_diagnostics_for_document(doc, language_server); + } + }) } } diff --git a/helix-view/src/handlers.rs b/helix-view/src/handlers.rs index 9ce6abb50..519ccca8a 100644 --- a/helix-view/src/handlers.rs +++ b/helix-view/src/handlers.rs @@ -19,7 +19,7 @@ pub struct Handlers { pub completions: Sender, pub signature_hints: Sender, pub auto_save: Sender, - pub pull_diagnostics_for_language_servers: Sender, + pub pull_diagnostics: Sender, } impl Handlers { diff --git a/helix-view/src/handlers/lsp.rs b/helix-view/src/handlers/lsp.rs index 82ccd0238..a1cfa7ece 100644 --- a/helix-view/src/handlers/lsp.rs +++ b/helix-view/src/handlers/lsp.rs @@ -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, +pub struct PullDiagnosticsEvent { + pub document_id: DocumentId, } #[derive(Debug)]