editor: Improve fuzzy match bucket logic for code completions (#29442)
Add new test and improve fuzzy match bucket logic which results into far better balance between LSP and fuzzy search. Before: <img width="500" alt="before" src="https://github.com/user-attachments/assets/3e8900a6-c0ff-4f37-b88e-b0e3783b7e9a" /> After: <img width="500" alt="after" src="https://github.com/user-attachments/assets/738c074c-d446-4697-aac6-9814362e88db" /> Release Notes: - N/A
This commit is contained in:
parent
8b910e1cd9
commit
3961d87ae0
2 changed files with 160 additions and 7 deletions
|
@ -1006,3 +1006,152 @@ fn test_sort_matches_for_snippets(_cx: &mut TestAppContext) {
|
|||
"Match order not expected"
|
||||
);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_sort_matches_for_exact_match(_cx: &mut TestAppContext) {
|
||||
// Case 1: "set_text"
|
||||
let query: Option<&str> = Some("set_text");
|
||||
let mut matches: Vec<SortableMatch<'_>> = vec![
|
||||
SortableMatch {
|
||||
string_match: StringMatch {
|
||||
candidate_id: 0,
|
||||
score: 1.0,
|
||||
positions: vec![],
|
||||
string: "set_text".to_string(),
|
||||
},
|
||||
is_snippet: false,
|
||||
sort_text: Some("7fffffff"),
|
||||
sort_key: (3, "set_text"),
|
||||
},
|
||||
SortableMatch {
|
||||
string_match: StringMatch {
|
||||
candidate_id: 0,
|
||||
score: 0.32000000000000006,
|
||||
positions: vec![],
|
||||
string: "set_placeholder_text".to_string(),
|
||||
},
|
||||
is_snippet: false,
|
||||
sort_text: Some("7fffffff"),
|
||||
sort_key: (3, "set_placeholder_text"),
|
||||
},
|
||||
SortableMatch {
|
||||
string_match: StringMatch {
|
||||
candidate_id: 0,
|
||||
score: 0.32,
|
||||
positions: vec![],
|
||||
string: "set_text_style_refinement".to_string(),
|
||||
},
|
||||
is_snippet: false,
|
||||
sort_text: Some("7fffffff"),
|
||||
sort_key: (3, "set_text_style_refinement"),
|
||||
},
|
||||
SortableMatch {
|
||||
string_match: StringMatch {
|
||||
candidate_id: 0,
|
||||
score: 0.16666666666666666,
|
||||
positions: vec![],
|
||||
string: "set_context_menu_options".to_string(),
|
||||
},
|
||||
is_snippet: false,
|
||||
sort_text: Some("7fffffff"),
|
||||
sort_key: (3, "set_context_menu_options"),
|
||||
},
|
||||
SortableMatch {
|
||||
string_match: StringMatch {
|
||||
candidate_id: 0,
|
||||
score: 0.08695652173913043,
|
||||
positions: vec![],
|
||||
string: "select_to_next_word_end".to_string(),
|
||||
},
|
||||
is_snippet: false,
|
||||
sort_text: Some("7fffffff"),
|
||||
sort_key: (3, "select_to_next_word_end"),
|
||||
},
|
||||
SortableMatch {
|
||||
string_match: StringMatch {
|
||||
candidate_id: 0,
|
||||
score: 0.07692307692307693,
|
||||
positions: vec![],
|
||||
string: "select_to_next_subword_end".to_string(),
|
||||
},
|
||||
is_snippet: false,
|
||||
sort_text: Some("7fffffff"),
|
||||
sort_key: (3, "select_to_next_subword_end"),
|
||||
},
|
||||
SortableMatch {
|
||||
string_match: StringMatch {
|
||||
candidate_id: 0,
|
||||
score: 0.06956521739130435,
|
||||
positions: vec![],
|
||||
string: "set_custom_context_menu".to_string(),
|
||||
},
|
||||
is_snippet: false,
|
||||
sort_text: Some("7fffffff"),
|
||||
sort_key: (3, "set_custom_context_menu"),
|
||||
},
|
||||
SortableMatch {
|
||||
string_match: StringMatch {
|
||||
candidate_id: 0,
|
||||
score: 0.06,
|
||||
positions: vec![],
|
||||
string: "select_to_end_of_excerpt".to_string(),
|
||||
},
|
||||
is_snippet: false,
|
||||
sort_text: Some("7fffffff"),
|
||||
sort_key: (3, "select_to_end_of_excerpt"),
|
||||
},
|
||||
SortableMatch {
|
||||
string_match: StringMatch {
|
||||
candidate_id: 0,
|
||||
score: 0.055384615384615386,
|
||||
positions: vec![],
|
||||
string: "select_to_start_of_excerpt".to_string(),
|
||||
},
|
||||
is_snippet: false,
|
||||
sort_text: Some("7fffffff"),
|
||||
sort_key: (3, "select_to_start_of_excerpt"),
|
||||
},
|
||||
SortableMatch {
|
||||
string_match: StringMatch {
|
||||
candidate_id: 0,
|
||||
score: 0.0464516129032258,
|
||||
positions: vec![],
|
||||
string: "select_to_start_of_next_excerpt".to_string(),
|
||||
},
|
||||
is_snippet: false,
|
||||
sort_text: Some("7fffffff"),
|
||||
sort_key: (3, "select_to_start_of_next_excerpt"),
|
||||
},
|
||||
SortableMatch {
|
||||
string_match: StringMatch {
|
||||
candidate_id: 0,
|
||||
score: 0.04363636363636363,
|
||||
positions: vec![],
|
||||
string: "select_to_end_of_previous_excerpt".to_string(),
|
||||
},
|
||||
is_snippet: false,
|
||||
sort_text: Some("7fffffff"),
|
||||
sort_key: (3, "select_to_end_of_previous_excerpt"),
|
||||
},
|
||||
];
|
||||
CompletionsMenu::sort_matches(&mut matches, query, SnippetSortOrder::Top);
|
||||
assert_eq!(
|
||||
matches
|
||||
.iter()
|
||||
.map(|m| m.string_match.string.as_str())
|
||||
.collect::<Vec<&str>>(),
|
||||
vec![
|
||||
"set_text",
|
||||
"set_context_menu_options",
|
||||
"set_placeholder_text",
|
||||
"set_text_style_refinement",
|
||||
"select_to_end_of_excerpt",
|
||||
"select_to_end_of_previous_excerpt",
|
||||
"select_to_next_subword_end",
|
||||
"select_to_next_word_end",
|
||||
"select_to_start_of_excerpt",
|
||||
"select_to_start_of_next_excerpt",
|
||||
"set_custom_context_menu"
|
||||
]
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue