Struct Router

Source
pub struct Router<St, Error = ResponseError> { /* private fields */ }
Expand description

A router dispatching requests and notifications to individual handlers.

Implementations§

Source§

impl<St, Error> Router<St, Error>
where Error: From<ResponseError> + Send + 'static,

Source

pub fn new(state: St) -> Self

Create a empty Router.

Source

pub fn request<R: Request, Fut>( &mut self, handler: impl Fn(&mut St, R::Params) -> Fut + Send + 'static, ) -> &mut Self
where Fut: Future<Output = Result<R::Result, Error>> + Send + 'static,

Add an asynchronous request handler for a specific LSP request R.

If handler for the method already exists, it replaces the old one.

Source

pub fn notification<N: Notification>( &mut self, handler: impl Fn(&mut St, N::Params) -> ControlFlow<Result<()>> + Send + 'static, ) -> &mut Self

Add a synchronous request handler for a specific LSP notification N.

If handler for the method already exists, it replaces the old one.

Source

pub fn event<E: Send + 'static>( &mut self, handler: impl Fn(&mut St, E) -> ControlFlow<Result<()>> + Send + 'static, ) -> &mut Self

Add a synchronous event handler for event type E.

If handler for the method already exists, it replaces the old one.

Source

pub fn unhandled_request<Fut>( &mut self, handler: impl Fn(&mut St, AnyRequest) -> Fut + Send + 'static, ) -> &mut Self
where Fut: Future<Output = Result<JsonValue, Error>> + Send + 'static,

Set an asynchronous catch-all request handler for any requests with no corresponding handler for its method.

There can only be a single catch-all request handler. New ones replace old ones.

The default handler is to respond a error response with code ErrorCode::METHOD_NOT_FOUND.

Source

pub fn unhandled_notification( &mut self, handler: impl Fn(&mut St, AnyNotification) -> ControlFlow<Result<()>> + Send + 'static, ) -> &mut Self

Set a synchronous catch-all notification handler for any notifications with no corresponding handler for its method.

There can only be a single catch-all notification handler. New ones replace old ones.

The default handler is to do nothing for methods starting with $/, and break the main loop with Error::Routing for other methods. Typically notifications are critical and losing them can break state synchronization, easily leading to catastrophic failures after incorrect incremental changes.

Source

pub fn unhandled_event( &mut self, handler: impl Fn(&mut St, AnyEvent) -> ControlFlow<Result<()>> + Send + 'static, ) -> &mut Self

Set a synchronous catch-all event handler for any notifications with no corresponding handler for its type.

There can only be a single catch-all event handler. New ones replace old ones.

The default handler is to break the main loop with Error::Routing. Since events are emitted internally, mishandling are typically logic errors.

Source§

impl<S> Router<S>
where S: LanguageServer<NotifyResult = ControlFlow<Result<()>>>, ResponseError: From<S::Error>,

Source

pub fn from_language_server(state: S) -> Self

Create a Router using its implementation of LanguageServer as handlers.

Source§

impl<S> Router<S>
where S: LanguageClient<NotifyResult = ControlFlow<Result<()>>>, ResponseError: From<S::Error>,

Source

pub fn from_language_client(state: S) -> Self

Create a Router using its implementation of LanguageClient as handlers.

Trait Implementations§

Source§

impl<St, Error> Default for Router<St, Error>
where St: Default, Error: From<ResponseError> + Send + 'static,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<St> LspService for Router<St>

Source§

fn notify(&mut self, notif: AnyNotification) -> ControlFlow<Result<()>>

Source§

fn emit(&mut self, event: AnyEvent) -> ControlFlow<Result<()>>

The handler of an arbitrary AnyEvent. Read more
Source§

impl<St, Error> Service<AnyRequest> for Router<St, Error>

Source§

type Response = Value

Responses given by the service.
Source§

type Error = Error

Errors produced by the service.
Source§

type Future = Pin<Box<dyn Future<Output = Result<Value, Error>> + Send>>

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: AnyRequest) -> Self::Future

Process the request and return the response asynchronously. Read more

Auto Trait Implementations§

§

impl<St, Error> Freeze for Router<St, Error>
where St: Freeze,

§

impl<St, Error = ResponseError> !RefUnwindSafe for Router<St, Error>

§

impl<St, Error> Send for Router<St, Error>
where St: Send,

§

impl<St, Error = ResponseError> !Sync for Router<St, Error>

§

impl<St, Error> Unpin for Router<St, Error>
where St: Unpin,

§

impl<St, Error = ResponseError> !UnwindSafe for Router<St, Error>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T