|
|
@ -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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|