aboutsummaryrefslogtreecommitdiff
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
parent69689625ce4465f2d008d6543553d0d91d53dca4 (diff)
cleaned up record field builder
-rw-r--r--crates/ra_assists/src/ast_builder.rs7
-rw-r--r--crates/ra_ide_api/src/diagnostics.rs4
2 files changed, 4 insertions, 7 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()),
diff --git a/crates/ra_ide_api/src/diagnostics.rs b/crates/ra_ide_api/src/diagnostics.rs
index 30b95a215..6602fd27e 100644
--- a/crates/ra_ide_api/src/diagnostics.rs
+++ b/crates/ra_ide_api/src/diagnostics.rs
@@ -59,7 +59,9 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic>
59 let node = d.ast(db); 59 let node = d.ast(db);
60 let mut ast_editor = AstEditor::new(node); 60 let mut ast_editor = AstEditor::new(node);
61 for f in d.missed_fields.iter() { 61 for f in d.missed_fields.iter() {
62 ast_editor.append_field(&AstBuilder::<RecordField>::from_name(f)); 62 let name_ref = AstBuilder::<ast::NameRef>::new(&f.to_string());
63 let unit = AstBuilder::<ast::Expr>::unit();
64 ast_editor.append_field(&AstBuilder::<RecordField>::from_pieces(name_ref, Some(unit)));
63 } 65 }
64 66
65 let mut builder = TextEditBuilder::default(); 67 let mut builder = TextEditBuilder::default();