From 4e748b188e7ddd7204c3436b1796f9098c6d9e13 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 14 Feb 2022 18:05:24 -0800 Subject: [PATCH] WIP - Wait for code action anchors to be valid --- crates/clock/src/clock.rs | 10 ++++++++++ crates/project/src/project.rs | 14 ++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/crates/clock/src/clock.rs b/crates/clock/src/clock.rs index 888889871f5330e773d832f217f6ca11b7515cb4..0fdeda0b99427150320f8d8f31e8b0ac212166a0 100644 --- a/crates/clock/src/clock.rs +++ b/crates/clock/src/clock.rs @@ -216,6 +216,16 @@ impl Global { } } +impl FromIterator for Global { + fn from_iter>(locals: T) -> Self { + let mut result = Self::new(); + for local in locals { + result.observe(local); + } + result + } +} + impl Ord for Lamport { fn cmp(&self, other: &Self) -> Ordering { // Use the replica id to break ties between concurrent events. diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 027ae52c2f407bbf93c2e71775748b2bdd83b996..7bfe9946a9dbf9aedc26e6d1db268ca36bce4319 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -2395,12 +2395,18 @@ impl Project { .end .and_then(language::proto::deserialize_anchor) .ok_or_else(|| anyhow!("invalid end"))?; - let code_actions = this.update(&mut cx, |this, cx| { - let buffer = this - .shared_buffers + let buffer = this.update(&mut cx, |this, _| { + this.shared_buffers .get(&sender_id) .and_then(|shared_buffers| shared_buffers.get(&envelope.payload.buffer_id).cloned()) - .ok_or_else(|| anyhow!("unknown buffer id {}", envelope.payload.buffer_id))?; + .ok_or_else(|| anyhow!("unknown buffer id {}", envelope.payload.buffer_id)) + })?; + buffer + .update(&mut cx, |buffer, _| { + buffer.wait_for_version([start.timestamp, end.timestamp].into_iter().collect()) + }) + .await; + let code_actions = this.update(&mut cx, |this, cx| { Ok::<_, anyhow::Error>(this.code_actions(&buffer, start..end, cx)) })?;