aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-09-25 13:09:03 +0100
committerAleksey Kladov <[email protected]>2019-09-25 13:09:03 +0100
commit25fca0475343170b8398f5c87c76c455205ed3c4 (patch)
tree6d756bd77bda4649a5e6ebc748e761d7551752f6 /crates/ra_assists
parent69689625ce4465f2d008d6543553d0d91d53dca4 (diff)
cleaned up record field builder
Diffstat (limited to 'crates/ra_assists')
-rw-r--r--crates/ra_assists/src/ast_builder.rs7
1 files changed, 1 insertions, 6 deletions
diff --git a/crates/ra_assists/src/ast_builder.rs b/crates/ra_assists/src/ast_builder.rs
index e4ea1fca9..9b9158ae2 100644
--- a/crates/ra_assists/src/ast_builder.rs
+++ b/crates/ra_assists/src/ast_builder.rs
@@ -1,6 +1,5 @@
1use itertools::Itertools; 1use itertools::Itertools;
2 2
3use hir::Name;
4use ra_syntax::{ast, AstNode, SourceFile}; 3use ra_syntax::{ast, AstNode, SourceFile};
5 4
6pub struct AstBuilder<N: AstNode> { 5pub struct AstBuilder<N: AstNode> {
@@ -8,15 +7,11 @@ pub struct AstBuilder<N: AstNode> {
8} 7}
9 8
10impl AstBuilder<ast::RecordField> { 9impl AstBuilder<ast::RecordField> {
11 pub fn from_name(name: &Name) -> ast::RecordField {
12 ast_node_from_file_text(&format!("fn f() {{ S {{ {}: (), }} }}", name))
13 }
14
15 fn from_text(text: &str) -> ast::RecordField { 10 fn from_text(text: &str) -> ast::RecordField {
16 ast_node_from_file_text(&format!("fn f() {{ S {{ {}, }} }}", text)) 11 ast_node_from_file_text(&format!("fn f() {{ S {{ {}, }} }}", text))
17 } 12 }
18 13
19 pub fn from_pieces(name: &ast::NameRef, expr: Option<&ast::Expr>) -> ast::RecordField { 14 pub fn from_pieces(name: ast::NameRef, expr: Option<ast::Expr>) -> ast::RecordField {
20 match expr { 15 match expr {
21 Some(expr) => Self::from_text(&format!("{}: {}", name.syntax(), expr.syntax())), 16 Some(expr) => Self::from_text(&format!("{}: {}", name.syntax(), expr.syntax())),
22 None => Self::from_text(&name.syntax().to_string()), 17 None => Self::from_text(&name.syntax().to_string()),