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-17 18:12:08 +02:00 committed by Max Brunsfeld
parent dd6820e714
commit 8de8c679c7
2 changed files with 58 additions and 6 deletions

View file

@ -64,6 +64,15 @@ pub async fn match_paths<'a, T>(
where
T: Clone + Send + Iterator<Item = &'a Snapshot> + 'a,
{
let path_count: usize = if include_ignored {
snapshots.clone().map(Snapshot::file_count).sum()
} else {
snapshots.clone().map(Snapshot::visible_file_count).sum()
};
if path_count == 0 {
return Vec::new();
}
let lowercase_query = query.to_lowercase().chars().collect::<Vec<_>>();
let query = query.chars().collect::<Vec<_>>();
@ -71,12 +80,6 @@ where
let query = &query;
let query_chars = CharBag::from(&lowercase_query[..]);
let path_count: usize = if include_ignored {
snapshots.clone().map(Snapshot::file_count).sum()
} else {
snapshots.clone().map(Snapshot::visible_file_count).sum()
};
let num_cpus = background.num_cpus().min(path_count);
let segment_size = (path_count + num_cpus - 1) / num_cpus;
let mut segment_results = (0..num_cpus)