Error if project is disconnected after getting completions response

This commit is contained in:
Antonio Scandurra 2022-11-28 19:18:31 +01:00
parent fa3f100eff
commit d0709e7bfa

View file

@ -3408,9 +3408,18 @@ impl Project {
position: Some(language::proto::serialize_anchor(&anchor)), position: Some(language::proto::serialize_anchor(&anchor)),
version: serialize_version(&source_buffer.version()), version: serialize_version(&source_buffer.version()),
}; };
cx.spawn_weak(|_, mut cx| async move { cx.spawn_weak(|this, mut cx| async move {
let response = rpc.request(message).await?; let response = rpc.request(message).await?;
if this
.upgrade(&cx)
.ok_or_else(|| anyhow!("project was dropped"))?
.read_with(&cx, |this, _| this.is_read_only())
{
return Err(anyhow!(
"failed to get completions: project was disconnected"
));
} else {
source_buffer_handle source_buffer_handle
.update(&mut cx, |buffer, _| { .update(&mut cx, |buffer, _| {
buffer.wait_for_version(deserialize_version(response.version)) buffer.wait_for_version(deserialize_version(response.version))
@ -3421,6 +3430,7 @@ impl Project {
language::proto::deserialize_completion(completion, language.clone()) language::proto::deserialize_completion(completion, language.clone())
}); });
futures::future::try_join_all(completions).await futures::future::try_join_all(completions).await
}
}) })
} else { } else {
Task::ready(Ok(Default::default())) Task::ready(Ok(Default::default()))