|
|
@ -39,10 +39,16 @@ pub(super) fn register_hooks(handlers: &Handlers) {
|
|
|
|
.doc
|
|
|
|
.doc
|
|
|
|
.has_language_server_with_feature(LanguageServerFeature::PullDiagnostics)
|
|
|
|
.has_language_server_with_feature(LanguageServerFeature::PullDiagnostics)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
let language_server_ids = event
|
|
|
|
|
|
|
|
.doc
|
|
|
|
|
|
|
|
.language_servers_with_feature(LanguageServerFeature::PullDiagnostics)
|
|
|
|
|
|
|
|
.map(|x| x.id())
|
|
|
|
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
|
|
|
|
send_blocking(
|
|
|
|
send_blocking(
|
|
|
|
&tx,
|
|
|
|
&tx,
|
|
|
|
PullDiagnosticsEvent {
|
|
|
|
PullDiagnosticsEvent {
|
|
|
|
document_id: event.doc.id(),
|
|
|
|
language_server_ids,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -54,12 +60,14 @@ const TIMEOUT: u64 = 120;
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub(super) struct PullDiagnosticsHandler {
|
|
|
|
pub(super) struct PullDiagnosticsHandler {
|
|
|
|
document_id: Option<helix_view::DocumentId>,
|
|
|
|
language_server_ids: Vec<LanguageServerId>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl PullDiagnosticsHandler {
|
|
|
|
impl PullDiagnosticsHandler {
|
|
|
|
pub fn new() -> PullDiagnosticsHandler {
|
|
|
|
pub fn new() -> PullDiagnosticsHandler {
|
|
|
|
PullDiagnosticsHandler { document_id: None }
|
|
|
|
PullDiagnosticsHandler {
|
|
|
|
|
|
|
|
language_server_ids: vec![],
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -71,60 +79,70 @@ 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.language_server_ids = event.language_server_ids;
|
|
|
|
Some(Instant::now() + Duration::from_millis(TIMEOUT))
|
|
|
|
Some(Instant::now() + Duration::from_millis(TIMEOUT))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn finish_debounce(&mut self) {
|
|
|
|
fn finish_debounce(&mut self) {
|
|
|
|
let document_id = self.document_id;
|
|
|
|
let language_servers = self.language_server_ids.clone();
|
|
|
|
|
|
|
|
|
|
|
|
job::dispatch_blocking(move |editor, _| {
|
|
|
|
job::dispatch_blocking(move |editor, _| {
|
|
|
|
let Some(document_id) = document_id else {
|
|
|
|
pull_diagnostic_for_document(
|
|
|
|
return;
|
|
|
|
editor,
|
|
|
|
};
|
|
|
|
language_servers,
|
|
|
|
pull_diagnostic_for_document(editor, document_id)
|
|
|
|
editor.documents().map(|x| x.id()).collect(),
|
|
|
|
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn pull_diagnostic_for_document(editor: &mut Editor, document_id: helix_view::DocumentId) {
|
|
|
|
fn pull_diagnostic_for_document(
|
|
|
|
let doc = doc_mut!(editor, &document_id);
|
|
|
|
editor: &mut Editor,
|
|
|
|
|
|
|
|
language_server_ids: Vec<LanguageServerId>,
|
|
|
|
for language_server in doc.language_servers_with_feature(LanguageServerFeature::PullDiagnostics)
|
|
|
|
document_ids: Vec<helix_view::DocumentId>,
|
|
|
|
{
|
|
|
|
) {
|
|
|
|
let Some(future) = language_server
|
|
|
|
for document_id in document_ids.clone() {
|
|
|
|
.text_document_diagnostic(doc.identifier(), doc.previous_diagnostic_id.clone())
|
|
|
|
let doc = doc_mut!(editor, &document_id);
|
|
|
|
else {
|
|
|
|
let language_servers = doc
|
|
|
|
return;
|
|
|
|
.language_servers()
|
|
|
|
};
|
|
|
|
.filter(|x| language_server_ids.contains(&x.id()));
|
|
|
|
|
|
|
|
|
|
|
|
let Some(uri) = doc.uri() else {
|
|
|
|
for language_server in language_servers {
|
|
|
|
return;
|
|
|
|
let Some(future) = language_server
|
|
|
|
};
|
|
|
|
.text_document_diagnostic(doc.identifier(), doc.previous_diagnostic_id.clone())
|
|
|
|
|
|
|
|
else {
|
|
|
|
let server_id = language_server.id();
|
|
|
|
return;
|
|
|
|
|
|
|
|
};
|
|
|
|
tokio::spawn(async move {
|
|
|
|
|
|
|
|
match future.await {
|
|
|
|
let Some(uri) = doc.uri() else {
|
|
|
|
Ok(res) => {
|
|
|
|
return;
|
|
|
|
job::dispatch(move |editor, _| {
|
|
|
|
};
|
|
|
|
let parsed_response: Option<lsp::DocumentDiagnosticReport> =
|
|
|
|
|
|
|
|
match serde_json::from_value(res) {
|
|
|
|
let server_id = language_server.id();
|
|
|
|
Ok(result) => Some(result),
|
|
|
|
|
|
|
|
Err(_) => None,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let Some(response) = parsed_response else {
|
|
|
|
tokio::spawn(async move {
|
|
|
|
return;
|
|
|
|
match future.await {
|
|
|
|
};
|
|
|
|
Ok(res) => {
|
|
|
|
|
|
|
|
job::dispatch(move |editor, _| {
|
|
|
|
|
|
|
|
log::error!("{}", res);
|
|
|
|
|
|
|
|
|
|
|
|
show_pull_diagnostics(editor, response, server_id, uri, document_id)
|
|
|
|
let parsed_response: Option<lsp::DocumentDiagnosticReport> =
|
|
|
|
})
|
|
|
|
match serde_json::from_value(res) {
|
|
|
|
.await
|
|
|
|
Ok(result) => Some(result),
|
|
|
|
|
|
|
|
Err(_) => None,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let Some(response) = parsed_response else {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
show_pull_diagnostics(editor, response, server_id, uri, &document_id)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.await
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Err(err) => log::error!("signature help request failed: {err}"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(err) => log::error!("signature help request failed: {err}"),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -133,9 +151,9 @@ fn show_pull_diagnostics(
|
|
|
|
response: lsp::DocumentDiagnosticReport,
|
|
|
|
response: lsp::DocumentDiagnosticReport,
|
|
|
|
server_id: LanguageServerId,
|
|
|
|
server_id: LanguageServerId,
|
|
|
|
uri: Uri,
|
|
|
|
uri: Uri,
|
|
|
|
document_id: helix_view::DocumentId,
|
|
|
|
document_id: &helix_view::DocumentId,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
let doc = doc_mut!(editor, &document_id);
|
|
|
|
let doc = doc_mut!(editor, document_id);
|
|
|
|
match response {
|
|
|
|
match response {
|
|
|
|
lsp::DocumentDiagnosticReport::Full(report) => {
|
|
|
|
lsp::DocumentDiagnosticReport::Full(report) => {
|
|
|
|
// Original file diagnostic
|
|
|
|
// Original file diagnostic
|
|
|
@ -184,7 +202,7 @@ fn parse_diagnostic(
|
|
|
|
|
|
|
|
|
|
|
|
fn handle_document_diagnostic_report_kind(
|
|
|
|
fn handle_document_diagnostic_report_kind(
|
|
|
|
editor: &mut Editor,
|
|
|
|
editor: &mut Editor,
|
|
|
|
document_id: helix_view::DocumentId,
|
|
|
|
document_id: &helix_view::DocumentId,
|
|
|
|
report: Option<HashMap<lsp::Url, lsp::DocumentDiagnosticReportKind>>,
|
|
|
|
report: Option<HashMap<lsp::Url, lsp::DocumentDiagnosticReportKind>>,
|
|
|
|
server_id: LanguageServerId,
|
|
|
|
server_id: LanguageServerId,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|