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 | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/crates/ide_completion/src/item.rs b/crates/ide_completion/src/item.rs index 7948e19af9..89cbddbad3 100644 --- a/crates/ide_completion/src/item.rs +++ b/crates/ide_completion/src/item.rs @@ -143,17 +143,8 @@ pub struct CompletionRelevance { pub is_op_method: bool, /// Set for item completions that are private but in the workspace. pub is_private_editable: bool, - /// This is set in cases like these: - /// - /// ``` - /// (a > b).not$0 - /// ``` - /// - /// 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, + /// Set for postfix snippet item completions + pub postfix_match: Option<CompletionRelevancePostfixMatch>, } #[derive(Debug, Clone, Copy, Eq, PartialEq)] @@ -180,6 +171,21 @@ pub enum CompletionRelevanceTypeMatch { Exact, } +#[derive(Debug, Clone, Copy, Eq, PartialEq)] +pub enum CompletionRelevancePostfixMatch { + /// Set in cases when item is postfix, but not exact + NonExact, + /// This is set in cases like these: + /// + /// ``` + /// (a > b).not$0 + /// ``` + /// + /// Basically, we want to guarantee that postfix snippets always takes + /// precedence over everything else. + Exact, +} + impl CompletionRelevance { const BASE_LINE: u32 = 3; /// Provides a relevance score. Higher values are more relevant. @@ -201,7 +207,7 @@ impl CompletionRelevance { if self.is_private_editable { score -= 1; } - if self.is_postfix { + if self.postfix_match.is_some() { score -= 3; } @@ -217,7 +223,7 @@ impl CompletionRelevance { if self.is_local { score += 1; } - if self.exact_postfix_snippet_match { + if self.postfix_match == Some(CompletionRelevancePostfixMatch::Exact) { score += 100; } @@ -536,7 +542,9 @@ mod tests { use itertools::Itertools; use test_utils::assert_eq_text; - use super::{CompletionRelevance, CompletionRelevanceTypeMatch}; + use super::{ + CompletionRelevance, CompletionRelevancePostfixMatch, CompletionRelevanceTypeMatch, + }; /// Check that these are CompletionRelevance are sorted in ascending order /// by their relevance score. @@ -579,7 +587,10 @@ 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_postfix: true, ..CompletionRelevance::default() }], + vec![CompletionRelevance { + postfix_match: Some(CompletionRelevancePostfixMatch::NonExact), + ..CompletionRelevance::default() + }], vec![CompletionRelevance { is_op_method: true, is_private_editable: true, @@ -619,7 +630,7 @@ mod tests { ..CompletionRelevance::default() }], vec![CompletionRelevance { - exact_postfix_snippet_match: true, + postfix_match: Some(CompletionRelevancePostfixMatch::Exact), ..CompletionRelevance::default() }], ]; |