From 2afccbe47727d9d2787f76efd67f5b5d9ff1d55a Mon Sep 17 00:00:00 2001 From: Josh Mcguigan Date: Sun, 22 Mar 2020 22:42:32 -0700 Subject: implement fill match arm assist for tuple of enums --- crates/ra_syntax/src/ast/make.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'crates/ra_syntax/src/ast') diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index 9f6f1cc53..9d8ed6238 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs @@ -136,6 +136,15 @@ pub fn placeholder_pat() -> ast::PlaceholderPat { } } +pub fn tuple_pat(pats: impl IntoIterator) -> ast::TuplePat { + let pats_str = pats.into_iter().map(|p| p.syntax().to_string()).join(", "); + return from_text(&format!("({})", pats_str)); + + fn from_text(text: &str) -> ast::TuplePat { + ast_from_text(&format!("fn f({}: ())", text)) + } +} + pub fn tuple_struct_pat( path: ast::Path, pats: impl IntoIterator, -- cgit v1.2.3 From bc48c9d5116f08efea26da94c82a3eaa1622fc5d Mon Sep 17 00:00:00 2001 From: Josh Mcguigan Date: Mon, 23 Mar 2020 05:19:09 -0700 Subject: review comments --- crates/ra_syntax/src/ast/make.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'crates/ra_syntax/src/ast') diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index 9d8ed6238..9257ccd1a 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs @@ -136,8 +136,13 @@ pub fn placeholder_pat() -> ast::PlaceholderPat { } } +/// Creates a tuple of patterns from an interator of patterns. +/// +/// Invariant: `pats` must be length > 1 +/// +/// FIXME handle `pats` length == 1 pub fn tuple_pat(pats: impl IntoIterator) -> ast::TuplePat { - let pats_str = pats.into_iter().map(|p| p.syntax().to_string()).join(", "); + let pats_str = pats.into_iter().map(|p| p.to_string()).join(", "); return from_text(&format!("({})", pats_str)); fn from_text(text: &str) -> ast::TuplePat { -- cgit v1.2.3