Fix panic when fuzzy-matching on a Worktree that contains no files

As part of our work on the deterministic executor, in c4e37dc we fixed a
bug that occurred when there were more CPUs than paths to fuzzy-match
on.

However, that introduced another bug that caused Zed to panic when
trying to calculate how many paths should be fuzzy-matched by each
available worker thread for worktrees that didn't contain any file.

This commit bails out early in `fuzzy::match_paths` if the vector of
paths to search is empty.
This commit is contained in:
Antonio Scandurra
2021-07-30 09:50:02 -07:00
committed by Max Brunsfeld
parent dd6820e714
commit 8de8c679c7
2 changed files with 58 additions and 6 deletions
+49
View File
@@ -2641,6 +2641,55 @@ mod tests {
);
}
#[gpui::test]
async fn test_search_worktree_without_files(cx: gpui::TestAppContext) {
let dir = temp_tree(json!({
"root": {
"dir1": {},
"dir2": {
"dir3": {}
}
}
}));
let tree = Worktree::open_local(
dir.path(),
Default::default(),
Arc::new(RealFs),
&mut cx.to_async(),
)
.await
.unwrap();
cx.read(|cx| tree.read(cx).as_local().unwrap().scan_complete())
.await;
let snapshot = cx.read(|cx| {
let tree = tree.read(cx);
assert_eq!(tree.file_count(), 0);
tree.snapshot()
});
let results = cx
.read(|cx| {
match_paths(
Some(&snapshot).into_iter(),
"dir",
false,
false,
false,
10,
Default::default(),
cx.background().clone(),
)
})
.await;
assert_eq!(
results
.into_iter()
.map(|result| result.path)
.collect::<Vec<Arc<Path>>>(),
vec![]
);
}
#[gpui::test]
async fn test_save_file(mut cx: gpui::TestAppContext) {
let app_state = cx.read(build_app_state);