From a1a4c7084582236cf83e9bdf5cffe3142fb55781 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 27 May 2022 10:48:47 -0700 Subject: [PATCH] Emit an event when adding a worktree to a project --- crates/collab/src/rpc.rs | 21 +++++++++++---------- crates/project/src/project.rs | 2 ++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/crates/collab/src/rpc.rs b/crates/collab/src/rpc.rs index 7ea925fce7d8dea824aeb24b6be936f0099655b0..6371e5178450c6abe3c1aa8684e0b77954c36fcb 100644 --- a/crates/collab/src/rpc.rs +++ b/crates/collab/src/rpc.rs @@ -2234,7 +2234,6 @@ mod tests { .read_with(cx_a, |project, _| project.next_remote_id()) .await; - let project_a_events = Rc::new(RefCell::new(Vec::new())); let user_b = client_a .user_store .update(cx_a, |store, cx| { @@ -2242,15 +2241,6 @@ mod tests { }) .await .unwrap(); - project_a.update(cx_a, { - let project_a_events = project_a_events.clone(); - move |_, cx| { - cx.subscribe(&cx.handle(), move |_, _, event, _| { - project_a_events.borrow_mut().push(event.clone()); - }) - .detach(); - } - }); let (worktree_a, _) = project_a .update(cx_a, |p, cx| { @@ -2262,6 +2252,17 @@ mod tests { .read_with(cx_a, |tree, _| tree.as_local().unwrap().scan_complete()) .await; + let project_a_events = Rc::new(RefCell::new(Vec::new())); + project_a.update(cx_a, { + let project_a_events = project_a_events.clone(); + move |_, cx| { + cx.subscribe(&cx.handle(), move |_, _, event, _| { + project_a_events.borrow_mut().push(event.clone()); + }) + .detach(); + } + }); + // Request to join that project as client B let project_b = cx_b.spawn(|mut cx| { let client = client_b.client.clone(); diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index abcd667293478ab1d13673d657e4e476852c5c38..964ee1c97e4b63454cf325fccf4189500acacf5c 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -139,6 +139,7 @@ pub struct Collaborator { #[derive(Clone, Debug, PartialEq, Eq)] pub enum Event { ActiveEntryChanged(Option), + WorktreeAdded, WorktreeRemoved(WorktreeId), DiskBasedDiagnosticsStarted, DiskBasedDiagnosticsUpdated, @@ -3637,6 +3638,7 @@ impl Project { self.worktrees .push(WorktreeHandle::Weak(worktree.downgrade())); } + cx.emit(Event::WorktreeAdded); cx.notify(); }