Skip to content

Commit b02c214

Browse files
committed
Auto merge of #17932 - Veykril:default-reply-lat-sensitive, 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.
2 parents 979e3b5 + 9b7b93e commit b02c214

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

Diff for: crates/rust-analyzer/src/handlers/dispatch.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,26 @@ impl RequestDispatcher<'_> {
139139
self.on_with_thread_intent::<true, ALLOW_RETRYING, R>(ThreadIntent::Worker, f)
140140
}
141141

142-
/// Dispatches a latency-sensitive request onto the thread pool.
142+
/// Dispatches a latency-sensitive request onto the thread pool. When the VFS is marked not
143+
/// ready this will return a default constructed [`R::Result`].
143144
pub(crate) fn on_latency_sensitive<const ALLOW_RETRYING: bool, R>(
144145
&mut self,
145146
f: fn(GlobalStateSnapshot, R::Params) -> anyhow::Result<R::Result>,
146147
) -> &mut Self
147148
where
148-
R: lsp_types::request::Request + 'static,
149-
R::Params: DeserializeOwned + panic::UnwindSafe + Send + fmt::Debug,
150-
R::Result: Serialize,
149+
R: lsp_types::request::Request<
150+
Params: DeserializeOwned + panic::UnwindSafe + Send + fmt::Debug,
151+
Result: Serialize + Default,
152+
> + 'static,
151153
{
154+
if !self.global_state.vfs_done {
155+
if let Some(lsp_server::Request { id, .. }) =
156+
self.req.take_if(|it| it.method == R::METHOD)
157+
{
158+
self.global_state.respond(lsp_server::Response::new_ok(id, R::Result::default()));
159+
}
160+
return self;
161+
}
152162
self.on_with_thread_intent::<true, ALLOW_RETRYING, R>(ThreadIntent::LatencySensitive, f)
153163
}
154164

0 commit comments

Comments
 (0)