@@ -143,17 +143,8 @@ pub struct CompletionRelevance {
143
143
pub is_op_method : bool ,
144
144
/// Set for item completions that are private but in the workspace.
145
145
pub is_private_editable : bool ,
146
- /// This is set in cases like these:
147
- ///
148
- /// ```
149
- /// (a > b).not$0
150
- /// ```
151
- ///
152
- /// Basically, we want to guarantee that postfix snippets always takes
153
- /// precedence over everything else.
154
- pub exact_postfix_snippet_match : bool ,
155
- /// Set in cases when item is postfix, but not exact
156
- pub is_postfix : bool ,
146
+ /// Set for postfix snippet item completions
147
+ pub postfix_match : Option < CompletionRelevancePostfixMatch > ,
157
148
}
158
149
159
150
#[ derive( Debug , Clone , Copy , Eq , PartialEq ) ]
@@ -180,6 +171,21 @@ pub enum CompletionRelevanceTypeMatch {
180
171
Exact ,
181
172
}
182
173
174
+ #[ derive( Debug , Clone , Copy , Eq , PartialEq ) ]
175
+ pub enum CompletionRelevancePostfixMatch {
176
+ /// Set in cases when item is postfix, but not exact
177
+ NonExact ,
178
+ /// This is set in cases like these:
179
+ ///
180
+ /// ```
181
+ /// (a > b).not$0
182
+ /// ```
183
+ ///
184
+ /// Basically, we want to guarantee that postfix snippets always takes
185
+ /// precedence over everything else.
186
+ Exact ,
187
+ }
188
+
183
189
impl CompletionRelevance {
184
190
const BASE_LINE : u32 = 3 ;
185
191
/// Provides a relevance score. Higher values are more relevant.
@@ -201,7 +207,7 @@ impl CompletionRelevance {
201
207
if self . is_private_editable {
202
208
score -= 1 ;
203
209
}
204
- if self . is_postfix {
210
+ if self . postfix_match . is_some ( ) {
205
211
score -= 3 ;
206
212
}
207
213
@@ -217,7 +223,7 @@ impl CompletionRelevance {
217
223
if self . is_local {
218
224
score += 1 ;
219
225
}
220
- if self . exact_postfix_snippet_match {
226
+ if self . postfix_match == Some ( CompletionRelevancePostfixMatch :: Exact ) {
221
227
score += 100 ;
222
228
}
223
229
@@ -536,7 +542,9 @@ mod tests {
536
542
use itertools:: Itertools ;
537
543
use test_utils:: assert_eq_text;
538
544
539
- use super :: { CompletionRelevance , CompletionRelevanceTypeMatch } ;
545
+ use super :: {
546
+ CompletionRelevance , CompletionRelevancePostfixMatch , CompletionRelevanceTypeMatch ,
547
+ } ;
540
548
541
549
/// Check that these are CompletionRelevance are sorted in ascending order
542
550
/// by their relevance score.
@@ -579,7 +587,10 @@ mod tests {
579
587
// This test asserts that the relevance score for these items is ascending, and
580
588
// that any items in the same vec have the same score.
581
589
let expected_relevance_order = vec ! [
582
- vec![ CompletionRelevance { is_postfix: true , ..CompletionRelevance :: default ( ) } ] ,
590
+ vec![ CompletionRelevance {
591
+ postfix_match: Some ( CompletionRelevancePostfixMatch :: NonExact ) ,
592
+ ..CompletionRelevance :: default ( )
593
+ } ] ,
583
594
vec![ CompletionRelevance {
584
595
is_op_method: true ,
585
596
is_private_editable: true ,
@@ -619,7 +630,7 @@ mod tests {
619
630
..CompletionRelevance :: default ( )
620
631
} ] ,
621
632
vec![ CompletionRelevance {
622
- exact_postfix_snippet_match : true ,
633
+ postfix_match : Some ( CompletionRelevancePostfixMatch :: Exact ) ,
623
634
..CompletionRelevance :: default ( )
624
635
} ] ,
625
636
] ;
0 commit comments