Skip to content

Commit

Permalink
Implement missing 3.17.0 pull-based diagnostic methods
Browse files Browse the repository at this point in the history
This commit implements the following new requests:

* textDocument/diagnostic (client-to-server)
* workspace/diagnostic (client-to-server)
* workspace/diagnostic/refresh (server-to-client)
  • Loading branch information
ebkalderon committed Aug 11, 2023
1 parent 5a874b3 commit 75b304a
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 2 deletions.
62 changes: 61 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DocumentDiagnosticReportResult> {
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<WorkspaceDiagnosticReportResult> {
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.
Expand Down
23 changes: 22 additions & 1 deletion src/service/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,28 @@ impl Client {
self.send_request::<InlayHintRefreshRequest>(()).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::<WorkspaceDiagnosticRefresh>(()).await
}

/// Submits validation diagnostics for an open file with the given URI.
///
Expand Down

0 comments on commit 75b304a

Please sign in to comment.