edit prediction cli: Skip worktree scan (#44658)

Release Notes:

- N/A

Co-authored-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
This commit is contained in:
Agus Zubiaga
2025-12-11 21:05:50 +00:00
committed by GitHub
co-authored by Max Brunsfeld
parent b5a0a3322d
commit 37f2ac24b8
10 changed files with 149 additions and 51 deletions
+43 -11
View File
@@ -14,7 +14,7 @@ use futures::{
mpsc::{self, UnboundedSender},
oneshot,
},
select_biased,
select_biased, stream,
task::Poll,
};
use fuzzy::CharBag;
@@ -129,6 +129,7 @@ pub struct LocalWorktree {
next_entry_id: Arc<AtomicUsize>,
settings: WorktreeSettings,
share_private_files: bool,
scanning_enabled: bool,
}
pub struct PathPrefixScanRequest {
@@ -356,6 +357,7 @@ impl Worktree {
visible: bool,
fs: Arc<dyn Fs>,
next_entry_id: Arc<AtomicUsize>,
scanning_enabled: bool,
cx: &mut AsyncApp,
) -> Result<Entity<Self>> {
let abs_path = path.into();
@@ -459,6 +461,7 @@ impl Worktree {
fs_case_sensitive,
visible,
settings,
scanning_enabled,
};
worktree.start_background_scanner(scan_requests_rx, path_prefixes_to_scan_rx, cx);
Worktree::Local(worktree)
@@ -1049,13 +1052,18 @@ impl LocalWorktree {
let share_private_files = self.share_private_files;
let next_entry_id = self.next_entry_id.clone();
let fs = self.fs.clone();
let scanning_enabled = self.scanning_enabled;
let settings = self.settings.clone();
let (scan_states_tx, mut scan_states_rx) = mpsc::unbounded();
let background_scanner = cx.background_spawn({
let abs_path = snapshot.abs_path.as_path().to_path_buf();
let background = cx.background_executor().clone();
async move {
let (events, watcher) = fs.watch(&abs_path, FS_WATCH_LATENCY).await;
let (events, watcher) = if scanning_enabled {
fs.watch(&abs_path, FS_WATCH_LATENCY).await
} else {
(Box::pin(stream::pending()) as _, Arc::new(NullWatcher) as _)
};
let fs_case_sensitive = fs.is_case_sensitive().await.unwrap_or_else(|e| {
log::error!("Failed to determine whether filesystem is case sensitive: {e:#}");
true
@@ -1080,6 +1088,7 @@ impl LocalWorktree {
}),
phase: BackgroundScannerPhase::InitialScan,
share_private_files,
scanning_enabled,
settings,
watcher,
};
@@ -3617,6 +3626,7 @@ struct BackgroundScanner {
watcher: Arc<dyn Watcher>,
settings: WorktreeSettings,
share_private_files: bool,
scanning_enabled: bool,
}
#[derive(Copy, Clone, PartialEq)]
@@ -3632,14 +3642,23 @@ impl BackgroundScanner {
// the git repository in an ancestor directory. Find any gitignore files
// in ancestor directories.
let root_abs_path = self.state.lock().await.snapshot.abs_path.clone();
let (ignores, repo) = discover_ancestor_git_repo(self.fs.clone(), &root_abs_path).await;
self.state
.lock()
.await
.snapshot
.ignores_by_parent_abs_path
.extend(ignores);
let containing_git_repository = if let Some((ancestor_dot_git, work_directory)) = repo {
let repo = if self.scanning_enabled {
let (ignores, repo) = discover_ancestor_git_repo(self.fs.clone(), &root_abs_path).await;
self.state
.lock()
.await
.snapshot
.ignores_by_parent_abs_path
.extend(ignores);
repo
} else {
None
};
let containing_git_repository = if let Some((ancestor_dot_git, work_directory)) = repo
&& self.scanning_enabled
{
maybe!(async {
self.state
.lock()
@@ -3663,6 +3682,7 @@ impl BackgroundScanner {
let mut global_gitignore_events = if let Some(global_gitignore_path) =
&paths::global_gitignore_path()
&& self.scanning_enabled
{
let is_file = self.fs.is_file(&global_gitignore_path).await;
self.state.lock().await.snapshot.global_gitignore = if is_file {
@@ -3705,7 +3725,7 @@ impl BackgroundScanner {
.insert_entry(root_entry, self.fs.as_ref(), self.watcher.as_ref())
.await;
}
if root_entry.is_dir() {
if root_entry.is_dir() && self.scanning_enabled {
state
.enqueue_scan_dir(
root_abs_path.as_path().into(),
@@ -5641,3 +5661,15 @@ async fn discover_git_paths(dot_git_abs_path: &Arc<Path>, fs: &dyn Fs) -> (Arc<P
};
(repository_dir_abs_path, common_dir_abs_path)
}
struct NullWatcher;
impl fs::Watcher for NullWatcher {
fn add(&self, _path: &Path) -> Result<()> {
Ok(())
}
fn remove(&self, _path: &Path) -> Result<()> {
Ok(())
}
}
+25
View File
@@ -44,6 +44,7 @@ async fn test_traversal(cx: &mut TestAppContext) {
true,
fs,
Default::default(),
true,
&mut cx.to_async(),
)
.await
@@ -108,6 +109,7 @@ async fn test_circular_symlinks(cx: &mut TestAppContext) {
true,
fs.clone(),
Default::default(),
true,
&mut cx.to_async(),
)
.await
@@ -207,6 +209,7 @@ async fn test_symlinks_pointing_outside(cx: &mut TestAppContext) {
true,
fs.clone(),
Default::default(),
true,
&mut cx.to_async(),
)
.await
@@ -357,6 +360,7 @@ async fn test_renaming_case_only(cx: &mut TestAppContext) {
true,
fs.clone(),
Default::default(),
true,
&mut cx.to_async(),
)
.await
@@ -434,6 +438,7 @@ async fn test_open_gitignored_files(cx: &mut TestAppContext) {
true,
fs.clone(),
Default::default(),
true,
&mut cx.to_async(),
)
.await
@@ -598,6 +603,7 @@ async fn test_dirs_no_longer_ignored(cx: &mut TestAppContext) {
true,
fs.clone(),
Default::default(),
true,
&mut cx.to_async(),
)
.await
@@ -698,6 +704,7 @@ async fn test_write_file(cx: &mut TestAppContext) {
true,
Arc::new(RealFs::new(None, cx.executor())),
Default::default(),
true,
&mut cx.to_async(),
)
.await
@@ -791,6 +798,7 @@ async fn test_file_scan_inclusions(cx: &mut TestAppContext) {
true,
Arc::new(RealFs::new(None, cx.executor())),
Default::default(),
true,
&mut cx.to_async(),
)
.await
@@ -856,6 +864,7 @@ async fn test_file_scan_exclusions_overrules_inclusions(cx: &mut TestAppContext)
true,
Arc::new(RealFs::new(None, cx.executor())),
Default::default(),
true,
&mut cx.to_async(),
)
.await
@@ -914,6 +923,7 @@ async fn test_file_scan_inclusions_reindexes_on_setting_change(cx: &mut TestAppC
true,
Arc::new(RealFs::new(None, cx.executor())),
Default::default(),
true,
&mut cx.to_async(),
)
.await
@@ -999,6 +1009,7 @@ async fn test_file_scan_exclusions(cx: &mut TestAppContext) {
true,
Arc::new(RealFs::new(None, cx.executor())),
Default::default(),
true,
&mut cx.to_async(),
)
.await
@@ -1080,6 +1091,7 @@ async fn test_hidden_files(cx: &mut TestAppContext) {
true,
Arc::new(RealFs::new(None, cx.executor())),
Default::default(),
true,
&mut cx.to_async(),
)
.await
@@ -1190,6 +1202,7 @@ async fn test_fs_events_in_exclusions(cx: &mut TestAppContext) {
true,
Arc::new(RealFs::new(None, cx.executor())),
Default::default(),
true,
&mut cx.to_async(),
)
.await
@@ -1301,6 +1314,7 @@ async fn test_fs_events_in_dot_git_worktree(cx: &mut TestAppContext) {
true,
Arc::new(RealFs::new(None, cx.executor())),
Default::default(),
true,
&mut cx.to_async(),
)
.await
@@ -1339,6 +1353,7 @@ async fn test_create_directory_during_initial_scan(cx: &mut TestAppContext) {
true,
fs,
Default::default(),
true,
&mut cx.to_async(),
)
.await
@@ -1407,6 +1422,7 @@ async fn test_create_dir_all_on_create_entry(cx: &mut TestAppContext) {
true,
fs_fake,
Default::default(),
true,
&mut cx.to_async(),
)
.await
@@ -1448,6 +1464,7 @@ async fn test_create_dir_all_on_create_entry(cx: &mut TestAppContext) {
true,
fs_real,
Default::default(),
true,
&mut cx.to_async(),
)
.await
@@ -1556,6 +1573,7 @@ async fn test_create_file_in_expanded_gitignored_dir(cx: &mut TestAppContext) {
true,
fs.clone(),
Default::default(),
true,
&mut cx.to_async(),
)
.await
@@ -1651,6 +1669,7 @@ async fn test_fs_event_for_gitignored_dir_does_not_lose_contents(cx: &mut TestAp
true,
fs.clone(),
Default::default(),
true,
&mut cx.to_async(),
)
.await
@@ -1728,6 +1747,7 @@ async fn test_random_worktree_operations_during_initial_scan(
true,
fs.clone(),
Default::default(),
true,
&mut cx.to_async(),
)
.await
@@ -1818,6 +1838,7 @@ async fn test_random_worktree_changes(cx: &mut TestAppContext, mut rng: StdRng)
true,
fs.clone(),
Default::default(),
true,
&mut cx.to_async(),
)
.await
@@ -1890,6 +1911,7 @@ async fn test_random_worktree_changes(cx: &mut TestAppContext, mut rng: StdRng)
true,
fs.clone(),
Default::default(),
true,
&mut cx.to_async(),
)
.await
@@ -2203,6 +2225,7 @@ async fn test_private_single_file_worktree(cx: &mut TestAppContext) {
true,
fs.clone(),
Default::default(),
true,
&mut cx.to_async(),
)
.await
@@ -2235,6 +2258,7 @@ async fn test_repository_above_root(executor: BackgroundExecutor, cx: &mut TestA
true,
fs.clone(),
Arc::default(),
true,
&mut cx.to_async(),
)
.await
@@ -2312,6 +2336,7 @@ async fn test_global_gitignore(executor: BackgroundExecutor, cx: &mut TestAppCon
true,
fs.clone(),
Arc::default(),
true,
&mut cx.to_async(),
)
.await