From 25fca0475343170b8398f5c87c76c455205ed3c4 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 25 Sep 2019 15:09:03 +0300 Subject: cleaned up record field builder --- crates/ra_assists/src/ast_builder.rs | 7 +------ crates/ra_ide_api/src/diagnostics.rs | 4 +++- 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 @@ use itertools::Itertools; -use hir::Name; use ra_syntax::{ast, AstNode, SourceFile}; pub struct AstBuilder { @@ -8,15 +7,11 @@ pub struct AstBuilder { } impl AstBuilder { - pub fn from_name(name: &Name) -> ast::RecordField { - ast_node_from_file_text(&format!("fn f() {{ S {{ {}: (), }} }}", name)) - } - fn from_text(text: &str) -> ast::RecordField { ast_node_from_file_text(&format!("fn f() {{ S {{ {}, }} }}", text)) } - pub fn from_pieces(name: &ast::NameRef, expr: Option<&ast::Expr>) -> ast::RecordField { + pub fn from_pieces(name: ast::NameRef, expr: Option) -> ast::RecordField { match expr { Some(expr) => Self::from_text(&format!("{}: {}", name.syntax(), expr.syntax())), 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 let node = d.ast(db); let mut ast_editor = AstEditor::new(node); for f in d.missed_fields.iter() { - ast_editor.append_field(&AstBuilder::::from_name(f)); + let name_ref = AstBuilder::::new(&f.to_string()); + let unit = AstBuilder::::unit(); + ast_editor.append_field(&AstBuilder::::from_pieces(name_ref, Some(unit))); } let mut builder = TextEditBuilder::default(); -- cgit v1.2.3