Omit gitignored files from context file picker (#23777)

João Marcos created

In both `thread` and `prompt editor` the context file picker, gitignored
files are hidden (as expected) when searching files by path, but they
are still shown initially as you create the file picker.

Plus, selecting gitignored files in the `prompt editor` is bugged and
collapses everything.

This PR settles on not showing gitignored files to solve these
inconsistencies.

Release Notes:

- Fix gitignored files filter occasionally not working in context file
picker.

Change summary

Cargo.lock                                                  |  1 
crates/assistant2/src/context_picker/file_context_picker.rs |  2 
crates/assistant_slash_commands/Cargo.toml                  |  1 
crates/assistant_slash_commands/src/file_command.rs         |  9 ++
crates/worktree/src/worktree.rs                             | 25 ++++++
5 files changed, 33 insertions(+), 5 deletions(-)

Detailed changes

Cargo.lock 🔗

@@ -637,6 +637,7 @@ dependencies = [
  "ui",
  "util",
  "workspace",
+ "worktree",
 ]
 
 [[package]]

crates/assistant2/src/context_picker/file_context_picker.rs 🔗

@@ -124,7 +124,7 @@ impl FileContextPickerDelegate {
             let file_matches = project.worktrees(cx).flat_map(|worktree| {
                 let worktree = worktree.read(cx);
                 let path_prefix: Arc<str> = worktree.root_name().into();
-                worktree.files(true, 0).map(move |entry| PathMatch {
+                worktree.files(false, 0).map(move |entry| PathMatch {
                     score: 0.,
                     positions: Vec::new(),
                     worktree_id: worktree.id().to_usize(),

crates/assistant_slash_commands/Cargo.toml 🔗

@@ -45,6 +45,7 @@ toml.workspace = true
 ui.workspace = true
 util.workspace = true
 workspace.workspace = true
+worktree.workspace = true
 
 [dev-dependencies]
 env_logger.workspace = true

crates/assistant_slash_commands/src/file_command.rs 🔗

@@ -20,6 +20,7 @@ use std::{
 use ui::prelude::*;
 use util::ResultExt;
 use workspace::Workspace;
+use worktree::ChildEntriesOptions;
 
 pub struct FileSlashCommand;
 
@@ -42,7 +43,13 @@ impl FileSlashCommand {
                 .chain(project.worktrees(cx).flat_map(|worktree| {
                     let worktree = worktree.read(cx);
                     let id = worktree.id();
-                    worktree.child_entries(Path::new("")).map(move |entry| {
+                    let options = ChildEntriesOptions {
+                        include_files: true,
+                        include_dirs: true,
+                        include_ignored: false,
+                    };
+                    let entries = worktree.child_entries_with_options(Path::new(""), options);
+                    entries.map(move |entry| {
                         (
                             project::ProjectPath {
                                 worktree_id: id,

crates/worktree/src/worktree.rs 🔗

@@ -2724,14 +2724,27 @@ impl Snapshot {
     }
 
     pub fn child_entries<'a>(&'a self, parent_path: &'a Path) -> ChildEntriesIter<'a> {
+        let options = ChildEntriesOptions {
+            include_files: true,
+            include_dirs: true,
+            include_ignored: true,
+        };
+        self.child_entries_with_options(parent_path, options)
+    }
+
+    pub fn child_entries_with_options<'a>(
+        &'a self,
+        parent_path: &'a Path,
+        options: ChildEntriesOptions,
+    ) -> ChildEntriesIter<'a> {
         let mut cursor = self.entries_by_path.cursor(&());
         cursor.seek(&TraversalTarget::path(parent_path), Bias::Right, &());
         let traversal = Traversal {
             snapshot: self,
             cursor,
-            include_files: true,
-            include_dirs: true,
-            include_ignored: true,
+            include_files: options.include_files,
+            include_dirs: options.include_dirs,
+            include_ignored: options.include_ignored,
         };
         ChildEntriesIter {
             traversal,
@@ -6054,6 +6067,12 @@ impl<'a, 'b> SeekTarget<'a, PathSummary<Unit>, TraversalProgress<'a>> for Traver
     }
 }
 
+pub struct ChildEntriesOptions {
+    pub include_files: bool,
+    pub include_dirs: bool,
+    pub include_ignored: bool,
+}
+
 pub struct ChildEntriesIter<'a> {
     parent_path: &'a Path,
     traversal: Traversal<'a>,