diff options
-rw-r--r-- | crates/ide_completion/src/render.rs | 76 |
1 files changed, 42 insertions, 34 deletions
diff --git a/crates/ide_completion/src/render.rs b/crates/ide_completion/src/render.rs index 0c1169ecb..ede4aa807 100644 --- a/crates/ide_completion/src/render.rs +++ b/crates/ide_completion/src/render.rs | |||
@@ -343,7 +343,6 @@ mod tests { | |||
343 | use std::cmp::Reverse; | 343 | use std::cmp::Reverse; |
344 | 344 | ||
345 | use expect_test::{expect, Expect}; | 345 | use expect_test::{expect, Expect}; |
346 | use hir::Mutability; | ||
347 | 346 | ||
348 | use crate::{ | 347 | use crate::{ |
349 | test_utils::{check_edit, do_completion, get_all_items, TEST_CONFIG}, | 348 | test_utils::{check_edit, do_completion, get_all_items, TEST_CONFIG}, |
@@ -367,33 +366,39 @@ mod tests { | |||
367 | } | 366 | } |
368 | } | 367 | } |
369 | 368 | ||
370 | fn display_label(label: &str, mutability: Option<Mutability>) -> String { | ||
371 | let mutability_label = match mutability { | ||
372 | Some(Mutability::Shared) => "&", | ||
373 | Some(Mutability::Mut) => "&mut ", | ||
374 | None => "", | ||
375 | }; | ||
376 | |||
377 | format!("{}{}", mutability_label, label) | ||
378 | } | ||
379 | |||
380 | let mut completions = get_all_items(TEST_CONFIG, ra_fixture); | 369 | let mut completions = get_all_items(TEST_CONFIG, ra_fixture); |
381 | completions.sort_by_key(|it| { | 370 | completions.sort_by_key(|it| { |
382 | (Reverse(it.ref_match().map(|m| m.1).unwrap_or(it.relevance())), it.label().to_string()) | 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 | } | ||
383 | }); | 379 | }); |
380 | |||
384 | let actual = completions | 381 | let actual = completions |
385 | .into_iter() | 382 | .into_iter() |
386 | .filter(|it| it.completion_kind == CompletionKind::Reference) | 383 | .filter(|it| it.completion_kind == CompletionKind::Reference) |
387 | .map(|it| { | 384 | .flat_map(|it| { |
385 | let mut items = vec![]; | ||
386 | |||
388 | let tag = it.kind().unwrap().tag(); | 387 | let tag = it.kind().unwrap().tag(); |
389 | let (mutability, relevance) = it | 388 | let relevance = display_relevance(it.relevance()); |
390 | .ref_match() | 389 | items.push(format!("{} {} {}\n", tag, it.label(), relevance)); |
391 | .map(|(mutability, relevance)| (Some(mutability), relevance)) | 390 | |
392 | .unwrap_or((None, it.relevance())); | 391 | if let Some((mutability, relevance)) = it.ref_match() { |
393 | let relevance = display_relevance(relevance); | 392 | let label = format!("&{}{}", mutability.as_keyword_for_ref(), it.label()); |
394 | format!("{} {} {}\n", tag, display_label(it.label(), mutability), relevance) | 393 | let relevance = display_relevance(relevance); |
394 | |||
395 | items.push(format!("{} {} {}\n", tag, label, relevance)); | ||
396 | } | ||
397 | |||
398 | items | ||
395 | }) | 399 | }) |
396 | .collect::<String>(); | 400 | .collect::<String>(); |
401 | |||
397 | expect.assert_eq(&actual); | 402 | expect.assert_eq(&actual); |
398 | } | 403 | } |
399 | 404 | ||
@@ -898,8 +903,8 @@ fn foo(a: A) { B { bar: f(a.$0) }; } | |||
898 | "#, | 903 | "#, |
899 | expect![[r#" | 904 | expect![[r#" |
900 | fd foo [type+name] | 905 | fd foo [type+name] |
901 | fd bar [] | ||
902 | fd baz [] | 906 | fd baz [] |
907 | fd bar [] | ||
903 | "#]], | 908 | "#]], |
904 | ); | 909 | ); |
905 | check_relevance( | 910 | check_relevance( |
@@ -925,9 +930,10 @@ struct WorldSnapshot { _f: () }; | |||
925 | fn go(world: &WorldSnapshot) { go(w$0) } | 930 | fn go(world: &WorldSnapshot) { go(w$0) } |
926 | "#, | 931 | "#, |
927 | expect![[r#" | 932 | expect![[r#" |
933 | lc world [type+name] | ||
928 | lc &world [type+name] | 934 | lc &world [type+name] |
929 | st WorldSnapshot [] | ||
930 | fn go(…) [] | 935 | fn go(…) [] |
936 | st WorldSnapshot [] | ||
931 | "#]], | 937 | "#]], |
932 | ); | 938 | ); |
933 | } | 939 | } |
@@ -940,9 +946,9 @@ struct Foo; | |||
940 | fn f(foo: &Foo) { f(foo, w$0) } | 946 | fn f(foo: &Foo) { f(foo, w$0) } |
941 | "#, | 947 | "#, |
942 | expect![[r#" | 948 | expect![[r#" |
943 | st Foo [] | ||
944 | fn f(…) [] | ||
945 | lc foo [] | 949 | lc foo [] |
950 | fn f(…) [] | ||
951 | st Foo [] | ||
946 | "#]], | 952 | "#]], |
947 | ); | 953 | ); |
948 | } | 954 | } |
@@ -1044,13 +1050,14 @@ fn main() { | |||
1044 | } | 1050 | } |
1045 | "#, | 1051 | "#, |
1046 | expect![[r#" | 1052 | expect![[r#" |
1053 | lc t [] | ||
1047 | lc &t [type] | 1054 | lc &t [type] |
1048 | tt Deref [] | ||
1049 | st S [] | ||
1050 | st T [] | ||
1051 | fn foo(…) [] | ||
1052 | lc m [] | ||
1053 | fn main() [] | 1055 | fn main() [] |
1056 | lc m [] | ||
1057 | fn foo(…) [] | ||
1058 | st T [] | ||
1059 | st S [] | ||
1060 | tt Deref [] | ||
1054 | "#]], | 1061 | "#]], |
1055 | ) | 1062 | ) |
1056 | } | 1063 | } |
@@ -1097,14 +1104,15 @@ fn main() { | |||
1097 | } | 1104 | } |
1098 | "#, | 1105 | "#, |
1099 | expect![[r#" | 1106 | expect![[r#" |
1107 | lc t [] | ||
1100 | lc &mut t [type] | 1108 | lc &mut t [type] |
1101 | tt Deref [] | ||
1102 | tt DerefMut [] | ||
1103 | st S [] | ||
1104 | st T [] | ||
1105 | fn foo(…) [] | ||
1106 | lc m [] | ||
1107 | fn main() [] | 1109 | fn main() [] |
1110 | lc m [] | ||
1111 | fn foo(…) [] | ||
1112 | st T [] | ||
1113 | st S [] | ||
1114 | tt DerefMut [] | ||
1115 | tt Deref [] | ||
1108 | "#]], | 1116 | "#]], |
1109 | ) | 1117 | ) |
1110 | } | 1118 | } |