@@ -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
} ) ;
@@ -243,7 +243,7 @@ impl<'a> Render<'a> {
243
243
}
244
244
245
245
item. set_relevance ( CompletionRelevance {
246
- exact_type_match : compute_exact_type_match ( self . ctx . completion , & ty) ,
246
+ type_match : compute_exact_type_match ( self . ctx . completion , & ty) ,
247
247
exact_name_match : compute_exact_name_match ( self . ctx . completion , & local_name) ,
248
248
is_local : true ,
249
249
..CompletionRelevance :: default ( )
@@ -307,15 +307,24 @@ impl<'a> Render<'a> {
307
307
}
308
308
}
309
309
310
- fn compute_exact_type_match ( ctx : & CompletionContext , completion_ty : & hir:: Type ) -> bool {
311
- match ctx. expected_type . as_ref ( ) {
312
- Some ( expected_type) => {
313
- // We don't ever consider unit type to be an exact type match, since
314
- // nearly always this is not meaningful to the user.
315
- ( completion_ty == expected_type || expected_type. could_unify_with ( completion_ty) )
316
- && !expected_type. is_unit ( )
317
- }
318
- None => false ,
310
+ fn compute_exact_type_match (
311
+ ctx : & CompletionContext ,
312
+ completion_ty : & hir:: Type ,
313
+ ) -> Option < CompletionRelevanceTypeMatch > {
314
+ let expected_type = ctx. expected_type . as_ref ( ) ?;
315
+
316
+ // We don't ever consider unit type to be an exact type match, since
317
+ // nearly always this is not meaningful to the user.
318
+ if expected_type. is_unit ( ) {
319
+ return None ;
320
+ }
321
+
322
+ if completion_ty == expected_type {
323
+ Some ( CompletionRelevanceTypeMatch :: Exact )
324
+ } else if expected_type. could_unify_with ( completion_ty) {
325
+ Some ( CompletionRelevanceTypeMatch :: CouldUnify )
326
+ } else {
327
+ None
319
328
}
320
329
}
321
330
@@ -347,6 +356,7 @@ mod tests {
347
356
use itertools:: Itertools ;
348
357
349
358
use crate :: {
359
+ item:: CompletionRelevanceTypeMatch ,
350
360
test_utils:: { check_edit, do_completion, get_all_items, TEST_CONFIG } ,
351
361
CompletionKind , CompletionRelevance ,
352
362
} ;
@@ -359,7 +369,11 @@ mod tests {
359
369
fn check_relevance ( ra_fixture : & str , expect : Expect ) {
360
370
fn display_relevance ( relevance : CompletionRelevance ) -> String {
361
371
let relevance_factors = vec ! [
362
- ( relevance. exact_type_match, "type" ) ,
372
+ ( relevance. type_match == Some ( CompletionRelevanceTypeMatch :: Exact ) , "type" ) ,
373
+ (
374
+ relevance. type_match == Some ( CompletionRelevanceTypeMatch :: CouldUnify ) ,
375
+ "type_could_unify" ,
376
+ ) ,
363
377
( relevance. exact_name_match, "name" ) ,
364
378
( relevance. is_local, "local" ) ,
365
379
]
@@ -532,7 +546,9 @@ fn main() { let _: m::Spam = S$0 }
532
546
detail: "(i32)",
533
547
relevance: CompletionRelevance {
534
548
exact_name_match: false,
535
- exact_type_match: true,
549
+ type_match: Some(
550
+ Exact,
551
+ ),
536
552
is_local: false,
537
553
},
538
554
trigger_call_info: true,
@@ -558,7 +574,9 @@ fn main() { let _: m::Spam = S$0 }
558
574
detail: "()",
559
575
relevance: CompletionRelevance {
560
576
exact_name_match: false,
561
- exact_type_match: true,
577
+ type_match: Some(
578
+ Exact,
579
+ ),
562
580
is_local: false,
563
581
},
564
582
},
@@ -1107,7 +1125,7 @@ fn main() {
1107
1125
detail: "S",
1108
1126
relevance: CompletionRelevance {
1109
1127
exact_name_match: true,
1110
- exact_type_match: false ,
1128
+ type_match: None ,
1111
1129
is_local: true,
1112
1130
},
1113
1131
ref_match: "&mut ",
@@ -1334,8 +1352,8 @@ fn foo() {
1334
1352
}
1335
1353
"# ,
1336
1354
expect ! [ [ r#"
1337
- ev Foo::A(…) [type ]
1338
- ev Foo::B [type ]
1355
+ ev Foo::A(…) [type_could_unify ]
1356
+ ev Foo::B [type_could_unify ]
1339
1357
lc foo [type+local]
1340
1358
en Foo []
1341
1359
fn baz() []
0 commit comments