diff options
| author | Tongjun Gao <natural_selection_@outlook.com> | 2025-03-07 14:44:57 +0800 |
|---|---|---|
| committer | Tongjun Gao <natural_selection_@outlook.com> | 2025-03-07 14:44:57 +0800 |
| commit | 16878eb02a27e5d8a4520851d88c33bd34170695 (patch) | |
| tree | 843d4c7dd302c3fd89d9eefa2796649f7dcd7fec | |
| parent | f68fd669f3d7a0847b5c2f3b789b6c95db0acdc1 (diff) | |
| download | rust-16878eb02a27e5d8a4520851d88c33bd34170695.tar.gz rust-16878eb02a27e5d8a4520851d88c33bd34170695.zip | |
Refactor relevance scoring to use a named constant BASE_SCORE
Replace magic number with a named constant for improved readability and maintainability of the scoring logic
| -rw-r--r-- | src/tools/rust-analyzer/crates/ide-completion/src/item.rs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/item.rs b/src/tools/rust-analyzer/crates/ide-completion/src/item.rs index 294fbde1b6d..8d6dc4c8013 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/item.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/item.rs @@ -252,14 +252,16 @@ impl CompletionRelevance { /// Provides a relevance score. Higher values are more relevant. /// /// The absolute value of the relevance score is not meaningful, for - /// example a value of (!(0 as u32) / 2) doesn't mean "not relevant", rather + /// example a value of BASE_SCORE doesn't mean "not relevant", rather /// it means "least relevant". The score value should only be used /// for relative ordering. /// /// See is_relevant if you need to make some judgement about score /// in an absolute sense. + const BASE_SCORE: u32 = u32::MAX / 2; + pub fn score(self) -> u32 { - let mut score = !(0 as u32) / 2; + let mut score = Self::BASE_SCORE; let CompletionRelevance { exact_name_match, type_match, @@ -350,7 +352,7 @@ impl CompletionRelevance { /// some threshold such that we think it is especially likely /// to be relevant. pub fn is_relevant(&self) -> bool { - self.score() > !(0 as u32) / 2 + self.score() > Self::BASE_SCORE } } |
