Skip to content

Commit feeae11

Browse files
committed
Pull diagnostics
1 parent 2bd7452 commit feeae11

File tree

9 files changed

+341
-3
lines changed

9 files changed

+341
-3
lines changed

helix-core/src/syntax/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ pub enum LanguageServerFeature {
265265
WorkspaceSymbols,
266266
// Symbols, use bitflags, see above?
267267
Diagnostics,
268+
PullDiagnostics,
268269
RenameSymbol,
269270
InlayHints,
270271
DocumentColors,
@@ -289,6 +290,7 @@ impl Display for LanguageServerFeature {
289290
DocumentSymbols => "document-symbols",
290291
WorkspaceSymbols => "workspace-symbols",
291292
Diagnostics => "diagnostics",
293+
PullDiagnostics => "pull-diagnostics",
292294
RenameSymbol => "rename-symbol",
293295
InlayHints => "inlay-hints",
294296
DocumentColors => "document-colors",

helix-lsp/src/client.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ impl Client {
348348
Some(OneOf::Left(true) | OneOf::Right(_))
349349
),
350350
LanguageServerFeature::Diagnostics => true, // there's no extra server capability
351+
LanguageServerFeature::PullDiagnostics => capabilities.diagnostic_provider.is_some(),
351352
LanguageServerFeature::RenameSymbol => matches!(
352353
capabilities.rename_provider,
353354
Some(OneOf::Left(true)) | Some(OneOf::Right(_))
@@ -578,6 +579,9 @@ impl Client {
578579
did_rename: Some(true),
579580
..Default::default()
580581
}),
582+
diagnostic: Some(lsp::DiagnosticWorkspaceClientCapabilities {
583+
refresh_support: Some(true),
584+
}),
581585
..Default::default()
582586
}),
583587
text_document: Some(lsp::TextDocumentClientCapabilities {
@@ -655,6 +659,10 @@ impl Client {
655659
}),
656660
..Default::default()
657661
}),
662+
diagnostic: Some(lsp::DiagnosticClientCapabilities {
663+
dynamic_registration: Some(false),
664+
related_document_support: Some(true),
665+
}),
658666
publish_diagnostics: Some(lsp::PublishDiagnosticsClientCapabilities {
659667
version_support: Some(true),
660668
tag_support: Some(lsp::TagSupport {
@@ -1219,6 +1227,32 @@ impl Client {
12191227
Some(self.call::<lsp::request::RangeFormatting>(params))
12201228
}
12211229

1230+
pub fn text_document_diagnostic(
1231+
&self,
1232+
text_document: lsp::TextDocumentIdentifier,
1233+
previous_result_id: Option<String>,
1234+
) -> Option<impl Future<Output = Result<lsp::DocumentDiagnosticReportResult>>> {
1235+
let capabilities = self.capabilities();
1236+
1237+
// Return early if the server does not support pull diagnostic.
1238+
let identifier = match capabilities.diagnostic_provider.as_ref()? {
1239+
lsp::DiagnosticServerCapabilities::Options(cap) => cap.identifier.clone(),
1240+
lsp::DiagnosticServerCapabilities::RegistrationOptions(cap) => {
1241+
cap.diagnostic_options.identifier.clone()
1242+
}
1243+
};
1244+
1245+
let params = lsp::DocumentDiagnosticParams {
1246+
text_document,
1247+
identifier,
1248+
previous_result_id,
1249+
work_done_progress_params: lsp::WorkDoneProgressParams::default(),
1250+
partial_result_params: lsp::PartialResultParams::default(),
1251+
};
1252+
1253+
Some(self.call::<lsp::request::DocumentDiagnosticRequest>(params))
1254+
}
1255+
12221256
pub fn text_document_document_highlight(
12231257
&self,
12241258
text_document: lsp::TextDocumentIdentifier,

helix-lsp/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ pub enum MethodCall {
463463
RegisterCapability(lsp::RegistrationParams),
464464
UnregisterCapability(lsp::UnregistrationParams),
465465
ShowDocument(lsp::ShowDocumentParams),
466+
WorkspaceDiagnosticRefresh,
466467
}
467468

468469
impl MethodCall {
@@ -494,6 +495,7 @@ impl MethodCall {
494495
let params: lsp::ShowDocumentParams = params.parse()?;
495496
Self::ShowDocument(params)
496497
}
498+
lsp::request::WorkspaceDiagnosticRefresh::METHOD => Self::WorkspaceDiagnosticRefresh,
497499
_ => {
498500
return Err(Error::Unhandled);
499501
}

helix-term/src/application.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,16 @@ impl Application {
10111011
let result = self.handle_show_document(params, offset_encoding);
10121012
Ok(json!(result))
10131013
}
1014+
Ok(MethodCall::WorkspaceDiagnosticRefresh) => {
1015+
for document in self.editor.documents() {
1016+
let language_server = language_server!();
1017+
handlers::diagnostics::pull_diagnostics_for_document(
1018+
document,
1019+
language_server,
1020+
);
1021+
}
1022+
Ok(serde_json::Value::Null)
1023+
}
10141024
};
10151025

10161026
let language_server = language_server!();

helix-term/src/handlers.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use helix_event::AsyncHook;
66
use crate::config::Config;
77
use crate::events;
88
use crate::handlers::auto_save::AutoSaveHandler;
9+
use crate::handlers::diagnostics::PullDiagnosticsHandler;
910
use crate::handlers::signature_help::SignatureHelpHandler;
1011

1112
pub use helix_view::handlers::Handlers;
@@ -14,7 +15,7 @@ use self::document_colors::DocumentColorsHandler;
1415

1516
mod auto_save;
1617
pub mod completion;
17-
mod diagnostics;
18+
pub mod diagnostics;
1819
mod document_colors;
1920
mod signature_help;
2021
mod snippet;
@@ -26,12 +27,14 @@ pub fn setup(config: Arc<ArcSwap<Config>>) -> Handlers {
2627
let signature_hints = SignatureHelpHandler::new().spawn();
2728
let auto_save = AutoSaveHandler::new().spawn();
2829
let document_colors = DocumentColorsHandler::default().spawn();
30+
let pull_diagnostics = PullDiagnosticsHandler::new().spawn();
2931

3032
let handlers = Handlers {
3133
completions: helix_view::handlers::completion::CompletionHandler::new(event_tx),
3234
signature_hints,
3335
auto_save,
3436
document_colors,
37+
pull_diagnostics,
3538
};
3639

3740
helix_view::handlers::register_hooks(&handlers);

0 commit comments

Comments
 (0)