aboutsummaryrefslogtreecommitdiff
path: root/crates/syntax/src
diff options
context:
space:
mode:
authorunexge <[email protected]>2021-04-03 22:04:31 +0100
committerunexge <[email protected]>2021-04-04 18:52:43 +0100
commit8d4be829e09dae4af7b4a82b379fdb8700b0929f (patch)
tree860e45f32fc34b5f443addd04583658118ad2daa /crates/syntax/src
parentd3a112d68c74cbd02630f6c909071c94872c193f (diff)
Add convert tuple struct to named struct assist
Diffstat (limited to 'crates/syntax/src')
-rw-r--r--crates/syntax/src/ast/make.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs
index c6a7b99b7..3a588e540 100644
--- a/crates/syntax/src/ast/make.rs
+++ b/crates/syntax/src/ast/make.rs
@@ -133,6 +133,17 @@ pub fn use_(visibility: Option<ast::Visibility>, use_tree: ast::UseTree) -> ast:
133 ast_from_text(&format!("{}use {};", visibility, use_tree)) 133 ast_from_text(&format!("{}use {};", visibility, use_tree))
134} 134}
135 135
136pub fn record_expr(path: ast::Path, fields: ast::RecordExprFieldList) -> ast::RecordExpr {
137 ast_from_text(&format!("fn f() {{ {} {} }}", path, fields))
138}
139
140pub fn record_expr_field_list(
141 fields: impl IntoIterator<Item = ast::RecordExprField>,
142) -> ast::RecordExprFieldList {
143 let fields = fields.into_iter().join(", ");
144 ast_from_text(&format!("fn f() {{ S {{ {} }} }}", fields))
145}
146
136pub fn record_expr_field(name: ast::NameRef, expr: Option<ast::Expr>) -> ast::RecordExprField { 147pub fn record_expr_field(name: ast::NameRef, expr: Option<ast::Expr>) -> ast::RecordExprField {
137 return match expr { 148 return match expr {
138 Some(expr) => from_text(&format!("{}: {}", name, expr)), 149 Some(expr) => from_text(&format!("{}: {}", name, expr)),
@@ -325,6 +336,21 @@ pub fn record_pat(path: ast::Path, pats: impl IntoIterator<Item = ast::Pat>) ->
325 } 336 }
326} 337}
327 338
339pub fn record_pat_with_fields(path: ast::Path, fields: ast::RecordPatFieldList) -> ast::RecordPat {
340 ast_from_text(&format!("fn f({} {}: ()))", path, fields))
341}
342
343pub fn record_pat_field_list(
344 fields: impl IntoIterator<Item = ast::RecordPatField>,
345) -> ast::RecordPatFieldList {
346 let fields = fields.into_iter().join(", ");
347 ast_from_text(&format!("fn f(S {{ {} }}: ()))", fields))
348}
349
350pub fn record_pat_field(name_ref: ast::NameRef, pat: ast::Pat) -> ast::RecordPatField {
351 ast_from_text(&format!("fn f(S {{ {}: {} }}: ()))", name_ref, pat))
352}
353
328/// Returns a `BindPat` if the path has just one segment, a `PathPat` otherwise. 354/// Returns a `BindPat` if the path has just one segment, a `PathPat` otherwise.
329pub fn path_pat(path: ast::Path) -> ast::Pat { 355pub fn path_pat(path: ast::Path) -> ast::Pat {
330 return from_text(&path.to_string()); 356 return from_text(&path.to_string());