Parse .//a//b/-prefixed paths more leniently in the file finder (#31459)

Closes https://github.com/zed-industries/zed/issues/15081
Closes https://github.com/zed-industries/zed/issues/31064

Release Notes:

- Parse `./`/`a/`/`b/`-prefixed paths more leniently in the file finder
This commit is contained in:
Kirill Bulatov 2025-05-26 23:38:12 +03:00 committed by GitHub
parent 5b320d6714
commit 6840a4e5bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 49 additions and 1 deletions

View file

@ -1170,6 +1170,48 @@ impl PickerDelegate for FileFinderDelegate {
) -> Task<()> {
let raw_query = raw_query.replace(' ', "");
let raw_query = raw_query.trim();
let raw_query = match &raw_query.get(0..2) {
Some(".\\") | Some("./") => &raw_query[2..],
Some("a\\") | Some("a/") => {
if self
.workspace
.upgrade()
.into_iter()
.flat_map(|workspace| workspace.read(cx).worktrees(cx))
.all(|worktree| {
worktree
.read(cx)
.entry_for_path(Path::new("a"))
.is_none_or(|entry| !entry.is_dir())
})
{
&raw_query[2..]
} else {
raw_query
}
}
Some("b\\") | Some("b/") => {
if self
.workspace
.upgrade()
.into_iter()
.flat_map(|workspace| workspace.read(cx).worktrees(cx))
.all(|worktree| {
worktree
.read(cx)
.entry_for_path(Path::new("b"))
.is_none_or(|entry| !entry.is_dir())
})
{
&raw_query[2..]
} else {
raw_query
}
}
_ => raw_query,
};
if raw_query.is_empty() {
// if there was no query before, and we already have some (history) matches
// there's no need to update anything, since nothing has changed.

View file

@ -206,6 +206,11 @@ async fn test_matching_paths(cx: &mut TestAppContext) {
for bandana_query in [
"bandana",
"./bandana",
".\\bandana",
util::separator!("a/bandana"),
"b/bandana",
"b\\bandana",
" bandana",
"bandana ",
" bandana ",
@ -224,7 +229,8 @@ async fn test_matching_paths(cx: &mut TestAppContext) {
assert_eq!(
picker.delegate.matches.len(),
1,
"Wrong number of matches for bandana query '{bandana_query}'"
"Wrong number of matches for bandana query '{bandana_query}'. Matches: {:?}",
picker.delegate.matches
);
});
cx.dispatch_action(SelectNext);