From 6f8aa75329d0a4e588e58b8f22f7932bf3d3a706 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 16:21:30 +0200 Subject: Rename RecordLit -> RecordExpr --- crates/ra_syntax/src/ast/edit.rs | 10 +++--- crates/ra_syntax/src/ast/expr_ext.rs | 6 ++-- crates/ra_syntax/src/ast/generated/nodes.rs | 50 +++++++++++++++-------------- crates/ra_syntax/src/ast/make.rs | 4 +-- crates/ra_syntax/src/ast/node_ext.rs | 8 ++--- 5 files changed, 40 insertions(+), 38 deletions(-) (limited to 'crates/ra_syntax/src/ast') diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs index 0110300af..8d3e42f25 100644 --- a/crates/ra_syntax/src/ast/edit.rs +++ b/crates/ra_syntax/src/ast/edit.rs @@ -116,18 +116,18 @@ impl ast::AssocItemList { } } -impl ast::RecordFieldList { +impl ast::RecordExprFieldList { #[must_use] - pub fn append_field(&self, field: &ast::RecordField) -> ast::RecordFieldList { + pub fn append_field(&self, field: &ast::RecordExprField) -> ast::RecordExprFieldList { self.insert_field(InsertPosition::Last, field) } #[must_use] pub fn insert_field( &self, - position: InsertPosition<&'_ ast::RecordField>, - field: &ast::RecordField, - ) -> ast::RecordFieldList { + position: InsertPosition<&'_ ast::RecordExprField>, + field: &ast::RecordExprField, + ) -> ast::RecordExprFieldList { let is_multiline = self.syntax().text().contains_char('\n'); let ws; let space = if is_multiline { diff --git a/crates/ra_syntax/src/ast/expr_ext.rs b/crates/ra_syntax/src/ast/expr_ext.rs index 8692b9bb5..365f94287 100644 --- a/crates/ra_syntax/src/ast/expr_ext.rs +++ b/crates/ra_syntax/src/ast/expr_ext.rs @@ -412,8 +412,8 @@ fn test_literal_with_attr() { assert_eq!(lit.token().text(), r#""Hello""#); } -impl ast::RecordField { - pub fn parent_record_lit(&self) -> ast::RecordLit { - self.syntax().ancestors().find_map(ast::RecordLit::cast).unwrap() +impl ast::RecordExprField { + pub fn parent_record_lit(&self) -> ast::RecordExpr { + self.syntax().ancestors().find_map(ast::RecordExpr::cast).unwrap() } } diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index efe0cbe3a..9f9c06e50 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -909,30 +909,32 @@ impl MatchGuard { pub fn expr(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct RecordLit { +pub struct RecordExpr { pub(crate) syntax: SyntaxNode, } -impl RecordLit { +impl RecordExpr { pub fn path(&self) -> Option { support::child(&self.syntax) } - pub fn record_field_list(&self) -> Option { support::child(&self.syntax) } + pub fn record_expr_field_list(&self) -> Option { + support::child(&self.syntax) + } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct RecordFieldList { +pub struct RecordExprFieldList { pub(crate) syntax: SyntaxNode, } -impl RecordFieldList { +impl RecordExprFieldList { pub fn l_curly_token(&self) -> Option { support::token(&self.syntax, T!['{']) } - pub fn fields(&self) -> AstChildren { support::children(&self.syntax) } + pub fn fields(&self) -> AstChildren { support::children(&self.syntax) } pub fn dotdot_token(&self) -> Option { support::token(&self.syntax, T![..]) } pub fn spread(&self) -> Option { support::child(&self.syntax) } pub fn r_curly_token(&self) -> Option { support::token(&self.syntax, T!['}']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct RecordField { +pub struct RecordExprField { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for RecordField {} -impl RecordField { +impl ast::AttrsOwner for RecordExprField {} +impl RecordExprField { pub fn name_ref(&self) -> Option { support::child(&self.syntax) } pub fn colon_token(&self) -> Option { support::token(&self.syntax, T![:]) } pub fn expr(&self) -> Option { support::child(&self.syntax) } @@ -1345,7 +1347,7 @@ pub enum Expr { BlockExpr(BlockExpr), ReturnExpr(ReturnExpr), MatchExpr(MatchExpr), - RecordLit(RecordLit), + RecordExpr(RecordExpr), CallExpr(CallExpr), IndexExpr(IndexExpr), MethodCallExpr(MethodCallExpr), @@ -2357,8 +2359,8 @@ impl AstNode for MatchGuard { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for RecordLit { - fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_LIT } +impl AstNode for RecordExpr { + fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_EXPR } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -2368,8 +2370,8 @@ impl AstNode for RecordLit { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for RecordFieldList { - fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_LIST } +impl AstNode for RecordExprFieldList { + fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_EXPR_FIELD_LIST } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -2379,8 +2381,8 @@ impl AstNode for RecordFieldList { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for RecordField { - fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD } +impl AstNode for RecordExprField { + fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_EXPR_FIELD } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -3119,8 +3121,8 @@ impl From for Expr { impl From for Expr { fn from(node: MatchExpr) -> Expr { Expr::MatchExpr(node) } } -impl From for Expr { - fn from(node: RecordLit) -> Expr { Expr::RecordLit(node) } +impl From for Expr { + fn from(node: RecordExpr) -> Expr { Expr::RecordExpr(node) } } impl From for Expr { fn from(node: CallExpr) -> Expr { Expr::CallExpr(node) } @@ -3172,7 +3174,7 @@ impl AstNode for Expr { match kind { TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL - | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | RECORD_LIT | CALL_EXPR | INDEX_EXPR + | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | RECORD_EXPR | CALL_EXPR | INDEX_EXPR | METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | EFFECT_EXPR | CAST_EXPR | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL | BOX_EXPR => { true @@ -3197,7 +3199,7 @@ impl AstNode for Expr { BLOCK_EXPR => Expr::BlockExpr(BlockExpr { syntax }), RETURN_EXPR => Expr::ReturnExpr(ReturnExpr { syntax }), MATCH_EXPR => Expr::MatchExpr(MatchExpr { syntax }), - RECORD_LIT => Expr::RecordLit(RecordLit { syntax }), + RECORD_EXPR => Expr::RecordExpr(RecordExpr { syntax }), CALL_EXPR => Expr::CallExpr(CallExpr { syntax }), INDEX_EXPR => Expr::IndexExpr(IndexExpr { syntax }), METHOD_CALL_EXPR => Expr::MethodCallExpr(MethodCallExpr { syntax }), @@ -3234,7 +3236,7 @@ impl AstNode for Expr { Expr::BlockExpr(it) => &it.syntax, Expr::ReturnExpr(it) => &it.syntax, Expr::MatchExpr(it) => &it.syntax, - Expr::RecordLit(it) => &it.syntax, + Expr::RecordExpr(it) => &it.syntax, Expr::CallExpr(it) => &it.syntax, Expr::IndexExpr(it) => &it.syntax, Expr::MethodCallExpr(it) => &it.syntax, @@ -3893,17 +3895,17 @@ impl std::fmt::Display for MatchGuard { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for RecordLit { +impl std::fmt::Display for RecordExpr { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for RecordFieldList { +impl std::fmt::Display for RecordExprFieldList { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for RecordField { +impl std::fmt::Display for RecordExprField { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index 4759f23a5..183ec4481 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs @@ -64,13 +64,13 @@ pub fn use_item(use_tree: ast::UseTree) -> ast::Use { ast_from_text(&format!("use {};", use_tree)) } -pub fn record_field(name: ast::NameRef, expr: Option) -> ast::RecordField { +pub fn record_field(name: ast::NameRef, expr: Option) -> ast::RecordExprField { return match expr { Some(expr) => from_text(&format!("{}: {}", name, expr)), None => from_text(&name.to_string()), }; - fn from_text(text: &str) -> ast::RecordField { + fn from_text(text: &str) -> ast::RecordExprField { ast_from_text(&format!("fn f() {{ S {{ {}, }} }}", text)) } } diff --git a/crates/ra_syntax/src/ast/node_ext.rs b/crates/ra_syntax/src/ast/node_ext.rs index a7a301d6b..8c7457e32 100644 --- a/crates/ra_syntax/src/ast/node_ext.rs +++ b/crates/ra_syntax/src/ast/node_ext.rs @@ -189,11 +189,11 @@ impl ast::StructDef { } } -impl ast::RecordField { - pub fn for_field_name(field_name: &ast::NameRef) -> Option { +impl ast::RecordExprField { + pub fn for_field_name(field_name: &ast::NameRef) -> Option { let candidate = - field_name.syntax().parent().and_then(ast::RecordField::cast).or_else(|| { - field_name.syntax().ancestors().nth(4).and_then(ast::RecordField::cast) + field_name.syntax().parent().and_then(ast::RecordExprField::cast).or_else(|| { + field_name.syntax().ancestors().nth(4).and_then(ast::RecordExprField::cast) })?; if candidate.field_name().as_ref() == Some(field_name) { Some(candidate) -- cgit v1.2.3