From 2772f87198ad75fbe72aeae5b4bc7684ce0a0d35 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 29 May 2024 09:11:28 -0700 Subject: [PATCH] Make sure not to signal the main thread on fs events in ignored directories (#12436) Release Notes: - N/A --- crates/worktree/src/worktree.rs | 42 ++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/crates/worktree/src/worktree.rs b/crates/worktree/src/worktree.rs index d5d3897670..4818f70aa0 100644 --- a/crates/worktree/src/worktree.rs +++ b/crates/worktree/src/worktree.rs @@ -3524,6 +3524,15 @@ impl BackgroundScanner { }) .collect::>(); + { + let mut state = self.state.lock(); + let is_idle = state.snapshot.completed_scan_id == state.snapshot.scan_id; + state.snapshot.scan_id += 1; + if is_idle { + state.snapshot.completed_scan_id = state.snapshot.scan_id; + } + } + self.reload_entries_for_paths( root_path, root_canonical_path, @@ -3532,6 +3541,7 @@ impl BackgroundScanner { None, ) .await; + self.send_status_update(scanning, Some(request.done)) } @@ -3605,19 +3615,23 @@ impl BackgroundScanner { } }); - let (scan_job_tx, scan_job_rx) = channel::unbounded(); - if !relative_paths.is_empty() || !dot_git_paths.is_empty() { - log::debug!("received fs events {:?}", relative_paths); - self.reload_entries_for_paths( - root_path, - root_canonical_path, - &relative_paths, - abs_paths, - Some(scan_job_tx.clone()), - ) - .await; + if relative_paths.is_empty() && dot_git_paths.is_empty() { + return; } + self.state.lock().snapshot.scan_id += 1; + + let (scan_job_tx, scan_job_rx) = channel::unbounded(); + log::debug!("received fs events {:?}", relative_paths); + self.reload_entries_for_paths( + root_path, + root_canonical_path, + &relative_paths, + abs_paths, + Some(scan_job_tx.clone()), + ) + .await; + self.update_ignore_statuses(scan_job_tx).await; self.scan_dirs(false, scan_job_rx).await; @@ -4025,13 +4039,7 @@ impl BackgroundScanner { .await; let mut state = self.state.lock(); - let snapshot = &mut state.snapshot; - let is_idle = snapshot.completed_scan_id == snapshot.scan_id; let doing_recursive_update = scan_queue_tx.is_some(); - snapshot.scan_id += 1; - if is_idle && !doing_recursive_update { - snapshot.completed_scan_id = snapshot.scan_id; - } // Remove any entries for paths that no longer exist or are being recursively // refreshed. Do this before adding any new entries, so that renames can be