From 47ce8ae05c952bcecf091bfc3132bca15092edae Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Mon, 16 May 2022 11:50:21 +0200 Subject: [PATCH] Poll snapshot after refreshing entry --- crates/project/src/worktree.rs | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/crates/project/src/worktree.rs b/crates/project/src/worktree.rs index abaf49c9f2..1c77c3add7 100644 --- a/crates/project/src/worktree.rs +++ b/crates/project/src/worktree.rs @@ -826,7 +826,7 @@ impl LocalWorktree { root_char_bag = snapshot.root_char_bag; next_entry_id = snapshot.next_entry_id.clone(); } - cx.spawn_weak(|this, cx| async move { + cx.spawn_weak(|this, mut cx| async move { let entry = Entry::new( path, &fs.metadata(&abs_path) @@ -836,20 +836,21 @@ impl LocalWorktree { root_char_bag, ); - let (entry, snapshot, snapshots_tx) = this + let this = this .upgrade(&cx) - .ok_or_else(|| anyhow!("worktree was dropped"))? - .read_with(&cx, |this, _| { - let this = this.as_local().unwrap(); - let mut snapshot = this.background_snapshot.lock(); - if let Some(old_path) = old_path { - snapshot.remove_path(&old_path); - } - let entry = snapshot.insert_entry(entry, fs.as_ref()); - snapshot.scan_id += 1; - let snapshots_tx = this.share.as_ref().map(|s| s.snapshots_tx.clone()); - (entry, snapshot.clone(), snapshots_tx) - }); + .ok_or_else(|| anyhow!("worktree was dropped"))?; + let (entry, snapshot, snapshots_tx) = this.read_with(&cx, |this, _| { + let this = this.as_local().unwrap(); + let mut snapshot = this.background_snapshot.lock(); + if let Some(old_path) = old_path { + snapshot.remove_path(&old_path); + } + let entry = snapshot.insert_entry(entry, fs.as_ref()); + snapshot.scan_id += 1; + let snapshots_tx = this.share.as_ref().map(|s| s.snapshots_tx.clone()); + (entry, snapshot.clone(), snapshots_tx) + }); + this.update(&mut cx, |this, cx| this.poll_snapshot(cx)); if let Some(snapshots_tx) = snapshots_tx { snapshots_tx.send(snapshot).await.ok();