Struct tower_lsp::Client

source ·
pub struct Client { /* private fields */ }
Expand description

Handle for communicating with the language client.

This type provides a very cheap implementation of Clone so API consumers can cheaply clone and pass it around as needed.

It also implements [tower::Service] in order to remain independent from the underlying transport and to facilitate further abstraction with middleware.

Implementations§

source§

impl Client

source

pub async fn register_capability( &self, registrations: Vec<Registration> ) -> Result<()>

Registers a new capability with the client.

This corresponds to the client/registerCapability request.

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).

source

pub async fn unregister_capability( &self, unregisterations: Vec<Unregistration> ) -> Result<()>

Unregisters a capability with the client.

This corresponds to the client/unregisterCapability request.

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).

source

pub async fn show_message<M: Display>(&self, typ: MessageType, message: M)

Notifies the client to display a particular message in the user interface.

This corresponds to the window/showMessage notification.

source

pub async fn show_message_request<M: Display>( &self, typ: MessageType, message: M, actions: Option<Vec<MessageActionItem>> ) -> Result<Option<MessageActionItem>>

Requests the client to display a particular message in the user interface.

Unlike the show_message notification, this request can also pass a list of actions and wait for an answer from the client.

This corresponds to the window/showMessageRequest request.

source

pub async fn log_message<M: Display>(&self, typ: MessageType, message: M)

Notifies the client to log a particular message.

This corresponds to the window/logMessage notification.

source

pub async fn show_document(&self, params: ShowDocumentParams) -> Result<bool>

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.

This corresponds to the window/showDocument request.

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).

Compatibility

This request was introduced in specification version 3.16.0.

source

pub async fn telemetry_event<S: Serialize>(&self, data: S)

Notifies the client to log a telemetry event.

This corresponds to the telemetry/event notification.

source

pub async fn code_lens_refresh(&self) -> Result<()>

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.

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).

Compatibility

This request was introduced in specification version 3.16.0.

source

pub async fn semantic_tokens_refresh(&self) -> Result<()>

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.

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/semanticTokens/refresh request.

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).

Compatibility

This request was introduced in specification version 3.16.0.

source

pub async fn inline_value_refresh(&self) -> Result<()>

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.

This corresponds to the workspace/inlineValue/refresh request.

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).

Compatibility

This request was introduced in specification version 3.17.0.

source

pub async fn inlay_hint_refresh(&self) -> Result<()>

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 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.

This corresponds to the workspace/inlayHint/refresh request.

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).

Compatibility

This request was introduced in specification version 3.17.0.

source

pub async fn workspace_diagnostic_refresh(&self) -> Result<()>

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.

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).

Compatibility

This request was introduced in specification version 3.17.0.

source

pub async fn publish_diagnostics( &self, uri: Url, diags: Vec<Diagnostic>, version: Option<i32> )

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

This corresponds to the textDocument/publishDiagnostics notification.

Initialization

This notification will only be sent if the server is initialized.

source

pub async fn configuration( &self, items: Vec<ConfigurationItem> ) -> Result<Vec<Value>>

Fetches configuration settings from the client.

The request can fetch several configuration settings in one roundtrip. The order of the returned configuration settings correspond to the order of the passed ConfigurationItems (e.g. the first item in the response is the result for the first configuration item in the params).

This corresponds to the workspace/configuration request.

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).

Compatibility

This request was introduced in specification version 3.6.0.

source

pub async fn workspace_folders(&self) -> Result<Option<Vec<WorkspaceFolder>>>

Fetches the current open list of workspace folders.

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/workspaceFolders request.

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).

Compatibility

This request was introduced in specification version 3.6.0.

source

pub async fn apply_edit( &self, edit: WorkspaceEdit ) -> Result<ApplyWorkspaceEditResponse>

Requests a workspace resource be edited on the client side and returns whether the edit was applied.

This corresponds to the workspace/applyEdit request.

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).

source

pub async fn send_notification<N>(&self, params: N::Params)where N: Notification,

Sends a custom notification to the client.

Initialization

This notification will only be sent if the server is initialized.

source

pub async fn send_request<R>(&self, params: R::Params) -> Result<R::Result>where R: Request,

Sends a custom request to the client.

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).

source§

impl Client

source

pub fn next_request_id(&self) -> Id

Increments the internal request ID counter and returns the previous value.

This method can be used to build custom Request objects with numeric IDs that are guaranteed to be unique every time.

Trait Implementations§

source§

impl Clone for Client

source§

fn clone(&self) -> Client

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Client

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Service<Request> for Client

§

type Response = Option<Response>

Responses given by the service.
§

type Error = ExitedError

Errors produced by the service.
§

type Future = Pin<Box<dyn Future<Output = Result<<Client as Service<Request>>::Response, <Client as Service<Request>>::Error>> + Send, Global>>

The future response value.
source§

fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>

Returns Poll::Ready(Ok(())) when the service is able to process requests. Read more
source§

fn call(&mut self, req: Request) -> Self::Future

Process the request and return the response asynchronously. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, Request> ServiceExt<Request> for Twhere T: Service<Request> + ?Sized,

source§

fn ready(&mut self) -> Ready<'_, Self, Request>where Self: Sized,

Yields a mutable reference to the service when it is ready to accept a request.
source§

fn ready_and(&mut self) -> Ready<'_, Self, Request>where Self: Sized,

👎Deprecated since 0.4.6: please use the ServiceExt::ready method instead
Yields a mutable reference to the service when it is ready to accept a request.
source§

fn ready_oneshot(self) -> ReadyOneshot<Self, Request>where Self: Sized,

Yields the service when it is ready to accept a request.
source§

fn oneshot(self, req: Request) -> Oneshot<Self, Request>where Self: Sized,

Consume this Service, calling with the providing request once it is ready.
source§

fn call_all<S>(self, reqs: S) -> CallAll<Self, S>where Self: Sized, Self::Error: Into<Box<dyn Error + Sync + Send, Global>>, S: Stream<Item = Request>,

Process all requests from the given Stream, and produce a Stream of their responses. Read more
source§

fn and_then<F>(self, f: F) -> AndThen<Self, F>where Self: Sized, F: Clone,

Executes a new future after this service’s future resolves. This does not alter the behaviour of the poll_ready method. Read more
source§

fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>where Self: Sized, F: FnOnce(Self::Response) -> Response + Clone,

Maps this service’s response value to a different value. This does not alter the behaviour of the poll_ready method. Read more
source§

fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>where Self: Sized, F: FnOnce(Self::Error) -> Error + Clone,

Maps this service’s error value to a different value. This does not alter the behaviour of the poll_ready method. Read more
source§

fn map_result<F, Response, Error>(self, f: F) -> MapResult<Self, F>where Self: Sized, Error: From<Self::Error>, F: FnOnce(Result<Self::Response, Self::Error>) -> Result<Response, Error> + Clone,

Maps this service’s result type (Result<Self::Response, Self::Error>) to a different value, regardless of whether the future succeeds or fails. Read more
source§

fn map_request<F, NewRequest>(self, f: F) -> MapRequest<Self, F>where Self: Sized, F: FnMut(NewRequest) -> Request,

Composes a function in front of the service. Read more
source§

fn then<F, Response, Error, Fut>(self, f: F) -> Then<Self, F>where Self: Sized, Error: From<Self::Error>, F: FnOnce(Result<Self::Response, Self::Error>) -> Fut + Clone, Fut: Future<Output = Result<Response, Error>>,

Composes an asynchronous function after this service. Read more
source§

fn map_future<F, Fut, Response, Error>(self, f: F) -> MapFuture<Self, F>where Self: Sized, F: FnMut(Self::Future) -> Fut, Error: From<Self::Error>, Fut: Future<Output = Result<Response, Error>>,

Composes a function that transforms futures produced by the service. Read more
source§

fn boxed(self) -> BoxService<Request, Self::Response, Self::Error>where Self: Sized + Send + 'static, Self::Future: Send + 'static,

Convert the service into a Service + Send trait object. Read more
source§

fn boxed_clone(self) -> BoxCloneService<Request, Self::Response, Self::Error>where Self: Clone + Sized + Send + 'static, Self::Future: Send + 'static,

Convert the service into a Service + Clone + Send trait object. Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more