Merge pull request #19307 from Natural-selection1/master

Fix logical error in PR #19297
This commit is contained in:
Lukas Wirth 2025-03-07 06:58:48 +00:00 committed by GitHub
commit 488d1dc7aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -252,14 +252,16 @@ impl CompletionRelevance {
/// Provides a relevance score. Higher values are more relevant. /// Provides a relevance score. Higher values are more relevant.
/// ///
/// The absolute value of the relevance score is not meaningful, for /// The absolute value of the relevance score is not meaningful, for
/// example a value of 0 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 /// it means "least relevant". The score value should only be used
/// for relative ordering. /// for relative ordering.
/// ///
/// 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.
const BASE_SCORE: u32 = u32::MAX / 2;
pub fn score(self) -> u32 { pub fn score(self) -> u32 {
let mut score = !0 / 2; let mut score = Self::BASE_SCORE;
let CompletionRelevance { let CompletionRelevance {
exact_name_match, exact_name_match,
type_match, type_match,
@ -350,7 +352,7 @@ impl CompletionRelevance {
/// some threshold such that we think it is especially likely /// some threshold such that we think it is especially likely
/// to be relevant. /// to be relevant.
pub fn is_relevant(&self) -> bool { pub fn is_relevant(&self) -> bool {
self.score() > (!0 / 2) self.score() > Self::BASE_SCORE
} }
} }