diff options
| author | Lukas Wirth <lukastw97@gmail.com> | 2024-08-20 09:53:37 +0200 |
|---|---|---|
| committer | Lukas Wirth <lukastw97@gmail.com> | 2024-08-20 09:53:37 +0200 |
| commit | a7d15a8c3b5e9bd651d2a2606e3bd346e2b3b2d1 (patch) | |
| tree | 65080384849bc0126afbfe6df7bd77dee9d6f7f4 | |
| parent | df6ce9607ca80cd2068393b0cb2178ae1c39c677 (diff) | |
| download | rust-a7d15a8c3b5e9bd651d2a2606e3bd346e2b3b2d1.tar.gz rust-a7d15a8c3b5e9bd651d2a2606e3bd346e2b3b2d1.zip | |
fix: Fix panics for semantic highlighting at startup
| -rw-r--r-- | src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/dispatch.rs | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/dispatch.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/dispatch.rs index a105ec63820..f03de8ce0f0 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/dispatch.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/dispatch.rs @@ -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) } |
