@@ -20,8 +20,8 @@ use ide_db::{
20
20
use syntax:: TextRange ;
21
21
22
22
use crate :: {
23
- item:: ImportEdit , CompletionContext , CompletionItem , CompletionItemKind , CompletionKind ,
24
- CompletionRelevance ,
23
+ item:: { CompletionRelevanceTypeMatch , ImportEdit } ,
24
+ CompletionContext , CompletionItem , CompletionItemKind , CompletionKind , CompletionRelevance ,
25
25
} ;
26
26
27
27
use crate :: render:: { enum_variant:: render_variant, function:: render_fn, macro_:: render_macro} ;
@@ -143,7 +143,7 @@ impl<'a> Render<'a> {
143
143
. set_deprecated ( is_deprecated) ;
144
144
145
145
item. set_relevance ( CompletionRelevance {
146
- exact_type_match : compute_exact_type_match ( self . ctx . completion , ty) ,
146
+ type_match : compute_exact_type_match ( self . ctx . completion , ty) ,
147
147
exact_name_match : compute_exact_name_match ( self . ctx . completion , name. to_string ( ) ) ,
148
148
..CompletionRelevance :: default ( )
149
149
} ) ;
@@ -245,7 +245,7 @@ impl<'a> Render<'a> {
245
245
}
246
246
247
247
item. set_relevance ( CompletionRelevance {
248
- exact_type_match : compute_exact_type_match ( self . ctx . completion , & ty) ,
248
+ type_match : compute_exact_type_match ( self . ctx . completion , & ty) ,
249
249
exact_name_match : compute_exact_name_match ( self . ctx . completion , & local_name) ,
250
250
is_local : true ,
251
251
..CompletionRelevance :: default ( )
@@ -309,15 +309,24 @@ impl<'a> Render<'a> {
309
309
}
310
310
}
311
311
312
- fn compute_exact_type_match ( ctx : & CompletionContext , completion_ty : & hir:: Type ) -> bool {
313
- match ctx. expected_type . as_ref ( ) {
314
- Some ( expected_type) => {
315
- // We don't ever consider unit type to be an exact type match, since
316
- // nearly always this is not meaningful to the user.
317
- ( completion_ty == expected_type || expected_type. could_unify_with ( completion_ty) )
318
- && !expected_type. is_unit ( )
319
- }
320
- None => false ,
312
+ fn compute_exact_type_match (
313
+ ctx : & CompletionContext ,
314
+ completion_ty : & hir:: Type ,
315
+ ) -> Option < CompletionRelevanceTypeMatch > {
316
+ let expected_type = ctx. expected_type . as_ref ( ) ?;
317
+
318
+ // We don't ever consider unit type to be an exact type match, since
319
+ // nearly always this is not meaningful to the user.
320
+ if expected_type. is_unit ( ) {
321
+ return None ;
322
+ }
323
+
324
+ if completion_ty == expected_type {
325
+ Some ( CompletionRelevanceTypeMatch :: Exact )
326
+ } else if expected_type. could_unify_with ( completion_ty) {
327
+ Some ( CompletionRelevanceTypeMatch :: CouldUnify )
328
+ } else {
329
+ None
321
330
}
322
331
}
323
332
@@ -349,6 +358,7 @@ mod tests {
349
358
use itertools:: Itertools ;
350
359
351
360
use crate :: {
361
+ item:: CompletionRelevanceTypeMatch ,
352
362
test_utils:: { check_edit, do_completion, get_all_items, TEST_CONFIG } ,
353
363
CompletionKind , CompletionRelevance ,
354
364
} ;
@@ -361,7 +371,11 @@ mod tests {
361
371
fn check_relevance ( ra_fixture : & str , expect : Expect ) {
362
372
fn display_relevance ( relevance : CompletionRelevance ) -> String {
363
373
let relevance_factors = vec ! [
364
- ( relevance. exact_type_match, "type" ) ,
374
+ ( relevance. type_match == Some ( CompletionRelevanceTypeMatch :: Exact ) , "type" ) ,
375
+ (
376
+ relevance. type_match == Some ( CompletionRelevanceTypeMatch :: CouldUnify ) ,
377
+ "type_could_unify" ,
378
+ ) ,
365
379
( relevance. exact_name_match, "name" ) ,
366
380
( relevance. is_local, "local" ) ,
367
381
]
@@ -534,7 +548,9 @@ fn main() { let _: m::Spam = S$0 }
534
548
detail: "(i32)",
535
549
relevance: CompletionRelevance {
536
550
exact_name_match: false,
537
- exact_type_match: true,
551
+ type_match: Some(
552
+ Exact,
553
+ ),
538
554
is_local: false,
539
555
},
540
556
trigger_call_info: true,
@@ -560,7 +576,9 @@ fn main() { let _: m::Spam = S$0 }
560
576
detail: "()",
561
577
relevance: CompletionRelevance {
562
578
exact_name_match: false,
563
- exact_type_match: true,
579
+ type_match: Some(
580
+ Exact,
581
+ ),
564
582
is_local: false,
565
583
},
566
584
},
@@ -1109,7 +1127,7 @@ fn main() {
1109
1127
detail: "S",
1110
1128
relevance: CompletionRelevance {
1111
1129
exact_name_match: true,
1112
- exact_type_match: false ,
1130
+ type_match: None ,
1113
1131
is_local: true,
1114
1132
},
1115
1133
ref_match: "&mut ",
@@ -1374,8 +1392,8 @@ fn foo() {
1374
1392
}
1375
1393
"# ,
1376
1394
expect ! [ [ r#"
1377
- ev Foo::A(…) [type ]
1378
- ev Foo::B [type ]
1395
+ ev Foo::A(…) [type_could_unify ]
1396
+ ev Foo::B [type_could_unify ]
1379
1397
lc foo [type+local]
1380
1398
en Foo []
1381
1399
fn baz() []
0 commit comments