editor: Prioritize fuzzy score over sort positions in code completion sort (#35229)

We already prioritize matches that come after separators like `_`: 


https://github.com/zed-industries/zed/blob/cef7d53607381975ea00d6302d8a9aab3c40eb1f/crates/fuzzy/src/matcher.rs#L274

and deprioritize non-consecutive matches using distance penalty:


https://github.com/zed-industries/zed/blob/cef7d53607381975ea00d6302d8a9aab3c40eb1f/crates/fuzzy/src/matcher.rs#L281

In completion sort, letting fuzzy score be the primary sort factor and
sort positions be secondary yields better results upon testing. We still
need sort positions because of this kind of test case:


https://github.com/zed-industries/zed/blob/cef7d53607381975ea00d6302d8a9aab3c40eb1f/crates/editor/src/code_completion_tests.rs#L195-L217

Before/After:

<img height="250" alt="image"
src="https://github.com/user-attachments/assets/38495576-add6-4435-93f0-891f48ec9263"
/>
<img height="250" alt="image"
src="https://github.com/user-attachments/assets/0c73b835-0e23-4e30-a3ff-28bb56294239"
/>


Release Notes:

- N/A
This commit is contained in:
Smit Barmase
2025-07-29 01:15:29 +05:30
committed by GitHub
parent b64977f6f4
commit cf13a76618
2 changed files with 25 additions and 3 deletions
+2 -2
View File
@@ -1057,9 +1057,9 @@ impl CompletionsMenu {
enum MatchTier<'a> {
WordStartMatch {
sort_exact: Reverse<i32>,
sort_positions: Vec<usize>,
sort_snippet: Reverse<i32>,
sort_score: Reverse<OrderedFloat<f64>>,
sort_positions: Vec<usize>,
sort_text: Option<&'a str>,
sort_kind: usize,
sort_label: &'a str,
@@ -1137,9 +1137,9 @@ impl CompletionsMenu {
MatchTier::WordStartMatch {
sort_exact,
sort_positions,
sort_snippet,
sort_score,
sort_positions,
sort_text,
sort_kind,
sort_label,