From ef04dc14ccf54b716cb331690fce25ef83939d72 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 6 Apr 2023 17:48:44 +0200 Subject: [PATCH] Update file on incomplete buffer instead of waiting for it to be opened This ensures that two successive file updates coming from the host are not applied in reverse order. --- crates/project/src/project.rs | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index a9cab023cd..4e39f5e155 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -5313,28 +5313,20 @@ impl Project { mut cx: AsyncAppContext, ) -> Result<()> { let buffer_id = envelope.payload.buffer_id; - let is_incomplete = this.read_with(&cx, |this, _| { - this.incomplete_remote_buffers.contains_key(&buffer_id) - }); - - let buffer = if is_incomplete { - Some( - this.update(&mut cx, |this, cx| { - this.wait_for_remote_buffer(buffer_id, cx) - }) - .await?, - ) - } else { - None - }; this.update(&mut cx, |this, cx| { let payload = envelope.payload.clone(); - if let Some(buffer) = buffer.or_else(|| { - this.opened_buffers - .get(&buffer_id) - .and_then(|b| b.upgrade(cx)) - }) { + if let Some(buffer) = this + .opened_buffers + .get(&buffer_id) + .and_then(|b| b.upgrade(cx)) + .or_else(|| { + this.incomplete_remote_buffers + .get(&buffer_id) + .cloned() + .flatten() + }) + { let file = payload.file.ok_or_else(|| anyhow!("invalid file"))?; let worktree = this .worktree_for_id(WorktreeId::from_proto(file.worktree_id), cx)