From 2b160f4f3cc7c5f7806545acb68884e475ca10a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Marcos?= Date: Tue, 28 Jan 2025 11:40:42 -0300 Subject: [PATCH] Omit gitignored files from context file picker (#23777) 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. --- Cargo.lock | 1 + .../src/context_picker/file_context_picker.rs | 2 +- crates/assistant_slash_commands/Cargo.toml | 1 + .../src/file_command.rs | 9 ++++++- crates/worktree/src/worktree.rs | 25 ++++++++++++++++--- 5 files changed, 33 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4d1d6a843b..d0ccc16795 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -637,6 +637,7 @@ dependencies = [ "ui", "util", "workspace", + "worktree", ] [[package]] diff --git a/crates/assistant2/src/context_picker/file_context_picker.rs b/crates/assistant2/src/context_picker/file_context_picker.rs index b68ae87145..757249dbea 100644 --- a/crates/assistant2/src/context_picker/file_context_picker.rs +++ b/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 = 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(), diff --git a/crates/assistant_slash_commands/Cargo.toml b/crates/assistant_slash_commands/Cargo.toml index 5987e85cad..25d762223d 100644 --- a/crates/assistant_slash_commands/Cargo.toml +++ b/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 diff --git a/crates/assistant_slash_commands/src/file_command.rs b/crates/assistant_slash_commands/src/file_command.rs index 10d1d88ae9..d898d82bc3 100644 --- a/crates/assistant_slash_commands/src/file_command.rs +++ b/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, diff --git a/crates/worktree/src/worktree.rs b/crates/worktree/src/worktree.rs index f8336484a3..9a3362bd46 100644 --- a/crates/worktree/src/worktree.rs +++ b/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, 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>,