@@ -143,15 +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 ,
146
+ /// Set for postfix snippet item completions
147
+ pub postfix_match : Option < CompletionRelevancePostfixMatch > ,
155
148
}
156
149
157
150
#[ derive( Debug , Clone , Copy , Eq , PartialEq ) ]
@@ -178,8 +171,23 @@ pub enum CompletionRelevanceTypeMatch {
178
171
Exact ,
179
172
}
180
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
+
181
189
impl CompletionRelevance {
182
- const BASE_LINE : u32 = 2 ;
190
+ const BASE_LINE : u32 = 3 ;
183
191
/// Provides a relevance score. Higher values are more relevant.
184
192
///
185
193
/// The absolute value of the relevance score is not meaningful, for
@@ -199,6 +207,9 @@ impl CompletionRelevance {
199
207
if self . is_private_editable {
200
208
score -= 1 ;
201
209
}
210
+ if self . postfix_match . is_some ( ) {
211
+ score -= 3 ;
212
+ }
202
213
203
214
// score increases
204
215
if self . exact_name_match {
@@ -212,9 +223,10 @@ impl CompletionRelevance {
212
223
if self . is_local {
213
224
score += 1 ;
214
225
}
215
- if self . exact_postfix_snippet_match {
226
+ if self . postfix_match == Some ( CompletionRelevancePostfixMatch :: Exact ) {
216
227
score += 100 ;
217
228
}
229
+
218
230
score
219
231
}
220
232
@@ -530,7 +542,9 @@ mod tests {
530
542
use itertools:: Itertools ;
531
543
use test_utils:: assert_eq_text;
532
544
533
- use super :: { CompletionRelevance , CompletionRelevanceTypeMatch } ;
545
+ use super :: {
546
+ CompletionRelevance , CompletionRelevancePostfixMatch , CompletionRelevanceTypeMatch ,
547
+ } ;
534
548
535
549
/// Check that these are CompletionRelevance are sorted in ascending order
536
550
/// by their relevance score.
@@ -573,6 +587,10 @@ mod tests {
573
587
// This test asserts that the relevance score for these items is ascending, and
574
588
// that any items in the same vec have the same score.
575
589
let expected_relevance_order = vec ! [
590
+ vec![ CompletionRelevance {
591
+ postfix_match: Some ( CompletionRelevancePostfixMatch :: NonExact ) ,
592
+ ..CompletionRelevance :: default ( )
593
+ } ] ,
576
594
vec![ CompletionRelevance {
577
595
is_op_method: true ,
578
596
is_private_editable: true ,
@@ -612,7 +630,7 @@ mod tests {
612
630
..CompletionRelevance :: default ( )
613
631
} ] ,
614
632
vec![ CompletionRelevance {
615
- exact_postfix_snippet_match : true ,
633
+ postfix_match : Some ( CompletionRelevancePostfixMatch :: Exact ) ,
616
634
..CompletionRelevance :: default ( )
617
635
} ] ,
618
636
] ;
0 commit comments