aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/completion/presentation.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/completion/presentation.rs')
-rw-r--r--crates/ra_ide/src/completion/presentation.rs35
1 files changed, 34 insertions, 1 deletions
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs
index 48afee5fb..64349dcb8 100644
--- a/crates/ra_ide/src/completion/presentation.rs
+++ b/crates/ra_ide/src/completion/presentation.rs
@@ -315,6 +315,7 @@ impl Completions {
315 } 315 }
316 316
317 if variant_kind == StructKind::Tuple { 317 if variant_kind == StructKind::Tuple {
318 mark::hit!(inserts_parens_for_tuple_enums);
318 let params = Params::Anonymous(variant.fields(ctx.db).len()); 319 let params = Params::Anonymous(variant.fields(ctx.db).len());
319 res = res.add_call_parens(ctx, qualified_name, params) 320 res = res.add_call_parens(ctx, qualified_name, params)
320 } 321 }
@@ -383,10 +384,17 @@ impl Builder {
383 if !ctx.config.add_call_parenthesis { 384 if !ctx.config.add_call_parenthesis {
384 return self; 385 return self;
385 } 386 }
386 if ctx.use_item_syntax.is_some() || ctx.is_call { 387 if ctx.use_item_syntax.is_some() {
387 mark::hit!(no_parens_in_use_item); 388 mark::hit!(no_parens_in_use_item);
388 return self; 389 return self;
389 } 390 }
391 if ctx.is_pattern_call {
392 mark::hit!(dont_duplicate_pattern_parens);
393 return self;
394 }
395 if ctx.is_call {
396 return self;
397 }
390 398
391 // Don't add parentheses if the expected type is some function reference. 399 // Don't add parentheses if the expected type is some function reference.
392 if let Some(ty) = &ctx.expected_type { 400 if let Some(ty) = &ctx.expected_type {
@@ -865,6 +873,7 @@ fn main() { foo(${1:foo}, ${2:bar}, ${3:ho_ge_})$0 }
865 873
866 #[test] 874 #[test]
867 fn inserts_parens_for_tuple_enums() { 875 fn inserts_parens_for_tuple_enums() {
876 mark::check!(inserts_parens_for_tuple_enums);
868 check_edit( 877 check_edit(
869 "Some", 878 "Some",
870 r#" 879 r#"
@@ -906,6 +915,30 @@ fn main(value: Option<i32>) {
906 } 915 }
907 916
908 #[test] 917 #[test]
918 fn dont_duplicate_pattern_parens() {
919 mark::check!(dont_duplicate_pattern_parens);
920 check_edit(
921 "Var",
922 r#"
923enum E { Var(i32) }
924fn main() {
925 match E::Var(92) {
926 E::<|>(92) => (),
927 }
928}
929"#,
930 r#"
931enum E { Var(i32) }
932fn main() {
933 match E::Var(92) {
934 E::Var(92) => (),
935 }
936}
937"#,
938 );
939 }
940
941 #[test]
909 fn no_call_parens_if_fn_ptr_needed() { 942 fn no_call_parens_if_fn_ptr_needed() {
910 mark::check!(no_call_parens_if_fn_ptr_needed); 943 mark::check!(no_call_parens_if_fn_ptr_needed);
911 check_edit( 944 check_edit(