pub struct LspServiceBuilder<S> { /* private fields */ }
Expand description

A builder to customize the properties of an LspService.

To construct an LspServiceBuilder, refer to LspService::build.

Implementations§

Defines a custom JSON-RPC request or notification with the given method name and handler.

Handler varieties

Fundamentally, any inherent async fn(&self) method defined directly on the language server backend could be considered a valid method handler.

Handlers may optionally include a single params argument. This argument may be of any type that implements Serialize.

Handlers which return () are treated as notifications, while those which return jsonrpc::Result<T> are treated as requests.

Similar to the params argument, the T in the Result<T> return values may be of any type which implements DeserializeOwned. Additionally, this type must be convertible into a serde_json::Value using serde_json::to_value. If this latter constraint is not met, the client will receive a JSON-RPC error response with code -32603 (Internal Error) instead of the expected response.

Examples
use serde_json::{json, Value};
use tower_lsp::jsonrpc::Result;
use tower_lsp::lsp_types::*;
use tower_lsp::{LanguageServer, LspService};

struct Mock;

// Implementation of `LanguageServer` omitted...

impl Mock {
    async fn request(&self) -> Result<i32> {
        Ok(123)
    }

    async fn request_params(&self, params: Vec<String>) -> Result<Value> {
        Ok(json!({"num_elems":params.len()}))
    }

    async fn notification(&self) {
        // ...
    }

    async fn notification_params(&self, params: Value) {
        // ...
    }
}

let (service, socket) = LspService::build(|_| Mock)
    .custom_method("custom/request", Mock::request)
    .custom_method("custom/requestParams", Mock::request_params)
    .custom_method("custom/notification", Mock::notification)
    .custom_method("custom/notificationParams", Mock::notification_params)
    .finish();

Constructs the LspService and returns it, along with a channel for server-to-client communication.

Trait Implementations§

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

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

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more