aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorivan770 <[email protected]>2021-03-13 13:32:37 +0000
committerivan770 <[email protected]>2021-03-13 13:32:37 +0000
commit75cb441fba111bed153f519f1f2906843360cfc7 (patch)
treef3916171b982e32d61431f1d15ca5688044466bb /crates
parentd064ed5f63b746277895ae2aad37b5fd1516cce7 (diff)
Simplify call site and deref completion test
Diffstat (limited to 'crates')
-rw-r--r--crates/ide_completion/src/render.rs101
1 files changed, 16 insertions, 85 deletions
diff --git a/crates/ide_completion/src/render.rs b/crates/ide_completion/src/render.rs
index 027dee4f0..e72f54ef4 100644
--- a/crates/ide_completion/src/render.rs
+++ b/crates/ide_completion/src/render.rs
@@ -327,18 +327,18 @@ impl<'a> Render<'a> {
327fn compute_relevance(ctx: &RenderContext, ty: &Type, name: &str) -> Option<CompletionRelevance> { 327fn compute_relevance(ctx: &RenderContext, ty: &Type, name: &str) -> Option<CompletionRelevance> {
328 let (expected_name, expected_type) = ctx.expected_name_and_type()?; 328 let (expected_name, expected_type) = ctx.expected_name_and_type()?;
329 let mut res = CompletionRelevance::default(); 329 let mut res = CompletionRelevance::default();
330 res.exact_type_match = ty == &expected_type 330 res.exact_type_match = relevance_type_match(ctx.db().upcast(), ty, expected_type);
331 || autoderef_relevance(
332 ctx.db().upcast(),
333 ty,
334 expected_type.remove_ref().as_ref().unwrap_or(&expected_type),
335 );
336 res.exact_name_match = name == &expected_name; 331 res.exact_name_match = name == &expected_name;
337 Some(res) 332 Some(res)
338} 333}
339 334
340fn autoderef_relevance(db: &dyn HirDatabase, ty: &Type, expected_type: &Type) -> bool { 335fn relevance_type_match(db: &dyn HirDatabase, ty: &Type, expected_type: Type) -> bool {
341 ty.autoderef(db).any(|deref_ty| &deref_ty == expected_type) 336 if ty == &expected_type {
337 return true;
338 }
339
340 let ty_without_ref = expected_type.remove_ref().unwrap_or(expected_type);
341 ty.autoderef(db).any(|deref_ty| deref_ty == ty_without_ref)
342} 342}
343 343
344#[cfg(test)] 344#[cfg(test)]
@@ -1001,7 +1001,7 @@ fn main() {
1001 1001
1002 #[test] 1002 #[test]
1003 fn suggest_deref() { 1003 fn suggest_deref() {
1004 check( 1004 check_relevance(
1005 r#" 1005 r#"
1006#[lang = "deref"] 1006#[lang = "deref"]
1007trait Deref { 1007trait Deref {
@@ -1030,82 +1030,13 @@ fn main() {
1030} 1030}
1031 "#, 1031 "#,
1032 expect![[r#" 1032 expect![[r#"
1033 [ 1033 lc t [type]
1034 CompletionItem { 1034 tt Deref []
1035 label: "Deref", 1035 st S []
1036 source_range: 293..293, 1036 st T []
1037 delete: 293..293, 1037 fn foo(…) []
1038 insert: "Deref", 1038 lc m []
1039 kind: SymbolKind( 1039 fn main() []
1040 Trait,
1041 ),
1042 },
1043 CompletionItem {
1044 label: "S",
1045 source_range: 293..293,
1046 delete: 293..293,
1047 insert: "S",
1048 kind: SymbolKind(
1049 Struct,
1050 ),
1051 },
1052 CompletionItem {
1053 label: "T",
1054 source_range: 293..293,
1055 delete: 293..293,
1056 insert: "T",
1057 kind: SymbolKind(
1058 Struct,
1059 ),
1060 },
1061 CompletionItem {
1062 label: "foo(…)",
1063 source_range: 293..293,
1064 delete: 293..293,
1065 insert: "foo(${1:s})$0",
1066 kind: SymbolKind(
1067 Function,
1068 ),
1069 lookup: "foo",
1070 detail: "-> ()",
1071 trigger_call_info: true,
1072 },
1073 CompletionItem {
1074 label: "m",
1075 source_range: 293..293,
1076 delete: 293..293,
1077 insert: "m",
1078 kind: SymbolKind(
1079 Local,
1080 ),
1081 detail: "i32",
1082 },
1083 CompletionItem {
1084 label: "main()",
1085 source_range: 293..293,
1086 delete: 293..293,
1087 insert: "main()$0",
1088 kind: SymbolKind(
1089 Function,
1090 ),
1091 lookup: "main",
1092 detail: "-> ()",
1093 },
1094 CompletionItem {
1095 label: "t",
1096 source_range: 293..293,
1097 delete: 293..293,
1098 insert: "t",
1099 kind: SymbolKind(
1100 Local,
1101 ),
1102 detail: "T",
1103 relevance: CompletionRelevance {
1104 exact_name_match: false,
1105 exact_type_match: true,
1106 },
1107 },
1108 ]
1109 "#]], 1040 "#]],
1110 ) 1041 )
1111 } 1042 }