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 | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/crates/ide_completion/src/item.rs b/crates/ide_completion/src/item.rs index 4b9f7d17c3..e86a1af8ae 100644 --- a/crates/ide_completion/src/item.rs +++ b/crates/ide_completion/src/item.rs @@ -152,6 +152,8 @@ pub struct CompletionRelevance { /// Basically, we want to guarantee that postfix snippets always takes /// precedence over everything else. pub exact_postfix_snippet_match: bool, + /// Set in cases when item is postfix, but not exact + pub is_postfix: bool, } #[derive(Debug, Clone, Copy, Eq, PartialEq)] @@ -179,7 +181,7 @@ pub enum CompletionRelevanceTypeMatch { } impl CompletionRelevance { - const BASE_LINE: u32 = 2; + const BASE_LINE: u32 = 3; /// Provides a relevance score. Higher values are more relevant. /// /// The absolute value of the relevance score is not meaningful, for @@ -199,6 +201,9 @@ impl CompletionRelevance { if self.is_private_editable { score -= 1; } + if self.is_postfix { + score -= 3; + } // score increases if self.exact_name_match { @@ -215,6 +220,7 @@ impl CompletionRelevance { if self.exact_postfix_snippet_match { score += 100; } + score } @@ -574,6 +580,10 @@ mod tests { // that any items in the same vec have the same score. let expected_relevance_order = vec![ vec![CompletionRelevance { + is_postfix: true, + ..CompletionRelevance::default() + }], + vec![CompletionRelevance { is_op_method: true, is_private_editable: true, ..CompletionRelevance::default() |