pub(crate) struct RequestDispatcher<'a> {
pub(crate) req: Option<Request>,
pub(crate) global_state: &'a mut GlobalState,
}Expand description
A visitor for routing a raw JSON request to an appropriate handler function.
Most requests are read-only and async and are handled on the threadpool
(on method).
Some read-only requests are latency sensitive, and are immediately handled
on the main loop thread (on_sync). These are typically typing-related
requests.
Some requests modify the state, and are run on the main thread to get
&mut (on_sync_mut).
Read-only requests are wrapped into catch_unwind – they don’t modify the
state, so it’s OK to recover from their failures.
Fields§
§req: Option<Request>§global_state: &'a mut GlobalStateImplementations§
Source§impl RequestDispatcher<'_>
impl RequestDispatcher<'_>
Sourcepub(crate) fn on_sync_mut<R>(
&mut self,
f: fn(&mut GlobalState, R::Params) -> Result<R::Result>,
) -> &mut Self
pub(crate) fn on_sync_mut<R>( &mut self, f: fn(&mut GlobalState, R::Params) -> Result<R::Result>, ) -> &mut Self
Dispatches the request onto the current thread, given full access to
mutable global state. Unlike all other methods here, this one isn’t
guarded by catch_unwind, so, please, don’t make bugs :-)
Sourcepub(crate) fn on_sync<R>(
&mut self,
f: fn(GlobalStateSnapshot, R::Params) -> Result<R::Result>,
) -> &mut Self
pub(crate) fn on_sync<R>( &mut self, f: fn(GlobalStateSnapshot, R::Params) -> Result<R::Result>, ) -> &mut Self
Dispatches the request onto the current thread.
Sourcepub(crate) fn on<const ALLOW_RETRYING: bool, R>(
&mut self,
f: fn(GlobalStateSnapshot, R::Params) -> Result<R::Result>,
) -> &mut Selfwhere
R: Request<Params: DeserializeOwned + UnwindSafe + Send + Debug, Result: Serialize + Default> + 'static,
pub(crate) fn on<const ALLOW_RETRYING: bool, R>(
&mut self,
f: fn(GlobalStateSnapshot, R::Params) -> Result<R::Result>,
) -> &mut Selfwhere
R: Request<Params: DeserializeOwned + UnwindSafe + Send + Debug, Result: Serialize + Default> + 'static,
Dispatches a non-latency-sensitive request onto the thread pool. When the VFS is marked not
ready this will return a default constructed R::Result.
Sourcepub(crate) fn on_with_vfs_default<R>(
&mut self,
f: fn(GlobalStateSnapshot, R::Params) -> Result<R::Result>,
default: impl FnOnce() -> R::Result,
on_cancelled: fn() -> ResponseError,
) -> &mut Selfwhere
R: Request<Params: DeserializeOwned + UnwindSafe + Send + Debug, Result: Serialize> + 'static,
pub(crate) fn on_with_vfs_default<R>(
&mut self,
f: fn(GlobalStateSnapshot, R::Params) -> Result<R::Result>,
default: impl FnOnce() -> R::Result,
on_cancelled: fn() -> ResponseError,
) -> &mut Selfwhere
R: Request<Params: DeserializeOwned + UnwindSafe + Send + Debug, Result: Serialize> + 'static,
Dispatches a non-latency-sensitive request onto the thread pool. When the VFS is marked not
ready this will return a default constructed R::Result.
Sourcepub(crate) fn on_identity<const ALLOW_RETRYING: bool, R, Params>(
&mut self,
f: fn(GlobalStateSnapshot, Params) -> Result<R::Result>,
) -> &mut Selfwhere
R: Request<Params = Params, Result = Params> + 'static,
Params: Serialize + DeserializeOwned + UnwindSafe + Send + Debug,
pub(crate) fn on_identity<const ALLOW_RETRYING: bool, R, Params>(
&mut self,
f: fn(GlobalStateSnapshot, Params) -> Result<R::Result>,
) -> &mut Selfwhere
R: Request<Params = Params, Result = Params> + 'static,
Params: Serialize + DeserializeOwned + UnwindSafe + Send + Debug,
Dispatches a non-latency-sensitive request onto the thread pool. When the VFS is marked not ready this will return the parameter as is.
Sourcepub(crate) fn on_latency_sensitive<const ALLOW_RETRYING: bool, R>(
&mut self,
f: fn(GlobalStateSnapshot, R::Params) -> Result<R::Result>,
) -> &mut Selfwhere
R: Request<Params: DeserializeOwned + UnwindSafe + Send + Debug, Result: Serialize + Default> + 'static,
pub(crate) fn on_latency_sensitive<const ALLOW_RETRYING: bool, R>(
&mut self,
f: fn(GlobalStateSnapshot, R::Params) -> Result<R::Result>,
) -> &mut Selfwhere
R: Request<Params: DeserializeOwned + UnwindSafe + Send + Debug, Result: Serialize + Default> + 'static,
Dispatches a latency-sensitive request onto the thread pool. When the VFS is marked not
ready this will return a default constructed R::Result.
Sourcepub(crate) fn on_fmt_thread<R>(
&mut self,
f: fn(GlobalStateSnapshot, R::Params) -> Result<R::Result>,
) -> &mut Selfwhere
R: Request + 'static,
R::Params: DeserializeOwned + UnwindSafe + Send + Debug,
R::Result: Serialize,
pub(crate) fn on_fmt_thread<R>(
&mut self,
f: fn(GlobalStateSnapshot, R::Params) -> Result<R::Result>,
) -> &mut Selfwhere
R: Request + 'static,
R::Params: DeserializeOwned + UnwindSafe + Send + Debug,
R::Result: Serialize,
Formatting requests should never block on waiting a for task thread to open up, editors will wait on the response and a late formatting update might mess with the document and user. We can’t run this on the main thread though as we invoke rustfmt which may take arbitrary time to complete!
pub(crate) fn finish(&mut self)
fn on_with_thread_intent<const RUSTFMT: bool, const ALLOW_RETRYING: bool, R>(
&mut self,
intent: ThreadIntent,
f: fn(GlobalStateSnapshot, R::Params) -> Result<R::Result>,
on_cancelled: fn() -> ResponseError,
) -> &mut Selfwhere
R: Request + 'static,
R::Params: DeserializeOwned + UnwindSafe + Send + Debug,
R::Result: Serialize,
fn parse<R>(&mut self) -> Option<(Request, R::Params, String)>where
R: Request,
R::Params: DeserializeOwned + Debug,
fn content_modified_error() -> ResponseError
Auto Trait Implementations§
impl<'a> Freeze for RequestDispatcher<'a>
impl<'a> !RefUnwindSafe for RequestDispatcher<'a>
impl<'a> !Send for RequestDispatcher<'a>
impl<'a> !Sync for RequestDispatcher<'a>
impl<'a> Unpin for RequestDispatcher<'a>
impl<'a> UnsafeUnpin for RequestDispatcher<'a>
impl<'a> !UnwindSafe for RequestDispatcher<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more