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.
This commit is contained in:
João Marcos 2025-01-28 11:40:42 -03:00 committed by GitHub
parent a5957bfaeb
commit 2b160f4f3c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 33 additions and 5 deletions

1
Cargo.lock generated
View file

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

View file

@ -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(),

View file

@ -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

View file

@ -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,

View file

@ -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>,