file_finder: Prioritize file name matches over path matches (#27937)
Closes https://github.com/zed-industries/zed/issues/27936 Adds additional comparison after the existing history-based comparison. This comparison checks whether the first position matched via fuzzy search is in the file name. If so, we prioritize this match over one in the path. If both items match either the file name or the path, the existing comparison logic is used. - [x] Tests Before: <img width="580" alt="image" src="https://github.com/user-attachments/assets/011fdd01-3dfa-4950-abb1-dfda10885664" /> After: <img width="614" alt="image" src="https://github.com/user-attachments/assets/9c4944b0-83dc-4611-94bb-aae1758fab23" /> Release Notes: - Fixed an issue where fuzzy matching in file finder did not properly prioritize matches in file names.
This commit is contained in:
parent
45e7cd1638
commit
b2904e5d9f
2 changed files with 102 additions and 6 deletions
|
@ -2372,3 +2372,48 @@ fn assert_match_at_position(
|
|||
.to_string_lossy();
|
||||
assert_eq!(match_file_name, expected_file_name);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_filename_precedence(cx: &mut TestAppContext) {
|
||||
let app_state = init_test(cx);
|
||||
|
||||
app_state
|
||||
.fs
|
||||
.as_fake()
|
||||
.insert_tree(
|
||||
path!("/src"),
|
||||
json!({
|
||||
"layout": {
|
||||
"app.css": "",
|
||||
"app.d.ts": "",
|
||||
"app.html": "",
|
||||
"+page.svelte": "",
|
||||
},
|
||||
"routes": {
|
||||
"+layout.svelte": "",
|
||||
}
|
||||
}),
|
||||
)
|
||||
.await;
|
||||
|
||||
let project = Project::test(app_state.fs.clone(), [path!("/src").as_ref()], cx).await;
|
||||
let (picker, _, cx) = build_find_picker(project, cx);
|
||||
|
||||
cx.simulate_input("layout");
|
||||
|
||||
picker.update(cx, |finder, _| {
|
||||
let search_matches = collect_search_matches(finder).search_paths_only();
|
||||
|
||||
assert_eq!(
|
||||
search_matches,
|
||||
vec![
|
||||
PathBuf::from("routes/+layout.svelte"),
|
||||
PathBuf::from("layout/app.css"),
|
||||
PathBuf::from("layout/app.d.ts"),
|
||||
PathBuf::from("layout/app.html"),
|
||||
PathBuf::from("layout/+page.svelte"),
|
||||
],
|
||||
"File with 'layout' in filename should be prioritized over files in 'layout' directory"
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue