Skip to content

Commit

Permalink
Auto merge of rust-lang#17932 - Veykril:default-reply-lat-sensitive, …
Browse files Browse the repository at this point in the history
…r=Veykril

fix: Fix panics for semantic highlighting at startup

Without this we might try to process semantic highlighting requests before the database has entries for the given file resulting in a panic. There is no work to be done either way so delay this like we do with other request handlers.
  • Loading branch information
bors committed Aug 20, 2024
2 parents df6ce96 + a7d15a8 commit a9e3555
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,26 @@ impl RequestDispatcher<'_> {
self.on_with_thread_intent::<true, ALLOW_RETRYING, R>(ThreadIntent::Worker, f)
}

/// Dispatches a latency-sensitive request onto the thread pool.
/// Dispatches a latency-sensitive request onto the thread pool. When the VFS is marked not
/// ready this will return a default constructed [`R::Result`].
pub(crate) fn on_latency_sensitive<const ALLOW_RETRYING: bool, R>(
&mut self,
f: fn(GlobalStateSnapshot, R::Params) -> anyhow::Result<R::Result>,
) -> &mut Self
where
R: lsp_types::request::Request + 'static,
R::Params: DeserializeOwned + panic::UnwindSafe + Send + fmt::Debug,
R::Result: Serialize,
R: lsp_types::request::Request<
Params: DeserializeOwned + panic::UnwindSafe + Send + fmt::Debug,
Result: Serialize + Default,
> + 'static,
{
if !self.global_state.vfs_done {
if let Some(lsp_server::Request { id, .. }) =
self.req.take_if(|it| it.method == R::METHOD)
{
self.global_state.respond(lsp_server::Response::new_ok(id, R::Result::default()));
}
return self;
}
self.on_with_thread_intent::<true, ALLOW_RETRYING, R>(ThreadIntent::LatencySensitive, f)
}

Expand Down

0 comments on commit a9e3555

Please sign in to comment.