Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide_completion/src/item.rs')
| -rw-r--r-- | crates/ide_completion/src/item.rs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/crates/ide_completion/src/item.rs b/crates/ide_completion/src/item.rs index 4a6e034dc9..8ac4291078 100644 --- a/crates/ide_completion/src/item.rs +++ b/crates/ide_completion/src/item.rs @@ -139,6 +139,8 @@ pub struct CompletionRelevance { /// } /// ``` pub is_local: bool, + /// Set for method completions of the `core::ops` family. + pub is_op_method: bool, /// This is set in cases like these: /// /// ``` @@ -175,6 +177,7 @@ pub enum CompletionRelevanceTypeMatch { } impl CompletionRelevance { + const BASE_LINE: u32 = 1; /// Provides a relevance score. Higher values are more relevant. /// /// The absolute value of the relevance score is not meaningful, for @@ -185,7 +188,7 @@ impl CompletionRelevance { /// See is_relevant if you need to make some judgement about score /// in an absolute sense. pub fn score(&self) -> u32 { - let mut score = 0; + let mut score = Self::BASE_LINE; if self.exact_name_match { score += 1; @@ -198,6 +201,9 @@ impl CompletionRelevance { if self.is_local { score += 1; } + if self.is_op_method { + score -= 1; + } if self.exact_postfix_snippet_match { score += 100; } @@ -208,7 +214,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 + self.score() > (Self::BASE_LINE + 1) } } @@ -558,6 +564,7 @@ mod tests { // This test asserts that the relevance score for these items is ascending, and // that any items in the same vec have the same score. let expected_relevance_order = vec![ + vec![CompletionRelevance { is_op_method: true, ..CompletionRelevance::default() }], vec![CompletionRelevance::default()], vec![ CompletionRelevance { exact_name_match: true, ..CompletionRelevance::default() }, @@ -588,10 +595,8 @@ mod tests { ..CompletionRelevance::default() }], vec![CompletionRelevance { - exact_name_match: false, - type_match: None, - is_local: false, exact_postfix_snippet_match: true, + ..CompletionRelevance::default() }], ]; |