aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ide_completion/src/render.rs63
1 files changed, 25 insertions, 38 deletions
diff --git a/crates/ide_completion/src/render.rs b/crates/ide_completion/src/render.rs
index ede4aa807..fcb8115fb 100644
--- a/crates/ide_completion/src/render.rs
+++ b/crates/ide_completion/src/render.rs
@@ -259,15 +259,17 @@ impl<'a> Render<'a> {
259 } 259 }
260 260
261 if let Some((_expected_name, expected_type)) = self.ctx.expected_name_and_type() { 261 if let Some((_expected_name, expected_type)) = self.ctx.expected_name_and_type() {
262 if let Some(ty_without_ref) = expected_type.remove_ref() { 262 if ty != expected_type {
263 if relevance_type_match(self.ctx.db().upcast(), &ty, &ty_without_ref) { 263 if let Some(ty_without_ref) = expected_type.remove_ref() {
264 cov_mark::hit!(suggest_ref); 264 if relevance_type_match(self.ctx.db().upcast(), &ty, &ty_without_ref) {
265 let mutability = if expected_type.is_mutable_reference() { 265 cov_mark::hit!(suggest_ref);
266 Mutability::Mut 266 let mutability = if expected_type.is_mutable_reference() {
267 } else { 267 Mutability::Mut
268 Mutability::Shared 268 } else {
269 }; 269 Mutability::Shared
270 item.ref_match(mutability); 270 };
271 item.ref_match(mutability);
272 }
271 } 273 }
272 } 274 }
273 } 275 }
@@ -340,8 +342,6 @@ fn relevance_type_match(db: &dyn HirDatabase, ty: &Type, expected_type: &Type) -
340 342
341#[cfg(test)] 343#[cfg(test)]
342mod tests { 344mod tests {
343 use std::cmp::Reverse;
344
345 use expect_test::{expect, Expect}; 345 use expect_test::{expect, Expect};
346 346
347 use crate::{ 347 use crate::{
@@ -366,19 +366,7 @@ mod tests {
366 } 366 }
367 } 367 }
368 368
369 let mut completions = get_all_items(TEST_CONFIG, ra_fixture); 369 let actual = get_all_items(TEST_CONFIG, ra_fixture)
370 completions.sort_by_key(|it| {
371 // (Reverse(it.ref_match().map(|m| m.1).unwrap_or(it.relevance())), it.label().to_string())
372 if let Some((mutability, relevance)) = it.ref_match() {
373 let label = format!("&{}{}", mutability.as_keyword_for_ref(), it.label());
374
375 Reverse((relevance, label))
376 } else {
377 Reverse((it.relevance(), it.label().to_string()))
378 }
379 });
380
381 let actual = completions
382 .into_iter() 370 .into_iter()
383 .filter(|it| it.completion_kind == CompletionKind::Reference) 371 .filter(|it| it.completion_kind == CompletionKind::Reference)
384 .flat_map(|it| { 372 .flat_map(|it| {
@@ -868,9 +856,9 @@ fn test(bar: u32) { }
868fn foo(s: S) { test(s.$0) } 856fn foo(s: S) { test(s.$0) }
869"#, 857"#,
870 expect![[r#" 858 expect![[r#"
859 fd foo []
871 fd bar [type+name] 860 fd bar [type+name]
872 fd baz [type] 861 fd baz [type]
873 fd foo []
874 "#]], 862 "#]],
875 ); 863 );
876 } 864 }
@@ -885,9 +873,9 @@ struct B { x: (), y: f32, bar: u32 }
885fn foo(a: A) { B { bar: a.$0 }; } 873fn foo(a: A) { B { bar: a.$0 }; }
886"#, 874"#,
887 expect![[r#" 875 expect![[r#"
876 fd foo []
888 fd bar [type+name] 877 fd bar [type+name]
889 fd baz [type] 878 fd baz [type]
890 fd foo []
891 "#]], 879 "#]],
892 ) 880 )
893 } 881 }
@@ -903,8 +891,8 @@ fn foo(a: A) { B { bar: f(a.$0) }; }
903"#, 891"#,
904 expect![[r#" 892 expect![[r#"
905 fd foo [type+name] 893 fd foo [type+name]
906 fd baz []
907 fd bar [] 894 fd bar []
895 fd baz []
908 "#]], 896 "#]],
909 ); 897 );
910 check_relevance( 898 check_relevance(
@@ -915,9 +903,9 @@ fn f(foo: i64) { }
915fn foo(a: A) { f(B { bar: a.$0 }); } 903fn foo(a: A) { f(B { bar: a.$0 }); }
916"#, 904"#,
917 expect![[r#" 905 expect![[r#"
906 fd foo []
918 fd bar [type+name] 907 fd bar [type+name]
919 fd baz [type] 908 fd baz [type]
920 fd foo []
921 "#]], 909 "#]],
922 ); 910 );
923 } 911 }
@@ -931,9 +919,8 @@ fn go(world: &WorldSnapshot) { go(w$0) }
931"#, 919"#,
932 expect![[r#" 920 expect![[r#"
933 lc world [type+name] 921 lc world [type+name]
934 lc &world [type+name]
935 fn go(…) []
936 st WorldSnapshot [] 922 st WorldSnapshot []
923 fn go(…) []
937 "#]], 924 "#]],
938 ); 925 );
939 } 926 }
@@ -947,8 +934,8 @@ fn f(foo: &Foo) { f(foo, w$0) }
947"#, 934"#,
948 expect![[r#" 935 expect![[r#"
949 lc foo [] 936 lc foo []
950 fn f(…) []
951 st Foo [] 937 st Foo []
938 fn f(…) []
952 "#]], 939 "#]],
953 ); 940 );
954 } 941 }
@@ -1050,14 +1037,14 @@ fn main() {
1050} 1037}
1051 "#, 1038 "#,
1052 expect![[r#" 1039 expect![[r#"
1040 lc m []
1053 lc t [] 1041 lc t []
1054 lc &t [type] 1042 lc &t [type]
1055 fn main() []
1056 lc m []
1057 fn foo(…) []
1058 st T [] 1043 st T []
1059 st S [] 1044 st S []
1045 fn main() []
1060 tt Deref [] 1046 tt Deref []
1047 fn foo(…) []
1061 "#]], 1048 "#]],
1062 ) 1049 )
1063 } 1050 }
@@ -1104,15 +1091,15 @@ fn main() {
1104} 1091}
1105 "#, 1092 "#,
1106 expect![[r#" 1093 expect![[r#"
1094 lc m []
1107 lc t [] 1095 lc t []
1108 lc &mut t [type] 1096 lc &mut t [type]
1109 fn main() [] 1097 tt DerefMut []
1110 lc m [] 1098 tt Deref []
1111 fn foo(…) [] 1099 fn foo(…) []
1112 st T [] 1100 st T []
1113 st S [] 1101 st S []
1114 tt DerefMut [] 1102 fn main() []
1115 tt Deref []
1116 "#]], 1103 "#]],
1117 ) 1104 )
1118 } 1105 }