mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-11 13:10:54 +00:00
fix infinite loop in path distance for fuzzy finder
This commit is contained in:
parent
81cbefec22
commit
b3dffeaf2a
1 changed files with 20 additions and 1 deletions
|
@ -198,6 +198,25 @@ fn distance_between_paths(path: &Path, relative_to: &Path) -> usize {
|
||||||
let mut path_components = path.components();
|
let mut path_components = path.components();
|
||||||
let mut relative_components = relative_to.components();
|
let mut relative_components = relative_to.components();
|
||||||
|
|
||||||
while path_components.next() == relative_components.next() {}
|
// while path_components.next() == relative_components.next() {}
|
||||||
|
|
||||||
|
while path_components
|
||||||
|
.next()
|
||||||
|
.zip(relative_components.next())
|
||||||
|
.map(|(path_component, relative_component)| path_component == relative_component)
|
||||||
|
.unwrap_or_default()
|
||||||
|
{}
|
||||||
path_components.count() + relative_components.count() + 1
|
path_components.count() + relative_components.count() + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
use super::distance_between_paths;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_distance_between_paths_empty() {
|
||||||
|
distance_between_paths(Path::new(""), Path::new(""));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue