diff --git a/crates/file_finder/src/file_finder.rs b/crates/file_finder/src/file_finder.rs index 931561ac7315cf..984cf953f66cde 100644 --- a/crates/file_finder/src/file_finder.rs +++ b/crates/file_finder/src/file_finder.rs @@ -1484,10 +1484,12 @@ impl<'a> PathComponentSlice<'a> { let mut len_with_elision = self.path_str.len(); let mut i = eligible_range.start; while i < eligible_range.end { - if pick_from_end { - i = eligible_range.end - i + eligible_range.start - 1; - } - len_with_elision -= self.component_ranges[i] + let x = if pick_from_end { + eligible_range.end - i + eligible_range.start - 1 + } else { + i + }; + len_with_elision -= self.component_ranges[x] .0 .as_os_str() .as_encoded_bytes() @@ -1501,9 +1503,11 @@ impl<'a> PathComponentSlice<'a> { if len_with_elision > budget { return None; } else if pick_from_end { - i..eligible_range.end + let x = eligible_range.end - i + eligible_range.start - 1; + x..eligible_range.end } else { - eligible_range.start..i + 1 + let x = i; + eligible_range.start..x + 1 } }; diff --git a/crates/file_finder/src/file_finder_tests.rs b/crates/file_finder/src/file_finder_tests.rs index 9efd5418dbe426..f54150df4bcb4e 100644 --- a/crates/file_finder/src/file_finder_tests.rs +++ b/crates/file_finder/src/file_finder_tests.rs @@ -19,31 +19,30 @@ fn init_logger() { #[test] fn test_path_component_slice() { #[track_caller] - fn check(path: &str, matches: impl IntoIterator, expected: &str) { + fn check(path: &str, budget: usize, matches: impl IntoIterator, expected: &str) { let mut path = path.to_owned(); let slice = PathComponentSlice::new(&path); let matches = Vec::from_iter(matches); - // FIXME make it work again - if let Some(range) = slice.elision_range(0, &matches) { + if let Some(range) = slice.elision_range(budget - 1, &matches) { path.replace_range(range, "…"); } assert_eq!(path, expected); } - check("p/a/b/c/d/", [], "p/…/d/"); - check("p/a/b/c/d/", [2, 4, 6], "p/a/b/c/d/"); - check("p/a/b/c/d/", [2, 6], "p/a/…/c/d/"); - check("p/a/b/c/d/", [6], "p/…/c/d/"); + check("p/a/b/c/d/", 6, [], "p/…/d/"); + check("p/a/b/c/d/", 1, [2, 4, 6], "p/a/b/c/d/"); + check("p/a/b/c/d/", 10, [2, 6], "p/a/…/c/d/"); + check("p/a/b/c/d/", 8, [6], "p/…/c/d/"); - check("p/a/b/c/d", [], "p/…/d"); - check("p/a/b/c/d", [2, 4, 6], "p/a/b/c/d"); - check("p/a/b/c/d", [2, 6], "p/a/…/c/d"); - check("p/a/b/c/d", [6], "p/…/c/d"); + check("p/a/b/c/d", 5, [], "p/…/d"); + check("p/a/b/c/d", 9, [2, 4, 6], "p/a/b/c/d"); + check("p/a/b/c/d", 9, [2, 6], "p/a/…/c/d"); + check("p/a/b/c/d", 7, [6], "p/…/c/d"); - check("/p/a/b/c/d/", [], "/p/…/d/"); - check("/p/a/b/c/d/", [3, 5, 7], "/p/a/b/c/d/"); - check("/p/a/b/c/d/", [3, 7], "/p/a/…/c/d/"); - check("/p/a/b/c/d/", [7], "/p/…/c/d/"); + check("/p/a/b/c/d/", 7, [], "/p/…/d/"); + check("/p/a/b/c/d/", 11, [3, 5, 7], "/p/a/b/c/d/"); + check("/p/a/b/c/d/", 11, [3, 7], "/p/a/…/c/d/"); + check("/p/a/b/c/d/", 9, [7], "/p/…/c/d/"); } #[test]