]> git.lizzy.rs Git - rust.git/commitdiff
update relevance score u8 -> u32
authorJosh Mcguigan <joshmcg88@gmail.com>
Fri, 12 Mar 2021 14:08:07 +0000 (06:08 -0800)
committerJosh Mcguigan <joshmcg88@gmail.com>
Fri, 12 Mar 2021 14:16:04 +0000 (06:16 -0800)
crates/ide_completion/src/item.rs
crates/rust-analyzer/src/to_proto.rs

index 352640e3b606b84a4893e7e93b4bb64abc802345..3febab32b589093a662d59cefb026cb9a8ea5ef5 100644 (file)
@@ -156,7 +156,7 @@ impl CompletionRelevance {
     ///
     /// See is_relevant if you need to make some judgement about score
     /// in an absolute sense.
-    pub fn score(&self) -> u8 {
+    pub fn score(&self) -> u32 {
         let mut score = 0;
 
         if self.exact_name_match {
@@ -525,7 +525,7 @@ fn check_relevance_score_ordered(expected_relevance_order: Vec<Vec<CompletionRel
             .map(|r| (r.score(), r))
             .sorted_by_key(|(score, _r)| *score)
             .fold(
-                (u8::MIN, vec![vec![]]),
+                (u32::MIN, vec![vec![]]),
                 |(mut currently_collecting_score, mut out), (score, r)| {
                     if currently_collecting_score == score {
                         out.last_mut().unwrap().push(r);
index a467bc685ccce0836c89f1227878721458547732..1a8cdadad0084d6c91ca2c9401a888dd4b300a72 100644 (file)
@@ -220,12 +220,12 @@ fn set_score(res: &mut lsp_types::CompletionItem, relevance: CompletionRelevance
         }
         // The relevance needs to be inverted to come up with a sort score
         // because the client will sort ascending.
-        let sort_score = relevance.score() ^ 0xFF;
-        // Zero pad the string to ensure values are sorted numerically
-        // even though the client is sorting alphabetically. Three
-        // characters is enough to fit the largest u8, which is the
-        // type of the relevance score.
-        res.sort_text = Some(format!("{:03}", sort_score));
+        let sort_score = relevance.score() ^ 0xFF_FF_FF_FF;
+        // Zero pad the string to ensure values can be properly sorted
+        // by the client. Hex format is used because it is easier to
+        // visually compare very large values, which the sort text
+        // tends to be since it is the opposite of the score.
+        res.sort_text = Some(format!("{:08x}", sort_score));
     }
 
     set_score(&mut lsp_item, item.relevance());
@@ -1117,13 +1117,13 @@ fn main() {
                 (
                     "&arg",
                     Some(
-                        "253",
+                        "fffffffd",
                     ),
                 ),
                 (
                     "arg",
                     Some(
-                        "254",
+                        "fffffffe",
                     ),
                 ),
             ]