From 877ae381a2796fca6714ccfe4f90c91be8db31e1 Mon Sep 17 00:00:00 2001 From: Finn Eitreim <48069764+feitreim@users.noreply.github.com> Date: Fri, 12 Jun 2026 15:48:37 -0400 Subject: [PATCH 1/5] tail proximity bonus to reward better matches --- crates/fuzzy_nucleo/src/paths.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/fuzzy_nucleo/src/paths.rs b/crates/fuzzy_nucleo/src/paths.rs index 6aaabfeb50ecb4..8d0832eb6b7927 100644 --- a/crates/fuzzy_nucleo/src/paths.rs +++ b/crates/fuzzy_nucleo/src/paths.rs @@ -134,6 +134,15 @@ fn get_filename_match_bonus( score as f64 / filename.len().max(1) as f64 } +pub const TAIL_REWARD_SCALE: f64 = 1.5; + +#[inline] +fn get_tail_proximity_bonus(matched_chars: &[u32], haystack_len: u32) -> f64 { + let trailing: u32 = matched_chars.iter().map(|&i| haystack_len - 1 - i).sum(); + let mean_trailing = trailing as f64 / matched_chars.len() as f64; + (1.0 / (1.0 + mean_trailing)) * TAIL_REWARD_SCALE +} + fn path_match_helper<'a>( matcher: &mut nucleo::Matcher, query: &Query, @@ -193,7 +202,9 @@ fn path_match_helper<'a>( let length_penalty = candidate_buf.len() as f64 * LENGTH_PENALTY; let filename_bonus = get_filename_match_bonus(&candidate_buf, &query.pattern, matcher); - let positive = (score as f64 + filename_bonus) * case_penalty(case_mismatches); + let tail_proximity_bonus = + get_tail_proximity_bonus(&matched_chars, candidate_buf.len() as u32); + let positive = (score as f64 + filename_bonus + tail_proximity_bonus) * case_penalty(case_mismatches); let adjusted_score = positive - length_penalty; let positions = positions_from_sorted(&candidate_buf, &matched_chars); From bf0dd5e0c2678c933ac2e54c527789838ebad69c Mon Sep 17 00:00:00 2001 From: Finn Eitreim <48069764+feitreim@users.noreply.github.com> Date: Fri, 12 Jun 2026 16:08:34 -0400 Subject: [PATCH 2/5] fmt --- crates/fuzzy_nucleo/src/paths.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/fuzzy_nucleo/src/paths.rs b/crates/fuzzy_nucleo/src/paths.rs index 8d0832eb6b7927..d258b570462ae7 100644 --- a/crates/fuzzy_nucleo/src/paths.rs +++ b/crates/fuzzy_nucleo/src/paths.rs @@ -204,7 +204,8 @@ fn path_match_helper<'a>( let filename_bonus = get_filename_match_bonus(&candidate_buf, &query.pattern, matcher); let tail_proximity_bonus = get_tail_proximity_bonus(&matched_chars, candidate_buf.len() as u32); - let positive = (score as f64 + filename_bonus + tail_proximity_bonus) * case_penalty(case_mismatches); + let positive = + (score as f64 + filename_bonus + tail_proximity_bonus) * case_penalty(case_mismatches); let adjusted_score = positive - length_penalty; let positions = positions_from_sorted(&candidate_buf, &matched_chars); From 17c1133f9d1133ce8e1df01f3a4c456625880606 Mon Sep 17 00:00:00 2001 From: Finn Eitreim <48069764+feitreim@users.noreply.github.com> Date: Fri, 12 Jun 2026 16:56:46 -0400 Subject: [PATCH 3/5] tweaks --- crates/fuzzy_nucleo/src/paths.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/fuzzy_nucleo/src/paths.rs b/crates/fuzzy_nucleo/src/paths.rs index d258b570462ae7..d59ec3ff2996cb 100644 --- a/crates/fuzzy_nucleo/src/paths.rs +++ b/crates/fuzzy_nucleo/src/paths.rs @@ -134,10 +134,14 @@ fn get_filename_match_bonus( score as f64 / filename.len().max(1) as f64 } -pub const TAIL_REWARD_SCALE: f64 = 1.5; +const TAIL_REWARD_SCALE: f64 = 1.5; #[inline] fn get_tail_proximity_bonus(matched_chars: &[u32], haystack_len: u32) -> f64 { + debug_assert!( + haystack_len != 0 && matched_chars.len() != 0, + "This should only be called on a successful match." + ); let trailing: u32 = matched_chars.iter().map(|&i| haystack_len - 1 - i).sum(); let mean_trailing = trailing as f64 / matched_chars.len() as f64; (1.0 / (1.0 + mean_trailing)) * TAIL_REWARD_SCALE @@ -202,8 +206,7 @@ fn path_match_helper<'a>( let length_penalty = candidate_buf.len() as f64 * LENGTH_PENALTY; let filename_bonus = get_filename_match_bonus(&candidate_buf, &query.pattern, matcher); - let tail_proximity_bonus = - get_tail_proximity_bonus(&matched_chars, candidate_buf.len() as u32); + let tail_proximity_bonus = get_tail_proximity_bonus(&matched_chars, haystack.len() as u32); let positive = (score as f64 + filename_bonus + tail_proximity_bonus) * case_penalty(case_mismatches); let adjusted_score = positive - length_penalty; From 4c55dda23ec2e1fda44caad2115ee0a8281368fc Mon Sep 17 00:00:00 2001 From: Finn Eitreim <48069764+feitreim@users.noreply.github.com> Date: Mon, 15 Jun 2026 17:09:45 -0400 Subject: [PATCH 4/5] add test --- crates/file_finder/src/file_finder_tests.rs | 49 +++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/crates/file_finder/src/file_finder_tests.rs b/crates/file_finder/src/file_finder_tests.rs index 726251e9dee876..9c6afb609474b6 100644 --- a/crates/file_finder/src/file_finder_tests.rs +++ b/crates/file_finder/src/file_finder_tests.rs @@ -447,6 +447,55 @@ async fn test_complex_path(cx: &mut TestAppContext) { }); } +#[gpui::test] +async fn test_tail_proximity_bonus_prefers_shallow_cargo_toml(cx: &mut TestAppContext) { + let app_state = init_test(cx); + + cx.update(|cx| { + let settings = *ProjectPanelSettings::get_global(cx); + ProjectPanelSettings::override_global( + ProjectPanelSettings { + hide_root: true, + ..settings + }, + cx, + ); + }); + + app_state + .fs + .as_fake() + .insert_tree( + path!("/root"), + json!({ + "zzz": { "zed": { "Cargo.toml": "" } }, + "zed": { "zzz": { "Cargo.toml": "" } }, + }), + ) + .await; + + let project = Project::test(app_state.fs.clone(), [path!("/root").as_ref()], cx).await; + let (picker, _, cx) = build_find_picker(project, cx); + + picker + .update_in(cx, |picker, window, cx| { + picker + .delegate + .update_matches("zed cargo".to_string(), window, cx) + }) + .await; + + picker.update(cx, |picker, _| { + assert_eq!( + collect_search_matches(picker).search_paths_only(), + vec![ + rel_path("zzz/zed/Cargo.toml").into(), + rel_path("zed/zzz/Cargo.toml").into(), + ], + ); + }); +} + #[gpui::test] async fn test_row_column_numbers_query_inside_file(cx: &mut TestAppContext) { let app_state = init_test(cx); From 3b0a5849ce9a880329ae24e891973721dc6cad8b Mon Sep 17 00:00:00 2001 From: Finn Eitreim <48069764+feitreim@users.noreply.github.com> Date: Mon, 15 Jun 2026 18:21:50 -0400 Subject: [PATCH 5/5] . --- crates/file_finder/src/file_finder_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/file_finder/src/file_finder_tests.rs b/crates/file_finder/src/file_finder_tests.rs index 9c6afb609474b6..ea025a8c277293 100644 --- a/crates/file_finder/src/file_finder_tests.rs +++ b/crates/file_finder/src/file_finder_tests.rs @@ -448,7 +448,7 @@ async fn test_complex_path(cx: &mut TestAppContext) { } #[gpui::test] -async fn test_tail_proximity_bonus_prefers_shallow_cargo_toml(cx: &mut TestAppContext) { +async fn test_tail_proximity_bonus_prefers_later_match(cx: &mut TestAppContext) { let app_state = init_test(cx); cx.update(|cx| {