aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorJosh Mcguigan <[email protected]>2021-03-12 14:08:07 +0000
committerJosh Mcguigan <[email protected]>2021-03-12 14:16:04 +0000
commitacbe297fbd10250e0d99d1e3e98751dd6ef77adc (patch)
tree5ff7a667e2d10a69333af496b75a85a637f0488c /crates
parent10fb065b146d7d03a65bbc73cdb34d32523dafa1 (diff)
update relevance score u8 -> u32
Diffstat (limited to 'crates')
-rw-r--r--crates/ide_completion/src/item.rs4
-rw-r--r--crates/rust-analyzer/src/to_proto.rs16
2 files changed, 10 insertions, 10 deletions
diff --git a/crates/ide_completion/src/item.rs b/crates/ide_completion/src/item.rs
index 352640e3b..3febab32b 100644
--- a/crates/ide_completion/src/item.rs
+++ b/crates/ide_completion/src/item.rs
@@ -156,7 +156,7 @@ impl CompletionRelevance {
156 /// 156 ///
157 /// See is_relevant if you need to make some judgement about score 157 /// See is_relevant if you need to make some judgement about score
158 /// in an absolute sense. 158 /// in an absolute sense.
159 pub fn score(&self) -> u8 { 159 pub fn score(&self) -> u32 {
160 let mut score = 0; 160 let mut score = 0;
161 161
162 if self.exact_name_match { 162 if self.exact_name_match {
@@ -525,7 +525,7 @@ mod tests {
525 .map(|r| (r.score(), r)) 525 .map(|r| (r.score(), r))
526 .sorted_by_key(|(score, _r)| *score) 526 .sorted_by_key(|(score, _r)| *score)
527 .fold( 527 .fold(
528 (u8::MIN, vec![vec![]]), 528 (u32::MIN, vec![vec![]]),
529 |(mut currently_collecting_score, mut out), (score, r)| { 529 |(mut currently_collecting_score, mut out), (score, r)| {
530 if currently_collecting_score == score { 530 if currently_collecting_score == score {
531 out.last_mut().unwrap().push(r); 531 out.last_mut().unwrap().push(r);
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs
index a467bc685..1a8cdadad 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -220,12 +220,12 @@ pub(crate) fn completion_item(
220 } 220 }
221 // The relevance needs to be inverted to come up with a sort score 221 // The relevance needs to be inverted to come up with a sort score
222 // because the client will sort ascending. 222 // because the client will sort ascending.
223 let sort_score = relevance.score() ^ 0xFF; 223 let sort_score = relevance.score() ^ 0xFF_FF_FF_FF;
224 // Zero pad the string to ensure values are sorted numerically 224 // Zero pad the string to ensure values can be properly sorted
225 // even though the client is sorting alphabetically. Three 225 // by the client. Hex format is used because it is easier to
226 // characters is enough to fit the largest u8, which is the 226 // visually compare very large values, which the sort text
227 // type of the relevance score. 227 // tends to be since it is the opposite of the score.
228 res.sort_text = Some(format!("{:03}", sort_score)); 228 res.sort_text = Some(format!("{:08x}", sort_score));
229 } 229 }
230 230
231 set_score(&mut lsp_item, item.relevance()); 231 set_score(&mut lsp_item, item.relevance());
@@ -1117,13 +1117,13 @@ mod tests {
1117 ( 1117 (
1118 "&arg", 1118 "&arg",
1119 Some( 1119 Some(
1120 "253", 1120 "fffffffd",
1121 ), 1121 ),
1122 ), 1122 ),
1123 ( 1123 (
1124 "arg", 1124 "arg",
1125 Some( 1125 Some(
1126 "254", 1126 "fffffffe",
1127 ), 1127 ),
1128 ), 1128 ),
1129 ] 1129 ]