From f823386db85ec1f0ee973b9c0534a9902dbcc2e2 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 14 Jul 2020 13:46:29 +0200 Subject: Add mark --- crates/ra_ide/src/completion/presentation.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'crates') diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs index 48afee5fb..e23971526 100644 --- a/crates/ra_ide/src/completion/presentation.rs +++ b/crates/ra_ide/src/completion/presentation.rs @@ -315,6 +315,7 @@ impl Completions { } if variant_kind == StructKind::Tuple { + mark::hit!(inserts_parens_for_tuple_enums); let params = Params::Anonymous(variant.fields(ctx.db).len()); res = res.add_call_parens(ctx, qualified_name, params) } @@ -865,6 +866,7 @@ fn main() { foo(${1:foo}, ${2:bar}, ${3:ho_ge_})$0 } #[test] fn inserts_parens_for_tuple_enums() { + mark::check!(inserts_parens_for_tuple_enums); check_edit( "Some", r#" -- cgit v1.2.3 From f7f4ea633b974cf90fb69120ff23908990a24bda Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 14 Jul 2020 13:51:43 +0200 Subject: Don't duplicate parens in patterns --- crates/ra_ide/src/completion/completion_context.rs | 5 ++++ crates/ra_ide/src/completion/presentation.rs | 33 +++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) (limited to 'crates') diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index 3d93f7067..9e82d6854 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -63,6 +63,8 @@ pub(crate) struct CompletionContext<'a> { pub(super) dot_receiver_is_ambiguous_float_literal: bool, /// If this is a call (method or function) in particular, i.e. the () are already there. pub(super) is_call: bool, + /// Like `is_call`, but for tuple patterns. + pub(super) is_pattern_call: bool, /// If this is a macro call, i.e. the () are already there. pub(super) is_macro_call: bool, pub(super) is_path_type: bool, @@ -136,6 +138,7 @@ impl<'a> CompletionContext<'a> { is_new_item: false, dot_receiver: None, is_call: false, + is_pattern_call: false, is_macro_call: false, is_path_type: false, has_type_args: false, @@ -370,6 +373,8 @@ impl<'a> CompletionContext<'a> { .and_then(|it| it.syntax().parent().and_then(ast::CallExpr::cast)) .is_some(); self.is_macro_call = path.syntax().parent().and_then(ast::MacroCall::cast).is_some(); + self.is_pattern_call = + path.syntax().parent().and_then(ast::TupleStructPat::cast).is_some(); self.is_path_type = path.syntax().parent().and_then(ast::PathType::cast).is_some(); self.has_type_args = segment.type_arg_list().is_some(); diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs index e23971526..64349dcb8 100644 --- a/crates/ra_ide/src/completion/presentation.rs +++ b/crates/ra_ide/src/completion/presentation.rs @@ -384,10 +384,17 @@ impl Builder { if !ctx.config.add_call_parenthesis { return self; } - if ctx.use_item_syntax.is_some() || ctx.is_call { + if ctx.use_item_syntax.is_some() { mark::hit!(no_parens_in_use_item); return self; } + if ctx.is_pattern_call { + mark::hit!(dont_duplicate_pattern_parens); + return self; + } + if ctx.is_call { + return self; + } // Don't add parentheses if the expected type is some function reference. if let Some(ty) = &ctx.expected_type { @@ -907,6 +914,30 @@ fn main(value: Option) { ); } + #[test] + fn dont_duplicate_pattern_parens() { + mark::check!(dont_duplicate_pattern_parens); + check_edit( + "Var", + r#" +enum E { Var(i32) } +fn main() { + match E::Var(92) { + E::<|>(92) => (), + } +} +"#, + r#" +enum E { Var(i32) } +fn main() { + match E::Var(92) { + E::Var(92) => (), + } +} +"#, + ); + } + #[test] fn no_call_parens_if_fn_ptr_needed() { mark::check!(no_call_parens_if_fn_ptr_needed); -- cgit v1.2.3