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§

source§

impl<S: LanguageServer> LspServiceBuilder<S>

source

pub fn custom_method<P, R, F>(self, name: &'static str, callback: F) -> Selfwhere P: FromParams, R: IntoResponse, F: for<'a> Method<&'a S, P, R> + Clone + Send + Sync + 'static,

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();
source

pub fn finish(self) -> (LspService<S>, ClientSocket)

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

Trait Implementations§

source§

impl<S: Debug> Debug for LspServiceBuilder<S>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S> !RefUnwindSafe for LspServiceBuilder<S>

§

impl<S> Send for LspServiceBuilder<S>where S: Send + Sync,

§

impl<S> !Sync for LspServiceBuilder<S>

§

impl<S> Unpin for LspServiceBuilder<S>

§

impl<S> !UnwindSafe for LspServiceBuilder<S>

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,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · 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>,

const: unstable · 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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · 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.
const: unstable · 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