mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
update relevance score u8 -> u32
This commit is contained in:
parent
10fb065b14
commit
acbe297fbd
2 changed files with 10 additions and 10 deletions
|
@ -156,7 +156,7 @@ impl CompletionRelevance {
|
||||||
///
|
///
|
||||||
/// See is_relevant if you need to make some judgement about score
|
/// See is_relevant if you need to make some judgement about score
|
||||||
/// in an absolute sense.
|
/// in an absolute sense.
|
||||||
pub fn score(&self) -> u8 {
|
pub fn score(&self) -> u32 {
|
||||||
let mut score = 0;
|
let mut score = 0;
|
||||||
|
|
||||||
if self.exact_name_match {
|
if self.exact_name_match {
|
||||||
|
@ -525,7 +525,7 @@ mod tests {
|
||||||
.map(|r| (r.score(), r))
|
.map(|r| (r.score(), r))
|
||||||
.sorted_by_key(|(score, _r)| *score)
|
.sorted_by_key(|(score, _r)| *score)
|
||||||
.fold(
|
.fold(
|
||||||
(u8::MIN, vec![vec![]]),
|
(u32::MIN, vec![vec![]]),
|
||||||
|(mut currently_collecting_score, mut out), (score, r)| {
|
|(mut currently_collecting_score, mut out), (score, r)| {
|
||||||
if currently_collecting_score == score {
|
if currently_collecting_score == score {
|
||||||
out.last_mut().unwrap().push(r);
|
out.last_mut().unwrap().push(r);
|
||||||
|
|
|
@ -220,12 +220,12 @@ pub(crate) fn completion_item(
|
||||||
}
|
}
|
||||||
// The relevance needs to be inverted to come up with a sort score
|
// The relevance needs to be inverted to come up with a sort score
|
||||||
// because the client will sort ascending.
|
// because the client will sort ascending.
|
||||||
let sort_score = relevance.score() ^ 0xFF;
|
let sort_score = relevance.score() ^ 0xFF_FF_FF_FF;
|
||||||
// Zero pad the string to ensure values are sorted numerically
|
// Zero pad the string to ensure values can be properly sorted
|
||||||
// even though the client is sorting alphabetically. Three
|
// by the client. Hex format is used because it is easier to
|
||||||
// characters is enough to fit the largest u8, which is the
|
// visually compare very large values, which the sort text
|
||||||
// type of the relevance score.
|
// tends to be since it is the opposite of the score.
|
||||||
res.sort_text = Some(format!("{:03}", sort_score));
|
res.sort_text = Some(format!("{:08x}", sort_score));
|
||||||
}
|
}
|
||||||
|
|
||||||
set_score(&mut lsp_item, item.relevance());
|
set_score(&mut lsp_item, item.relevance());
|
||||||
|
@ -1117,13 +1117,13 @@ mod tests {
|
||||||
(
|
(
|
||||||
"&arg",
|
"&arg",
|
||||||
Some(
|
Some(
|
||||||
"253",
|
"fffffffd",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"arg",
|
"arg",
|
||||||
Some(
|
Some(
|
||||||
"254",
|
"fffffffe",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue