diff options
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r-- | crates/ra_syntax/src/ast/edit.rs | 6 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/make.rs | 17 |
2 files changed, 20 insertions, 3 deletions
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs index df4ffefbf..f74c9f9c6 100644 --- a/crates/ra_syntax/src/ast/edit.rs +++ b/crates/ra_syntax/src/ast/edit.rs | |||
@@ -334,11 +334,11 @@ impl ast::UseTree { | |||
334 | } | 334 | } |
335 | 335 | ||
336 | #[must_use] | 336 | #[must_use] |
337 | pub fn strip_attrs_and_docs<N: ast::AttrsOwner>(node: &N) -> N { | 337 | pub fn remove_attrs_and_docs<N: ast::AttrsOwner>(node: &N) -> N { |
338 | N::cast(strip_attrs_and_docs_inner(node.syntax().clone())).unwrap() | 338 | N::cast(remove_attrs_and_docs_inner(node.syntax().clone())).unwrap() |
339 | } | 339 | } |
340 | 340 | ||
341 | fn strip_attrs_and_docs_inner(mut node: SyntaxNode) -> SyntaxNode { | 341 | fn remove_attrs_and_docs_inner(mut node: SyntaxNode) -> SyntaxNode { |
342 | while let Some(start) = | 342 | while let Some(start) = |
343 | node.children_with_tokens().find(|it| it.kind() == ATTR || it.kind() == COMMENT) | 343 | node.children_with_tokens().find(|it| it.kind() == ATTR || it.kind() == COMMENT) |
344 | { | 344 | { |
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index 9f6f1cc53..1145b69e8 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs | |||
@@ -87,6 +87,9 @@ pub fn block_from_expr(e: ast::Expr) -> ast::Block { | |||
87 | pub fn expr_unit() -> ast::Expr { | 87 | pub fn expr_unit() -> ast::Expr { |
88 | expr_from_text("()") | 88 | expr_from_text("()") |
89 | } | 89 | } |
90 | pub fn expr_empty_block() -> ast::Expr { | ||
91 | expr_from_text("{}") | ||
92 | } | ||
90 | pub fn expr_unimplemented() -> ast::Expr { | 93 | pub fn expr_unimplemented() -> ast::Expr { |
91 | expr_from_text("unimplemented!()") | 94 | expr_from_text("unimplemented!()") |
92 | } | 95 | } |
@@ -136,6 +139,20 @@ pub fn placeholder_pat() -> ast::PlaceholderPat { | |||
136 | } | 139 | } |
137 | } | 140 | } |
138 | 141 | ||
142 | /// Creates a tuple of patterns from an interator of patterns. | ||
143 | /// | ||
144 | /// Invariant: `pats` must be length > 1 | ||
145 | /// | ||
146 | /// FIXME handle `pats` length == 1 | ||
147 | pub fn tuple_pat(pats: impl IntoIterator<Item = ast::Pat>) -> ast::TuplePat { | ||
148 | let pats_str = pats.into_iter().map(|p| p.to_string()).join(", "); | ||
149 | return from_text(&format!("({})", pats_str)); | ||
150 | |||
151 | fn from_text(text: &str) -> ast::TuplePat { | ||
152 | ast_from_text(&format!("fn f({}: ())", text)) | ||
153 | } | ||
154 | } | ||
155 | |||
139 | pub fn tuple_struct_pat( | 156 | pub fn tuple_struct_pat( |
140 | path: ast::Path, | 157 | path: ast::Path, |
141 | pats: impl IntoIterator<Item = ast::Pat>, | 158 | pats: impl IntoIterator<Item = ast::Pat>, |