Sort completions by relevance for strong matches (#20145)

Further enhancement:
On exploring VSCode's sorting logic, there are two major distinctions:
* A config option exists to adjust sort priority of snippets. They can
be placed inline (default), top or at bottom of completitions.
* The sorting order sorts by (in order): sort_text (lower case),
sort_text, kind

ref:
https://github.com/microsoft/vscode/blob/6f2d4781e857a550b7e9b05d40b969c840e264db/src/vs/editor/contrib/suggest/browser/suggest.ts#L338-L383

Closes #19786

Release Notes:

- Improved sort order in completions to show relevant matches first
([#19786](https://github.com/zed-industries/zed/issues/19786))
This commit is contained in:
Avinash Thakur
2024-11-04 22:23:36 +02:00
committed by GitHub
parent 8196db6022
commit c9ec235b12
2 changed files with 76 additions and 8 deletions
+8 -8
View File
@@ -1353,22 +1353,22 @@ impl CompletionsMenu {
// Strong matches are the ones with a high fuzzy-matcher score (the "obvious" matches)
// and the Weak matches are the rest.
//
// For the strong matches, we sort by the language-servers score first and for the weak
// matches, we prefer our fuzzy finder first.
// For the strong matches, we sort by our fuzzy-finder score first and for the weak
// matches, we prefer language-server sort_text first.
//
// The thinking behind that: it's useless to take the sort_text the language-server gives
// us into account when it's obviously a bad match.
// The thinking behind that: we want to show strong matches first in order of relevance(fuzzy score).
// Rest of the matches(weak) can be sorted as language-server expects.
#[derive(PartialEq, Eq, PartialOrd, Ord)]
enum MatchScore<'a> {
Strong {
sort_text: Option<&'a str>,
score: Reverse<OrderedFloat<f64>>,
sort_text: Option<&'a str>,
sort_key: (usize, &'a str),
},
Weak {
score: Reverse<OrderedFloat<f64>>,
sort_text: Option<&'a str>,
score: Reverse<OrderedFloat<f64>>,
sort_key: (usize, &'a str),
},
}
@@ -1380,14 +1380,14 @@ impl CompletionsMenu {
if mat.score >= 0.2 {
MatchScore::Strong {
sort_text,
score,
sort_text,
sort_key,
}
} else {
MatchScore::Weak {
score,
sort_text,
score,
sort_key,
}
}