From 5b320d6714b720253f85f2542c27466d254d4f73 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 26 May 2025 23:24:32 +0300 Subject: [PATCH] Be more lenient when looking up gitignored files in file finder (#31457) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The lookup was disabled due to concerns of being forced to traverse many gitignored file entries. Since Zed does not index these eagerly, but only contents of the directories that are parent to the gitignored file entries, it might be not that bad — let's see how much improvement it provides. Closes https://github.com/zed-industries/zed/issues/31016 Release Notes: - Improved file finder to include indexed gitignored files in its search results --- crates/file_finder/src/file_finder.rs | 4 +- crates/file_finder/src/file_finder_tests.rs | 85 +++++++++++++++++++-- 2 files changed, 79 insertions(+), 10 deletions(-) diff --git a/crates/file_finder/src/file_finder.rs b/crates/file_finder/src/file_finder.rs index e0819aa14a..24721f1fa2 100644 --- a/crates/file_finder/src/file_finder.rs +++ b/crates/file_finder/src/file_finder.rs @@ -779,9 +779,7 @@ impl FileFinderDelegate { let worktree = worktree.read(cx); PathMatchCandidateSet { snapshot: worktree.snapshot(), - include_ignored: worktree - .root_entry() - .map_or(false, |entry| entry.is_ignored), + include_ignored: true, include_root_name, candidates: project::Candidates::Files, } diff --git a/crates/file_finder/src/file_finder_tests.rs b/crates/file_finder/src/file_finder_tests.rs index 71bfef2685..3c6e5b93dd 100644 --- a/crates/file_finder/src/file_finder_tests.rs +++ b/crates/file_finder/src/file_finder_tests.rs @@ -7,7 +7,7 @@ use menu::{Confirm, SelectNext, SelectPrevious}; use project::{FS_WATCH_LATENCY, RemoveOptions}; use serde_json::json; use util::path; -use workspace::{AppState, OpenOptions, ToggleFileFinder, Workspace}; +use workspace::{AppState, CloseActiveItem, OpenOptions, ToggleFileFinder, Workspace}; #[ctor::ctor] fn init_logger() { @@ -615,9 +615,13 @@ async fn test_ignored_root(cx: &mut TestAppContext) { "hiccup": "", }, "tracked-root": { - ".gitignore": "height", + ".gitignore": "height*", "happiness": "", "height": "", + "heights": { + "height_1": "", + "height_2": "", + }, "hi": "", "hiccup": "", }, @@ -628,14 +632,13 @@ async fn test_ignored_root(cx: &mut TestAppContext) { let project = Project::test( app_state.fs.clone(), [ - "/ancestor/tracked-root".as_ref(), - "/ancestor/ignored-root".as_ref(), + Path::new(path!("/ancestor/tracked-root")), + Path::new(path!("/ancestor/ignored-root")), ], cx, ) .await; - - let (picker, _, cx) = build_find_picker(project, cx); + let (picker, workspace, cx) = build_find_picker(project, cx); picker .update_in(cx, |picker, window, cx| { @@ -644,7 +647,75 @@ async fn test_ignored_root(cx: &mut TestAppContext) { .spawn_search(test_path_position("hi"), window, cx) }) .await; - picker.update(cx, |picker, _| assert_eq!(picker.delegate.matches.len(), 7)); + picker.update(cx, |picker, _| { + let matches = collect_search_matches(picker); + assert_eq!(matches.history.len(), 0); + assert_eq!( + matches.search, + vec![ + PathBuf::from("ignored-root/hi"), + PathBuf::from("tracked-root/hi"), + PathBuf::from("ignored-root/hiccup"), + PathBuf::from("tracked-root/hiccup"), + PathBuf::from("ignored-root/height"), + PathBuf::from("tracked-root/height"), + PathBuf::from("ignored-root/happiness"), + PathBuf::from("tracked-root/happiness"), + ], + "All ignored files that were indexed are found" + ); + }); + + workspace + .update_in(cx, |workspace, window, cx| { + workspace.open_abs_path( + PathBuf::from(path!("/ancestor/tracked-root/heights/height_1")), + OpenOptions { + visible: Some(OpenVisible::None), + ..OpenOptions::default() + }, + window, + cx, + ) + }) + .await + .unwrap(); + workspace + .update_in(cx, |workspace, window, cx| { + workspace.active_pane().update(cx, |pane, cx| { + pane.close_active_item(&CloseActiveItem::default(), window, cx) + .unwrap() + }) + }) + .await + .unwrap(); + picker + .update_in(cx, |picker, window, cx| { + picker + .delegate + .spawn_search(test_path_position("hi"), window, cx) + }) + .await; + picker.update(cx, |picker, _| { + let matches = collect_search_matches(picker); + assert_eq!(matches.history.len(), 0); + assert_eq!( + matches.search, + vec![ + PathBuf::from("ignored-root/hi"), + PathBuf::from("tracked-root/hi"), + PathBuf::from("ignored-root/hiccup"), + PathBuf::from("tracked-root/hiccup"), + PathBuf::from("ignored-root/height"), + PathBuf::from("tracked-root/height"), + PathBuf::from("tracked-root/heights/height_1"), + PathBuf::from("tracked-root/heights/height_2"), + PathBuf::from("ignored-root/happiness"), + PathBuf::from("tracked-root/happiness"), + ], + "All ignored files that were indexed are found" + ); + }); } #[gpui::test]