Support workspace diagnostic refresh

This commit is contained in:
Sofus Addington 2024-08-20 21:00:33 +02:00
parent 760c5a8105
commit afabbc9844
5 changed files with 20 additions and 3 deletions

View file

@ -571,6 +571,9 @@ impl Client {
did_rename: Some(true),
..Default::default()
}),
diagnostic: Some(lsp::DiagnosticWorkspaceClientCapabilities {
refresh_support: Some(true),
}),
..Default::default()
}),
text_document: Some(lsp::TextDocumentClientCapabilities {

View file

@ -10,6 +10,7 @@ pub use client::Client;
pub use futures_executor::block_on;
pub use helix_lsp_types as lsp;
pub use jsonrpc::Call;
use lsp::request::Request;
pub use lsp::{Position, Url};
use futures_util::stream::select_all::SelectAll;
@ -569,7 +570,6 @@ pub enum MethodCall {
impl MethodCall {
pub fn parse(method: &str, params: jsonrpc::Params) -> Result<MethodCall> {
use lsp::request::Request;
let request = match method {
lsp::request::WorkDoneProgressCreate::METHOD => {
let params: lsp::WorkDoneProgressCreateParams = params.parse()?;
@ -614,6 +614,7 @@ pub enum Notification {
ShowMessage(lsp::ShowMessageParams),
LogMessage(lsp::LogMessageParams),
ProgressMessage(lsp::ProgressParams),
WorkspaceDiagnosticRefresh,
}
impl Notification {
@ -640,6 +641,7 @@ impl Notification {
let params: lsp::ProgressParams = params.parse()?;
Self::ProgressMessage(params)
}
lsp::request::WorkspaceDiagnosticRefresh::METHOD => Self::WorkspaceDiagnosticRefresh,
_ => {
return Err(Error::Unhandled);
}

View file

@ -703,6 +703,15 @@ impl Application {
};
match notification {
Notification::WorkspaceDiagnosticRefresh => {
for document in self.editor.documents() {
let langugage_server = language_server!();
handlers::diagnostics::pull_diagnostics_for_document(
document,
langugage_server,
);
}
}
Notification::Initialized => {
let language_server = language_server!();

View file

@ -16,7 +16,7 @@ pub use helix_view::handlers::Handlers;
mod auto_save;
pub mod completion;
mod diagnostics;
pub mod diagnostics;
mod signature_help;
pub fn setup(config: Arc<ArcSwap<Config>>) -> Handlers {

View file

@ -114,7 +114,10 @@ impl helix_event::AsyncHook for PullDiagnosticsHandler {
}
}
fn pull_diagnostics_for_document(doc: &helix_view::Document, language_server: &helix_lsp::Client) {
pub fn pull_diagnostics_for_document(
doc: &helix_view::Document,
language_server: &helix_lsp::Client,
) {
let Some(future) = language_server
.text_document_diagnostic(doc.identifier(), doc.previous_diagnostic_id.clone())
else {