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,19 +3408,29 @@ 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?;
source_buffer_handle if this
.update(&mut cx, |buffer, _| { .upgrade(&cx)
buffer.wait_for_version(deserialize_version(response.version)) .ok_or_else(|| anyhow!("project was dropped"))?
}) .read_with(&cx, |this, _| this.is_read_only())
.await; {
return Err(anyhow!(
"failed to get completions: project was disconnected"
));
} else {
source_buffer_handle
.update(&mut cx, |buffer, _| {
buffer.wait_for_version(deserialize_version(response.version))
})
.await;
let completions = response.completions.into_iter().map(|completion| { let completions = response.completions.into_iter().map(|completion| {
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()))