Skip to content

Commit

Permalink
Reorder Client methods to better match 3.17.0 spec doc
Browse files Browse the repository at this point in the history
  • Loading branch information
ebkalderon committed Feb 28, 2023
1 parent 441ab9c commit 9af8a4d
Showing 1 changed file with 140 additions and 134 deletions.
274 changes: 140 additions & 134 deletions src/service/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,50 @@ impl Client {
}

impl Client {
/// Notifies the client to log a particular message.
// Lifecycle Messages

/// Registers a new capability with the client.
///
/// This corresponds to the [`window/logMessage`] notification.
/// This corresponds to the [`client/registerCapability`] request.
///
/// [`window/logMessage`]: https://microsoft.github.io/language-server-protocol/specification#window_logMessage
pub async fn log_message<M: Display>(&self, typ: MessageType, message: M) {
self.send_notification_unchecked::<LogMessage>(LogMessageParams {
typ,
message: message.to_string(),
})
.await;
/// [`client/registerCapability`]: https://microsoft.github.io/language-server-protocol/specification#client_registerCapability
///
/// # 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
pub async fn register_capability(
&self,
registrations: Vec<Registration>,
) -> jsonrpc::Result<()> {
self.send_request::<RegisterCapability>(RegistrationParams { registrations })
.await
}

/// Unregisters a capability with the client.
///
/// This corresponds to the [`client/unregisterCapability`] request.
///
/// [`client/unregisterCapability`]: https://microsoft.github.io/language-server-protocol/specification#client_unregisterCapability
///
/// # 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
pub async fn unregister_capability(
&self,
unregisterations: Vec<Unregistration>,
) -> jsonrpc::Result<()> {
self.send_request::<UnregisterCapability>(UnregistrationParams { unregisterations })
.await
}

// Window Features

/// Notifies the client to display a particular message in the user interface.
///
/// This corresponds to the [`window/showMessage`] notification.
Expand Down Expand Up @@ -124,6 +155,19 @@ impl Client {
.await
}

/// Notifies the client to log a particular message.
///
/// This corresponds to the [`window/logMessage`] notification.
///
/// [`window/logMessage`]: https://microsoft.github.io/language-server-protocol/specification#window_logMessage
pub async fn log_message<M: Display>(&self, typ: MessageType, message: M) {
self.send_notification_unchecked::<LogMessage>(LogMessageParams {
typ,
message: message.to_string(),
})
.await;
}

/// Asks the client to display a particular resource referenced by a URI in the user interface.
///
/// Returns `Ok(true)` if the document was successfully shown, or `Ok(false)` otherwise.
Expand All @@ -147,6 +191,9 @@ impl Client {
Ok(response.success)
}

// TODO: Add `work_done_progress_create()` here (since 3.15.0) when supported by `tower-lsp`.
// https://github.com/ebkalderon/tower-lsp/issues/176

/// Notifies the client to log a telemetry event.
///
/// This corresponds to the [`telemetry/event`] notification.
Expand All @@ -165,54 +212,44 @@ impl Client {
}
}

/// Registers a new capability with the client.
///
/// This corresponds to the [`client/registerCapability`] request.
///
/// [`client/registerCapability`]: https://microsoft.github.io/language-server-protocol/specification#client_registerCapability
///
/// # Initialization
/// Asks the client to refresh the code lenses currently shown in editors. As a result, the
/// client should ask the server to recompute the code lenses for these editors.
///
/// 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]).
/// This is useful if a server detects a configuration change which requires a re-calculation
/// of all code lenses.
///
/// [read more]: https://microsoft.github.io/language-server-protocol/specification#initialize
pub async fn register_capability(
&self,
registrations: Vec<Registration>,
) -> jsonrpc::Result<()> {
self.send_request::<RegisterCapability>(RegistrationParams { registrations })
.await
}

/// Unregisters a capability with the client.
/// Note that the client still has the freedom to delay the re-calculation of the code lenses
/// if for example an editor is currently not visible.
///
/// This corresponds to the [`client/unregisterCapability`] request.
/// This corresponds to the [`workspace/codeLens/refresh`] request.
///
/// [`client/unregisterCapability`]: https://microsoft.github.io/language-server-protocol/specification#client_unregisterCapability
/// [`workspace/codeLens/refresh`]: https://microsoft.github.io/language-server-protocol/specification#codeLens_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
pub async fn unregister_capability(
&self,
unregisterations: Vec<Unregistration>,
) -> jsonrpc::Result<()> {
self.send_request::<UnregisterCapability>(UnregistrationParams { unregisterations })
.await
///
/// # Compatibility
///
/// This request was introduced in specification version 3.16.0.
pub async fn code_lens_refresh(&self) -> jsonrpc::Result<()> {
self.send_request::<CodeLensRefresh>(()).await
}

/// Fetches the current open list of workspace folders.
/// Asks the client to refresh the editors for which this server provides semantic tokens. As a
/// result, the client should ask the server to recompute the semantic tokens for these
/// editors.
///
/// Returns `None` if only a single file is open in the tool. Returns an empty `Vec` if a
/// workspace is open but no folders are configured.
/// This is useful if a server detects a project-wide configuration change which requires a
/// re-calculation of all semantic tokens. Note that the client still has the freedom to delay
/// the re-calculation of the semantic tokens if for example an editor is currently not visible.
///
/// This corresponds to the [`workspace/workspaceFolders`] request.
/// This corresponds to the [`workspace/semanticTokens/refresh`] request.
///
/// [`workspace/workspaceFolders`]: https://microsoft.github.io/language-server-protocol/specification#workspace_workspaceFolders
/// [`workspace/semanticTokens/refresh`]: https://microsoft.github.io/language-server-protocol/specification#textDocument_semanticTokens
///
/// # Initialization
///
Expand All @@ -223,21 +260,21 @@ impl Client {
///
/// # Compatibility
///
/// This request was introduced in specification version 3.6.0.
pub async fn workspace_folders(&self) -> jsonrpc::Result<Option<Vec<WorkspaceFolder>>> {
self.send_request::<WorkspaceFoldersRequest>(()).await
/// This request was introduced in specification version 3.16.0.
pub async fn semantic_tokens_refresh(&self) -> jsonrpc::Result<()> {
self.send_request::<SemanticTokensRefresh>(()).await
}

/// Fetches configuration settings from the client.
/// Asks the client to refresh the inline values currently shown in editors. As a result, the
/// client should ask the server to recompute the inline values for these editors.
///
/// The request can fetch several configuration settings in one roundtrip. The order of the
/// returned configuration settings correspond to the order of the passed
/// [`ConfigurationItem`]s (e.g. the first item in the response is the result for the first
/// configuration item in the params).
/// This is useful if a server detects a configuration change which requires a re-calculation
/// of all inline values. Note that the client still has the freedom to delay the
/// re-calculation of the inline values if for example an editor is currently not visible.
///
/// This corresponds to the [`workspace/configuration`] request.
/// This corresponds to the [`workspace/inlineValue/refresh`] request.
///
/// [`workspace/configuration`]: https://microsoft.github.io/language-server-protocol/specification#workspace_configuration
/// [`workspace/inlineValue/refresh`]: https://microsoft.github.io/language-server-protocol/specification#workspace_inlineValue_refresh
///
/// # Initialization
///
Expand All @@ -248,36 +285,38 @@ impl Client {
///
/// # Compatibility
///
/// This request was introduced in specification version 3.6.0.
pub async fn configuration(
&self,
items: Vec<ConfigurationItem>,
) -> jsonrpc::Result<Vec<Value>> {
self.send_request::<WorkspaceConfiguration>(ConfigurationParams { items })
.await
/// This request was introduced in specification version 3.17.0.
pub async fn inline_value_refresh(&self) -> jsonrpc::Result<()> {
self.send_request::<InlineValueRefreshRequest>(()).await
}

/// Requests a workspace resource be edited on the client side and returns whether the edit was
/// applied.
/// Asks the client to refresh the inlay hints currently shown in editors. As a result, the
/// client should ask the server to recompute the inlay hints for these editors.
///
/// This corresponds to the [`workspace/applyEdit`] request.
/// This is useful if a server detects a configuration change which requires a re-calculation
/// of all inlay hints. Note that the client still has the freedom to delay the re-calculation
/// of the inlay hints if for example an editor is currently not visible.
///
/// [`workspace/applyEdit`]: https://microsoft.github.io/language-server-protocol/specification#workspace_applyEdit
/// This corresponds to the [`workspace/inlayHint/refresh`] request.
///
/// [`workspace/inlayHint/refresh`]: https://microsoft.github.io/language-server-protocol/specification#workspace_inlayHint_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
pub async fn apply_edit(
&self,
edit: WorkspaceEdit,
) -> jsonrpc::Result<ApplyWorkspaceEditResponse> {
self.send_request::<ApplyWorkspaceEdit>(ApplyWorkspaceEditParams { edit, label: None })
.await
///
/// # Compatibility
///
/// This request was introduced in specification version 3.17.0.
pub async fn inlay_hint_refresh(&self) -> jsonrpc::Result<()> {
self.send_request::<InlayHintRefreshRequest>(()).await
}

// TODO: Add `workspace_diagnostic_refresh()` here when supported by `lsp-types`.

/// Submits validation diagnostics for an open file with the given URI.
///
/// This corresponds to the [`textDocument/publishDiagnostics`] notification.
Expand All @@ -299,44 +338,18 @@ impl Client {
.await;
}

/// Asks the client to refresh the code lenses currently shown in editors. As a result, the
/// client should ask the server to recompute the code lenses for these editors.
///
/// This is useful if a server detects a configuration change which requires a re-calculation
/// of all code lenses.
///
/// Note that the client still has the freedom to delay the re-calculation of the code lenses
/// if for example an editor is currently not visible.
///
/// This corresponds to the [`workspace/codeLens/refresh`] request.
///
/// [`workspace/codeLens/refresh`]: https://microsoft.github.io/language-server-protocol/specification#codeLens_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.16.0.
pub async fn code_lens_refresh(&self) -> jsonrpc::Result<()> {
self.send_request::<CodeLensRefresh>(()).await
}
// Workspace Features

/// Asks the client to refresh the editors for which this server provides semantic tokens. As a
/// result, the client should ask the server to recompute the semantic tokens for these
/// editors.
/// Fetches configuration settings from the client.
///
/// This is useful if a server detects a project-wide configuration change which requires a
/// re-calculation of all semantic tokens. Note that the client still has the freedom to delay
/// the re-calculation of the semantic tokens if for example an editor is currently not visible.
/// The request can fetch several configuration settings in one roundtrip. The order of the
/// returned configuration settings correspond to the order of the passed
/// [`ConfigurationItem`]s (e.g. the first item in the response is the result for the first
/// configuration item in the params).
///
/// This corresponds to the [`workspace/semanticTokens/refresh`] request.
/// This corresponds to the [`workspace/configuration`] request.
///
/// [`workspace/semanticTokens/refresh`]: https://microsoft.github.io/language-server-protocol/specification#textDocument_semanticTokens
/// [`workspace/configuration`]: https://microsoft.github.io/language-server-protocol/specification#workspace_configuration
///
/// # Initialization
///
Expand All @@ -347,21 +360,23 @@ impl Client {
///
/// # Compatibility
///
/// This request was introduced in specification version 3.16.0.
pub async fn semantic_tokens_refresh(&self) -> jsonrpc::Result<()> {
self.send_request::<SemanticTokensRefresh>(()).await
/// This request was introduced in specification version 3.6.0.
pub async fn configuration(
&self,
items: Vec<ConfigurationItem>,
) -> jsonrpc::Result<Vec<Value>> {
self.send_request::<WorkspaceConfiguration>(ConfigurationParams { items })
.await
}

/// Asks the client to refresh the inlay hints currently shown in editors. As a result, the
/// client should ask the server to recompute the inlay hints for these editors.
/// Fetches the current open list of workspace folders.
///
/// This is useful if a server detects a configuration change which requires a re-calculation
/// of all inlay hints. Note that the client still has the freedom to delay the re-calculation
/// of the inlay hints if for example an editor is currently not visible.
/// Returns `None` if only a single file is open in the tool. Returns an empty `Vec` if a
/// workspace is open but no folders are configured.
///
/// This corresponds to the [`workspace/inlayHint/refresh`] request.
/// This corresponds to the [`workspace/workspaceFolders`] request.
///
/// [`workspace/inlayHint/refresh`]: https://microsoft.github.io/language-server-protocol/specification#workspace_inlayHint_refresh
/// [`workspace/workspaceFolders`]: https://microsoft.github.io/language-server-protocol/specification#workspace_workspaceFolders
///
/// # Initialization
///
Expand All @@ -372,41 +387,32 @@ impl Client {
///
/// # Compatibility
///
/// This request was introduced in specification version 3.17.0.
pub async fn inlay_hint_refresh(&self) -> jsonrpc::Result<()> {
self.send_request::<InlayHintRefreshRequest>(()).await
/// This request was introduced in specification version 3.6.0.
pub async fn workspace_folders(&self) -> jsonrpc::Result<Option<Vec<WorkspaceFolder>>> {
self.send_request::<WorkspaceFoldersRequest>(()).await
}

/// Asks the client to refresh the inline values currently shown in editors. As a result, the
/// client should ask the server to recompute the inline values for these editors.
///
/// This is useful if a server detects a configuration change which requires a re-calculation
/// of all inline values. Note that the client still has the freedom to delay the
/// re-calculation of the inline values if for example an editor is currently not visible.
/// Requests a workspace resource be edited on the client side and returns whether the edit was
/// applied.
///
/// This corresponds to the [`workspace/inlineValue/refresh`] request.
/// This corresponds to the [`workspace/applyEdit`] request.
///
/// [`workspace/inlineValue/refresh`]: https://microsoft.github.io/language-server-protocol/specification#workspace_inlineValue_refresh
/// [`workspace/applyEdit`]: https://microsoft.github.io/language-server-protocol/specification#workspace_applyEdit
///
/// # 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 inline_value_refresh(&self) -> jsonrpc::Result<()> {
self.send_request::<InlineValueRefreshRequest>(()).await
pub async fn apply_edit(
&self,
edit: WorkspaceEdit,
) -> jsonrpc::Result<ApplyWorkspaceEditResponse> {
self.send_request::<ApplyWorkspaceEdit>(ApplyWorkspaceEditParams { edit, label: None })
.await
}

// TODO: Add `workspace_diagnostic_refresh()` here when supported by `lsp-types`.

// TODO: Add `work_done_progress_create()` here (since 3.15.0) when supported by `tower-lsp`.
// https://github.com/ebkalderon/tower-lsp/issues/176

/// Sends a custom notification to the client.
///
/// # Initialization
Expand Down

0 comments on commit 9af8a4d

Please sign in to comment.