Skip to content

Commit acbe297

Browse files
committed
update relevance score u8 -> u32
1 parent 10fb065 commit acbe297

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

crates/ide_completion/src/item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl CompletionRelevance {
156156
///
157157
/// See is_relevant if you need to make some judgement about score
158158
/// in an absolute sense.
159-
pub fn score(&self) -> u8 {
159+
pub fn score(&self) -> u32 {
160160
let mut score = 0;
161161

162162
if self.exact_name_match {
@@ -525,7 +525,7 @@ mod tests {
525525
.map(|r| (r.score(), r))
526526
.sorted_by_key(|(score, _r)| *score)
527527
.fold(
528-
(u8::MIN, vec![vec![]]),
528+
(u32::MIN, vec![vec![]]),
529529
|(mut currently_collecting_score, mut out), (score, r)| {
530530
if currently_collecting_score == score {
531531
out.last_mut().unwrap().push(r);

crates/rust-analyzer/src/to_proto.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,12 @@ pub(crate) fn completion_item(
220220
}
221221
// The relevance needs to be inverted to come up with a sort score
222222
// because the client will sort ascending.
223-
let sort_score = relevance.score() ^ 0xFF;
224-
// Zero pad the string to ensure values are sorted numerically
225-
// even though the client is sorting alphabetically. Three
226-
// characters is enough to fit the largest u8, which is the
227-
// type of the relevance score.
228-
res.sort_text = Some(format!("{:03}", sort_score));
223+
let sort_score = relevance.score() ^ 0xFF_FF_FF_FF;
224+
// Zero pad the string to ensure values can be properly sorted
225+
// by the client. Hex format is used because it is easier to
226+
// visually compare very large values, which the sort text
227+
// tends to be since it is the opposite of the score.
228+
res.sort_text = Some(format!("{:08x}", sort_score));
229229
}
230230

231231
set_score(&mut lsp_item, item.relevance());
@@ -1117,13 +1117,13 @@ mod tests {
11171117
(
11181118
"&arg",
11191119
Some(
1120-
"253",
1120+
"fffffffd",
11211121
),
11221122
),
11231123
(
11241124
"arg",
11251125
Some(
1126-
"254",
1126+
"fffffffe",
11271127
),
11281128
),
11291129
]

0 commit comments

Comments
 (0)