mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-08 07:35:01 +03:00
Wait for version before returning completions
This commit is contained in:
parent
e824a6f220
commit
50a31721eb
@ -1283,6 +1283,10 @@ impl Buffer {
|
||||
self.text.wait_for_edits(edit_ids)
|
||||
}
|
||||
|
||||
pub fn wait_for_version(&mut self, version: clock::Global) -> impl Future<Output = ()> {
|
||||
self.text.wait_for_version(version)
|
||||
}
|
||||
|
||||
pub fn set_active_selections(
|
||||
&mut self,
|
||||
selections: Arc<[Selection<Anchor>]>,
|
||||
|
@ -1401,15 +1401,14 @@ impl Project {
|
||||
position: Some(language::proto::serialize_anchor(&anchor)),
|
||||
version: (&source_buffer.version()).into(),
|
||||
};
|
||||
cx.spawn_weak(|_, cx| async move {
|
||||
cx.spawn_weak(|_, mut cx| async move {
|
||||
let response = rpc.request(message).await?;
|
||||
|
||||
if !source_buffer_handle
|
||||
.read_with(&cx, |buffer, _| buffer.version())
|
||||
.observed_all(&response.version.into())
|
||||
{
|
||||
Err(anyhow!("completion response depends on unreceived edits"))?;
|
||||
}
|
||||
source_buffer_handle
|
||||
.update(&mut cx, |buffer, _| {
|
||||
buffer.wait_for_version(response.version.into())
|
||||
})
|
||||
.await;
|
||||
|
||||
response
|
||||
.completions
|
||||
|
@ -4196,17 +4196,18 @@ mod tests {
|
||||
drop(buffer);
|
||||
});
|
||||
}
|
||||
10..=14 => {
|
||||
10..=19 => {
|
||||
let completions = project.update(&mut cx, |project, cx| {
|
||||
log::info!(
|
||||
"Guest {}: requesting completions for buffer {:?}",
|
||||
guest_id,
|
||||
buffer.read(cx).file().unwrap().full_path(cx)
|
||||
);
|
||||
project.completions(&buffer, 0, cx)
|
||||
let offset = rng.borrow_mut().gen_range(0..=buffer.read(cx).len());
|
||||
project.completions(&buffer, offset, cx)
|
||||
});
|
||||
let completions = cx.background().spawn(async move {
|
||||
completions.await.expect("code actions request failed");
|
||||
completions.await.expect("completions request failed");
|
||||
});
|
||||
if rng.borrow_mut().gen_bool(0.3) {
|
||||
log::info!("Guest {}: detaching completions request", guest_id);
|
||||
@ -4215,14 +4216,16 @@ mod tests {
|
||||
completions.await;
|
||||
}
|
||||
}
|
||||
15..=19 => {
|
||||
20..=29 => {
|
||||
let code_actions = project.update(&mut cx, |project, cx| {
|
||||
log::info!(
|
||||
"Guest {}: requesting code actions for buffer {:?}",
|
||||
guest_id,
|
||||
buffer.read(cx).file().unwrap().full_path(cx)
|
||||
);
|
||||
project.code_actions(&buffer, 0..0, cx)
|
||||
let range =
|
||||
buffer.read(cx).random_byte_range(0, &mut *rng.borrow_mut());
|
||||
project.code_actions(&buffer, range, cx)
|
||||
});
|
||||
let code_actions = cx.background().spawn(async move {
|
||||
code_actions.await.expect("code actions request failed");
|
||||
@ -4234,7 +4237,7 @@ mod tests {
|
||||
code_actions.await;
|
||||
}
|
||||
}
|
||||
20..=29 if buffer.read_with(&cx, |buffer, _| buffer.is_dirty()) => {
|
||||
30..=39 if buffer.read_with(&cx, |buffer, _| buffer.is_dirty()) => {
|
||||
let (requested_version, save) = buffer.update(&mut cx, |buffer, cx| {
|
||||
log::info!(
|
||||
"Guest {}: saving buffer {:?}",
|
||||
|
@ -21,7 +21,7 @@ use operation_queue::OperationQueue;
|
||||
pub use patch::Patch;
|
||||
pub use point::*;
|
||||
pub use point_utf16::*;
|
||||
use postage::{oneshot, prelude::*};
|
||||
use postage::{barrier, oneshot, prelude::*};
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub use random_char_iter::*;
|
||||
use rope::TextDimension;
|
||||
@ -53,6 +53,7 @@ pub struct Buffer {
|
||||
pub lamport_clock: clock::Lamport,
|
||||
subscriptions: Topic,
|
||||
edit_id_resolvers: HashMap<clock::Local, Vec<oneshot::Sender<()>>>,
|
||||
version_barriers: Vec<(clock::Global, barrier::Sender)>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@ -574,6 +575,7 @@ impl Buffer {
|
||||
lamport_clock,
|
||||
subscriptions: Default::default(),
|
||||
edit_id_resolvers: Default::default(),
|
||||
version_barriers: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -835,6 +837,8 @@ impl Buffer {
|
||||
}
|
||||
}
|
||||
}
|
||||
self.version_barriers
|
||||
.retain(|(version, _)| !self.snapshot.version().observed_all(version));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -1305,6 +1309,16 @@ impl Buffer {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn wait_for_version(&mut self, version: clock::Global) -> impl Future<Output = ()> {
|
||||
let (tx, mut rx) = barrier::channel();
|
||||
if !self.snapshot.version.observed_all(&version) {
|
||||
self.version_barriers.push((version, tx));
|
||||
}
|
||||
async move {
|
||||
rx.recv().await;
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_edit(&mut self, edit_id: clock::Local) {
|
||||
for mut tx in self
|
||||
.edit_id_resolvers
|
||||
|
Loading…
Reference in New Issue
Block a user