Fix a bug where directories were not matching in the fuzzy matcher, when query contains the worktree root name (#16242)

Release Notes:

- N/A

Co-authored-by: Max <max@zed.dev>
This commit is contained in:
Mikayla Maki 2024-08-14 12:43:00 -07:00 committed by GitHub
parent e8bae839ed
commit 271e774713
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 21 deletions

View File

@ -32,7 +32,7 @@ use futures::{
stream::FuturesUnordered, stream::FuturesUnordered,
AsyncWriteExt, Future, FutureExt, StreamExt, AsyncWriteExt, Future, FutureExt, StreamExt,
}; };
use fuzzy::CharBag;
use git::{blame::Blame, repository::GitRepository}; use git::{blame::Blame, repository::GitRepository};
use globset::{Glob, GlobSet, GlobSetBuilder}; use globset::{Glob, GlobSet, GlobSetBuilder};
use gpui::{ use gpui::{
@ -11030,19 +11030,13 @@ impl<'a> Iterator for PathMatchCandidateSetIter<'a> {
type Item = fuzzy::PathMatchCandidate<'a>; type Item = fuzzy::PathMatchCandidate<'a>;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
self.traversal.next().map(|entry| match entry.kind { self.traversal
EntryKind::Dir => fuzzy::PathMatchCandidate { .next()
is_dir: true, .map(|entry| fuzzy::PathMatchCandidate {
is_dir: entry.kind.is_dir(),
path: &entry.path, path: &entry.path,
char_bag: CharBag::from_iter(entry.path.to_string_lossy().to_lowercase().chars()), char_bag: entry.char_bag,
}, })
EntryKind::File(char_bag) => fuzzy::PathMatchCandidate {
is_dir: false,
path: &entry.path,
char_bag,
},
EntryKind::UnloadedDir | EntryKind::PendingDir => unreachable!(),
})
} }
} }

View File

@ -1612,7 +1612,7 @@ impl ProjectPanel {
new_entry_kind = if edit_state.is_dir { new_entry_kind = if edit_state.is_dir {
EntryKind::Dir EntryKind::Dir
} else { } else {
EntryKind::File(Default::default()) EntryKind::File
}; };
} }
} }
@ -1652,6 +1652,7 @@ impl ProjectPanel {
git_status: entry.git_status, git_status: entry.git_status,
canonical_path: entry.canonical_path.clone(), canonical_path: entry.canonical_path.clone(),
is_symlink: entry.is_symlink, is_symlink: entry.is_symlink,
char_bag: entry.char_bag,
}); });
} }
if expanded_dir_ids.binary_search(&entry.id).is_err() if expanded_dir_ids.binary_search(&entry.id).is_err()
@ -1875,7 +1876,7 @@ impl ProjectPanel {
let status = git_status_setting.then(|| entry.git_status).flatten(); let status = git_status_setting.then(|| entry.git_status).flatten();
let is_expanded = expanded_entry_ids.binary_search(&entry.id).is_ok(); let is_expanded = expanded_entry_ids.binary_search(&entry.id).is_ok();
let icon = match entry.kind { let icon = match entry.kind {
EntryKind::File(_) => { EntryKind::File => {
if show_file_icons { if show_file_icons {
FileIcons::get_icon(&entry.path, cx) FileIcons::get_icon(&entry.path, cx)
} else { } else {

View File

@ -3164,6 +3164,7 @@ pub struct Entry {
pub git_status: Option<GitFileStatus>, pub git_status: Option<GitFileStatus>,
/// Whether this entry is considered to be a `.env` file. /// Whether this entry is considered to be a `.env` file.
pub is_private: bool, pub is_private: bool,
pub char_bag: CharBag,
} }
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
@ -3171,7 +3172,7 @@ pub enum EntryKind {
UnloadedDir, UnloadedDir,
PendingDir, PendingDir,
Dir, Dir,
File(CharBag), File,
} }
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, PartialEq)]
@ -3206,12 +3207,13 @@ impl Entry {
root_char_bag: CharBag, root_char_bag: CharBag,
canonical_path: Option<Box<Path>>, canonical_path: Option<Box<Path>>,
) -> Self { ) -> Self {
let char_bag = char_bag_for_path(root_char_bag, &path);
Self { Self {
id: ProjectEntryId::new(next_entry_id), id: ProjectEntryId::new(next_entry_id),
kind: if metadata.is_dir { kind: if metadata.is_dir {
EntryKind::PendingDir EntryKind::PendingDir
} else { } else {
EntryKind::File(char_bag_for_path(root_char_bag, &path)) EntryKind::File
}, },
path, path,
inode: metadata.inode, inode: metadata.inode,
@ -3222,6 +3224,7 @@ impl Entry {
is_external: false, is_external: false,
is_private: false, is_private: false,
git_status: None, git_status: None,
char_bag,
} }
} }
@ -3255,7 +3258,7 @@ impl EntryKind {
} }
pub fn is_file(&self) -> bool { pub fn is_file(&self) -> bool {
matches!(self, EntryKind::File(_)) matches!(self, EntryKind::File)
} }
} }
@ -5093,11 +5096,10 @@ impl<'a> TryFrom<(&'a CharBag, proto::Entry)> for Entry {
let kind = if entry.is_dir { let kind = if entry.is_dir {
EntryKind::Dir EntryKind::Dir
} else { } else {
let mut char_bag = *root_char_bag; EntryKind::File
char_bag.extend(entry.path.chars().map(|c| c.to_ascii_lowercase()));
EntryKind::File(char_bag)
}; };
let path: Arc<Path> = PathBuf::from(entry.path).into(); let path: Arc<Path> = PathBuf::from(entry.path).into();
let char_bag = char_bag_for_path(*root_char_bag, &path);
Ok(Entry { Ok(Entry {
id: ProjectEntryId::from_proto(entry.id), id: ProjectEntryId::from_proto(entry.id),
kind, kind,
@ -5110,6 +5112,7 @@ impl<'a> TryFrom<(&'a CharBag, proto::Entry)> for Entry {
git_status: git_status_from_proto(entry.git_status), git_status: git_status_from_proto(entry.git_status),
is_private: false, is_private: false,
is_symlink: entry.is_symlink, is_symlink: entry.is_symlink,
char_bag,
}) })
} }
} }