Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions crates/project/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use futures::{
stream::FuturesUnordered,
AsyncWriteExt, Future, FutureExt, StreamExt,
};
use fuzzy::CharBag;

use git::{blame::Blame, repository::GitRepository};
use globset::{Glob, GlobSet, GlobSetBuilder};
use gpui::{
Expand Down Expand Up @@ -11030,19 +11030,13 @@ impl<'a> Iterator for PathMatchCandidateSetIter<'a> {
type Item = fuzzy::PathMatchCandidate<'a>;

fn next(&mut self) -> Option<Self::Item> {
self.traversal.next().map(|entry| match entry.kind {
EntryKind::Dir => fuzzy::PathMatchCandidate {
is_dir: true,
path: &entry.path,
char_bag: CharBag::from_iter(entry.path.to_string_lossy().to_lowercase().chars()),
},
EntryKind::File(char_bag) => fuzzy::PathMatchCandidate {
is_dir: false,
self.traversal
.next()
.map(|entry| fuzzy::PathMatchCandidate {
is_dir: entry.kind.is_dir(),
path: &entry.path,
char_bag,
},
EntryKind::UnloadedDir | EntryKind::PendingDir => unreachable!(),
})
char_bag: entry.char_bag,
})
}
}

Expand Down
5 changes: 3 additions & 2 deletions crates/project_panel/src/project_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1612,7 +1612,7 @@ impl ProjectPanel {
new_entry_kind = if edit_state.is_dir {
EntryKind::Dir
} else {
EntryKind::File(Default::default())
EntryKind::File
};
}
}
Expand Down Expand Up @@ -1652,6 +1652,7 @@ impl ProjectPanel {
git_status: entry.git_status,
canonical_path: entry.canonical_path.clone(),
is_symlink: entry.is_symlink,
char_bag: entry.char_bag,
});
}
if expanded_dir_ids.binary_search(&entry.id).is_err()
Expand Down Expand Up @@ -1875,7 +1876,7 @@ impl ProjectPanel {
let status = git_status_setting.then(|| entry.git_status).flatten();
let is_expanded = expanded_entry_ids.binary_search(&entry.id).is_ok();
let icon = match entry.kind {
EntryKind::File(_) => {
EntryKind::File => {
if show_file_icons {
FileIcons::get_icon(&entry.path, cx)
} else {
Expand Down
15 changes: 9 additions & 6 deletions crates/worktree/src/worktree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3164,14 +3164,15 @@ pub struct Entry {
pub git_status: Option<GitFileStatus>,
/// Whether this entry is considered to be a `.env` file.
pub is_private: bool,
pub char_bag: CharBag,
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum EntryKind {
UnloadedDir,
PendingDir,
Dir,
File(CharBag),
File,
}

#[derive(Clone, Copy, Debug, PartialEq)]
Expand Down Expand Up @@ -3206,12 +3207,13 @@ impl Entry {
root_char_bag: CharBag,
canonical_path: Option<Box<Path>>,
) -> Self {
let char_bag = char_bag_for_path(root_char_bag, &path);
Self {
id: ProjectEntryId::new(next_entry_id),
kind: if metadata.is_dir {
EntryKind::PendingDir
} else {
EntryKind::File(char_bag_for_path(root_char_bag, &path))
EntryKind::File
},
path,
inode: metadata.inode,
Expand All @@ -3222,6 +3224,7 @@ impl Entry {
is_external: false,
is_private: false,
git_status: None,
char_bag,
}
}

Expand Down Expand Up @@ -3255,7 +3258,7 @@ impl EntryKind {
}

pub fn is_file(&self) -> bool {
matches!(self, EntryKind::File(_))
matches!(self, EntryKind::File)
}
}

Expand Down Expand Up @@ -5093,11 +5096,10 @@ impl<'a> TryFrom<(&'a CharBag, proto::Entry)> for Entry {
let kind = if entry.is_dir {
EntryKind::Dir
} else {
let mut char_bag = *root_char_bag;
char_bag.extend(entry.path.chars().map(|c| c.to_ascii_lowercase()));
EntryKind::File(char_bag)
EntryKind::File
};
let path: Arc<Path> = PathBuf::from(entry.path).into();
let char_bag = char_bag_for_path(*root_char_bag, &path);
Ok(Entry {
id: ProjectEntryId::from_proto(entry.id),
kind,
Expand All @@ -5110,6 +5112,7 @@ impl<'a> TryFrom<(&'a CharBag, proto::Entry)> for Entry {
git_status: git_status_from_proto(entry.git_status),
is_private: false,
is_symlink: entry.is_symlink,
char_bag,
})
}
}
Expand Down
Loading