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>
impl<St, Error> Router<St, Error>
Sourcepub fn request<R: Request, Fut>(
&mut self,
handler: impl Fn(&mut St, R::Params) -> Fut + Send + 'static,
) -> &mut Self
pub fn request<R: Request, Fut>( &mut self, handler: impl Fn(&mut St, R::Params) -> Fut + Send + 'static, ) -> &mut Self
Add an asynchronous request handler for a specific LSP request R
.
If handler for the method already exists, it replaces the old one.
Sourcepub fn notification<N: Notification>(
&mut self,
handler: impl Fn(&mut St, N::Params) -> ControlFlow<Result<()>> + Send + 'static,
) -> &mut Self
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.
Sourcepub fn event<E: Send + 'static>(
&mut self,
handler: impl Fn(&mut St, E) -> ControlFlow<Result<()>> + Send + 'static,
) -> &mut Self
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.
Sourcepub fn unhandled_request<Fut>(
&mut self,
handler: impl Fn(&mut St, AnyRequest) -> Fut + Send + 'static,
) -> &mut Self
pub fn unhandled_request<Fut>( &mut self, handler: impl Fn(&mut St, AnyRequest) -> Fut + Send + 'static, ) -> &mut Self
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
.
Sourcepub fn unhandled_notification(
&mut self,
handler: impl Fn(&mut St, AnyNotification) -> ControlFlow<Result<()>> + Send + 'static,
) -> &mut Self
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.
Sourcepub fn unhandled_event(
&mut self,
handler: impl Fn(&mut St, AnyEvent) -> ControlFlow<Result<()>> + Send + 'static,
) -> &mut Self
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>
impl<S> Router<S>
Sourcepub fn from_language_server(state: S) -> Self
pub fn from_language_server(state: S) -> Self
Create a Router
using its implementation of LanguageServer
as handlers.
Source§impl<S> Router<S>
impl<S> Router<S>
Sourcepub fn from_language_client(state: S) -> Self
pub fn from_language_client(state: S) -> Self
Create a Router
using its implementation of LanguageClient
as handlers.