diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index 3d93f70674..9e82d68541 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 e23971526f..64349dcb83 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);