assistant: Report all worktree entries in /file completions (#15617)

We were reporting file count as worktree entry count, which led to us
missing some of the entries in /file command completion.

/cc @bennetbo

The other components that used `PathMatchCandidateSet` are
`/diagnostics` and file finder. File finder is unaffected, as it used
`Candidates::Files` - thus previously reported count was correct for it;
`/diagnostics` were using `::Entries` as well, so it could miss entries
just like `/files`.

Release Notes:

- Fixed /file and /diagnostics slash commands omitting entries in it's
completions menu.
This commit is contained in:
Piotr Osiewicz 2024-08-01 16:09:53 +02:00 committed by GitHub
parent a9c6e435f7
commit ac1a15f5d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 42 additions and 4 deletions

View File

@ -10917,6 +10917,8 @@ impl<'a> fuzzy::PathMatchCandidateSet<'a> for PathMatchCandidateSet {
} }
fn len(&self) -> usize { fn len(&self) -> usize {
match self.candidates {
Candidates::Files => {
if self.include_ignored { if self.include_ignored {
self.snapshot.file_count() self.snapshot.file_count()
} else { } else {
@ -10924,6 +10926,24 @@ impl<'a> fuzzy::PathMatchCandidateSet<'a> for PathMatchCandidateSet {
} }
} }
Candidates::Directories => {
if self.include_ignored {
self.snapshot.dir_count()
} else {
self.snapshot.visible_dir_count()
}
}
Candidates::Entries => {
if self.include_ignored {
self.snapshot.entry_count()
} else {
self.snapshot.visible_entry_count()
}
}
}
}
fn prefix(&self) -> Arc<str> { fn prefix(&self) -> Arc<str> {
if self.snapshot.root_entry().map_or(false, |e| e.is_file()) { if self.snapshot.root_entry().map_or(false, |e| e.is_file()) {
self.snapshot.root_name().into() self.snapshot.root_name().into()

View File

@ -2118,6 +2118,24 @@ impl Snapshot {
Ok(()) Ok(())
} }
pub fn entry_count(&self) -> usize {
self.entries_by_path.summary().count
}
pub fn visible_entry_count(&self) -> usize {
self.entries_by_path.summary().non_ignored_count
}
pub fn dir_count(&self) -> usize {
let summary = self.entries_by_path.summary();
summary.count - summary.file_count
}
pub fn visible_dir_count(&self) -> usize {
let summary = self.entries_by_path.summary();
summary.non_ignored_count - summary.non_ignored_file_count
}
pub fn file_count(&self) -> usize { pub fn file_count(&self) -> usize {
self.entries_by_path.summary().file_count self.entries_by_path.summary().file_count
} }