From 2712cadaf69b2495fd8f4ebe91df63b3a73504a6 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 21 Jan 2022 17:44:24 -0800 Subject: [PATCH] Get integration tests passing * Fix misuse of guest buffer's id as its remote id Co-Authored-By: Nathan Sobo --- crates/project/src/project.rs | 12 ++++--- crates/project/src/worktree.rs | 12 +++---- crates/server/src/rpc.rs | 64 ++++++++++++---------------------- 3 files changed, 35 insertions(+), 53 deletions(-) diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index e161fcab91..e7b221a985 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -427,7 +427,7 @@ impl Project { for worktree in this.worktrees(cx).collect::>() { worktree.update(cx, |worktree, cx| { let worktree = worktree.as_local_mut().unwrap(); - tasks.push(worktree.share(cx)); + tasks.push(worktree.share(project_id, cx)); }); } }); @@ -526,12 +526,14 @@ impl Project { cx.spawn(move |this, mut cx| async move { let load_result = load_buffer.await; - *tx.borrow_mut() = Some(this.update(&mut cx, |this, _| { + *tx.borrow_mut() = Some(this.update(&mut cx, |this, cx| { // Record the fact that the buffer is no longer loading. this.loading_buffers.remove(&path); let buffer = load_result.map_err(Arc::new)?; - this.open_buffers - .insert(buffer.id(), OpenBuffer::Loaded(buffer.downgrade())); + this.open_buffers.insert( + buffer.read(cx).remote_id() as usize, + OpenBuffer::Loaded(buffer.downgrade()), + ); Ok((buffer, Arc::new(AtomicBool::new(true)))) })); }) @@ -1109,7 +1111,7 @@ impl Project { if is_shared { worktree .update(&mut cx, |worktree, cx| { - worktree.as_local_mut().unwrap().share(cx) + worktree.as_local_mut().unwrap().share(project_id, cx) }) .await?; } diff --git a/crates/project/src/worktree.rs b/crates/project/src/worktree.rs index 58271d8fdc..b364af2bf5 100644 --- a/crates/project/src/worktree.rs +++ b/crates/project/src/worktree.rs @@ -739,13 +739,11 @@ impl LocalWorktree { }) } - pub fn share(&mut self, cx: &mut ModelContext) -> Task> { - let project_id = if let Registration::Done { project_id } = self.registration { - project_id - } else { - return Task::ready(Err(anyhow!("cannot share worktree before registering it"))); - }; - + pub fn share( + &mut self, + project_id: u64, + cx: &mut ModelContext, + ) -> Task> { if self.share.is_some() { return Task::ready(Ok(())); } diff --git a/crates/server/src/rpc.rs b/crates/server/src/rpc.rs index cca6a3da4b..8032a85eef 100644 --- a/crates/server/src/rpc.rs +++ b/crates/server/src/rpc.rs @@ -1160,10 +1160,8 @@ mod tests { cx, ) }); - let (worktree_a, _) = project_a - .update(&mut cx_a, |p, cx| { - p.find_or_create_worktree_for_abs_path("/a", false, cx) - }) + let worktree_a = project_a + .update(&mut cx_a, |p, cx| p.add_local_worktree("/a", false, cx)) .await .unwrap(); let worktree_id = worktree_a.read_with(&cx_a, |tree, _| tree.id()); @@ -1298,10 +1296,8 @@ mod tests { cx, ) }); - let (worktree_a, _) = project_a - .update(&mut cx_a, |p, cx| { - p.find_or_create_worktree_for_abs_path("/a", false, cx) - }) + let worktree_a = project_a + .update(&mut cx_a, |p, cx| p.add_local_worktree("/a", false, cx)) .await .unwrap(); worktree_a @@ -1400,10 +1396,8 @@ mod tests { cx, ) }); - let (worktree_a, _) = project_a - .update(&mut cx_a, |p, cx| { - p.find_or_create_worktree_for_abs_path("/a", false, cx) - }) + let worktree_a = project_a + .update(&mut cx_a, |p, cx| p.add_local_worktree("/a", false, cx)) .await .unwrap(); worktree_a @@ -1470,7 +1464,9 @@ mod tests { .condition(&mut cx_a, |buf, _| buf.text() == "i-am-c, i-am-b, i-am-a") .await; buffer_b - .condition(&mut cx_b, |buf, _| buf.text() == "i-am-c, i-am-b, i-am-a") + .condition(&mut cx_b, |buf, _| { + dbg!(buf.text()) == "i-am-c, i-am-b, i-am-a" + }) .await; buffer_c .condition(&mut cx_c, |buf, _| buf.text() == "i-am-c, i-am-b, i-am-a") @@ -1550,10 +1546,8 @@ mod tests { cx, ) }); - let (worktree_a, _) = project_a - .update(&mut cx_a, |p, cx| { - p.find_or_create_worktree_for_abs_path("/dir", false, cx) - }) + let worktree_a = project_a + .update(&mut cx_a, |p, cx| p.add_local_worktree("/dir", false, cx)) .await .unwrap(); worktree_a @@ -1645,10 +1639,8 @@ mod tests { cx, ) }); - let (worktree_a, _) = project_a - .update(&mut cx_a, |p, cx| { - p.find_or_create_worktree_for_abs_path("/dir", false, cx) - }) + let worktree_a = project_a + .update(&mut cx_a, |p, cx| p.add_local_worktree("/dir", false, cx)) .await .unwrap(); worktree_a @@ -1725,10 +1717,8 @@ mod tests { cx, ) }); - let (worktree_a, _) = project_a - .update(&mut cx_a, |p, cx| { - p.find_or_create_worktree_for_abs_path("/dir", false, cx) - }) + let worktree_a = project_a + .update(&mut cx_a, |p, cx| p.add_local_worktree("/dir", false, cx)) .await .unwrap(); worktree_a @@ -1801,10 +1791,8 @@ mod tests { cx, ) }); - let (worktree_a, _) = project_a - .update(&mut cx_a, |p, cx| { - p.find_or_create_worktree_for_abs_path("/a", false, cx) - }) + let worktree_a = project_a + .update(&mut cx_a, |p, cx| p.add_local_worktree("/a", false, cx)) .await .unwrap(); worktree_a @@ -1890,10 +1878,8 @@ mod tests { cx, ) }); - let (worktree_a, _) = project_a - .update(&mut cx_a, |p, cx| { - p.find_or_create_worktree_for_abs_path("/a", false, cx) - }) + let worktree_a = project_a + .update(&mut cx_a, |p, cx| p.add_local_worktree("/a", false, cx)) .await .unwrap(); worktree_a @@ -2110,10 +2096,8 @@ mod tests { cx, ) }); - let (worktree_a, _) = project_a - .update(&mut cx_a, |p, cx| { - p.find_or_create_worktree_for_abs_path("/a", false, cx) - }) + let worktree_a = project_a + .update(&mut cx_a, |p, cx| p.add_local_worktree("/a", false, cx)) .await .unwrap(); worktree_a @@ -2617,10 +2601,8 @@ mod tests { cx, ) }); - let (worktree_a, _) = project_a - .update(&mut cx_a, |p, cx| { - p.find_or_create_worktree_for_abs_path("/a", false, cx) - }) + let worktree_a = project_a + .update(&mut cx_a, |p, cx| p.add_local_worktree("/a", false, cx)) .await .unwrap(); worktree_a