From 75b304a6d6836b9c63876e73f27d0e3426a1db6b Mon Sep 17 00:00:00 2001 From: Eyal Kalderon Date: Thu, 10 Aug 2023 22:02:46 -0400 Subject: [PATCH] Implement missing 3.17.0 pull-based diagnostic methods This commit implements the following new requests: * textDocument/diagnostic (client-to-server) * workspace/diagnostic (client-to-server) * workspace/diagnostic/refresh (server-to-client) --- src/lib.rs | 62 ++++++++++++++++++++++++++++++++++++++++++- src/service/client.rs | 23 +++++++++++++++- 2 files changed, 83 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1f52858..5a0afba 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -841,7 +841,67 @@ pub trait LanguageServer: Send + Sync + 'static { Err(Error::method_not_found()) } - // TODO: Add `diagnostic()` and `workspace_diagnostic()` here when supported by `lsp-types`. + /// The [`textDocument/diagnostic`] request is sent from the client to the server to ask the + /// server to compute the diagnostics for a given document. + /// + /// As with other pull requests, the server is asked to compute the diagnostics for the + /// currently synced version of the document. + /// + /// The request doesn't define its own client and server capabilities. It is only issued if a + /// server registers for the [`textDocument/diagnostic`] request. + /// + /// [`textDocument/diagnostic`]: https://microsoft.github.io/language-server-protocol/specification#textDocument_diagnostic + /// + /// # Compatibility + /// + /// This request was introduced in specification version 3.17.0. + #[rpc(name = "textDocument/diagnostic")] + async fn diagnostic( + &self, + params: DocumentDiagnosticParams, + ) -> Result { + let _ = params; + error!("Got a textDocument/diagnostic request, but it is not implemented"); + Err(Error::method_not_found()) + } + + /// The [`workspace/diagnostic`] request is sent from the client to the server to ask the + /// server to compute workspace wide diagnostics which previously where pushed from the server + /// to the client. + /// + /// In contrast to the [`textDocument/diagnostic`] request, the workspace request can be + /// long-running and is not bound to a specific workspace or document state. If the client + /// supports streaming for the workspace diagnostic pull, it is legal to provide a + /// `textDocument/diagnostic` report multiple times for the same document URI. The last one + /// reported will win over previous reports. + /// + /// [`textDocument/diagnostic`]: https://microsoft.github.io/language-server-protocol/specification#textDocument_diagnostic + /// + /// If a client receives a diagnostic report for a document in a workspace diagnostic request + /// for which the client also issues individual document diagnostic pull requests, the client + /// needs to decide which diagnostics win and should be presented. In general: + /// + /// * Diagnostics for a higher document version should win over those from a lower document + /// version (e.g. note that document versions are steadily increasing). + /// * Diagnostics from a document pull should win over diagnostics from a workspace pull. + /// + /// The request doesn't define its own client and server capabilities. It is only issued if a + /// server registers for the [`workspace/diagnostic`] request. + /// + /// [`workspace/diagnostic`]: https://microsoft.github.io/language-server-protocol/specification#workspace_diagnostic + /// + /// # Compatibility + /// + /// This request was introduced in specification version 3.17.0. + #[rpc(name = "workspace/diagnostic")] + async fn workspace_diagnostic( + &self, + params: WorkspaceDiagnosticParams, + ) -> Result { + let _ = params; + error!("Got a workspace/diagnostic request, but it is not implemented"); + Err(Error::method_not_found()) + } /// The [`textDocument/signatureHelp`] request is sent from the client to the server to request /// signature information at a given cursor position. diff --git a/src/service/client.rs b/src/service/client.rs index da5d95c..f3ccdee 100644 --- a/src/service/client.rs +++ b/src/service/client.rs @@ -315,7 +315,28 @@ impl Client { self.send_request::(()).await } - // TODO: Add `workspace_diagnostic_refresh()` here when supported by `lsp-types`. + /// Asks the client to refresh all needed document and workspace diagnostics. + /// + /// This is useful if a server detects a project wide configuration change which requires a + /// re-calculation of all diagnostics. + /// + /// This corresponds to the [`workspace/diagnostic/refresh`] request. + /// + /// [`workspace/diagnostic/refresh`]: https://microsoft.github.io/language-server-protocol/specification#diagnostic_refresh + /// + /// # Initialization + /// + /// If the request is sent to the client before the server has been initialized, this will + /// immediately return `Err` with JSON-RPC error code `-32002` ([read more]). + /// + /// [read more]: https://microsoft.github.io/language-server-protocol/specification#initialize + /// + /// # Compatibility + /// + /// This request was introduced in specification version 3.17.0. + pub async fn workspace_diagnostic_refresh(&self) -> jsonrpc::Result<()> { + self.send_request::(()).await + } /// Submits validation diagnostics for an open file with the given URI. ///