From 2984da672e0c73d56501c6b6e4d19fd28152b5eb Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 11:42:51 +0200 Subject: Split ItemList & AssocItemList --- crates/ra_syntax/src/ast/edit.rs | 9 ++-- crates/ra_syntax/src/ast/generated/nodes.rs | 71 ++++++++++++++++++++--------- 2 files changed, 56 insertions(+), 24 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 abc7a646c..01a310f66 100644 --- a/crates/ra_syntax/src/ast/edit.rs +++ b/crates/ra_syntax/src/ast/edit.rs @@ -80,9 +80,12 @@ where } } -impl ast::ItemList { +impl ast::AssocItemList { #[must_use] - pub fn append_items(&self, items: impl IntoIterator) -> ast::ItemList { + pub fn append_items( + &self, + items: impl IntoIterator, + ) -> ast::AssocItemList { let mut res = self.clone(); if !self.syntax().text().contains_char('\n') { res = make_multiline(res); @@ -92,7 +95,7 @@ impl ast::ItemList { } #[must_use] - pub fn append_item(&self, item: ast::AssocItem) -> ast::ItemList { + pub fn append_item(&self, item: ast::AssocItem) -> ast::AssocItemList { let (indent, position) = match self.assoc_items().last() { Some(it) => ( leading_indent(it.syntax()).unwrap_or_default().to_string(), diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index dfda79550..7ccb7ea7f 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -112,7 +112,7 @@ impl ImplDef { pub fn impl_token(&self) -> Option { support::token(&self.syntax, T![impl]) } pub fn excl_token(&self) -> Option { support::token(&self.syntax, T![!]) } pub fn for_token(&self) -> Option { support::token(&self.syntax, T![for]) } - pub fn item_list(&self) -> Option { support::child(&self.syntax) } + pub fn assoc_item_list(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct MacroCall { @@ -180,7 +180,7 @@ impl TraitDef { pub fn unsafe_token(&self) -> Option { support::token(&self.syntax, T![unsafe]) } pub fn auto_token(&self) -> Option { support::token(&self.syntax, T![auto]) } pub fn trait_token(&self) -> Option { support::token(&self.syntax, T![trait]) } - pub fn item_list(&self) -> Option { support::child(&self.syntax) } + pub fn assoc_item_list(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TypeAliasDef { @@ -238,11 +238,6 @@ impl Visibility { pub fn r_paren_token(&self) -> Option { support::token(&self.syntax, T![')']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Abi { - pub(crate) syntax: SyntaxNode, -} -impl Abi {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Name { pub(crate) syntax: SyntaxNode, } @@ -250,6 +245,20 @@ impl Name { pub fn ident_token(&self) -> Option { support::token(&self.syntax, T![ident]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct ItemList { + pub(crate) syntax: SyntaxNode, +} +impl ast::ModuleItemOwner for ItemList {} +impl ItemList { + pub fn l_curly_token(&self) -> Option { support::token(&self.syntax, T!['{']) } + pub fn r_curly_token(&self) -> Option { support::token(&self.syntax, T!['}']) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct Abi { + pub(crate) syntax: SyntaxNode, +} +impl Abi {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TypeParamList { pub(crate) syntax: SyntaxNode, } @@ -367,11 +376,10 @@ impl TypeBoundList { pub fn bounds(&self) -> AstChildren { support::children(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ItemList { +pub struct AssocItemList { pub(crate) syntax: SyntaxNode, } -impl ast::ModuleItemOwner for ItemList {} -impl ItemList { +impl AssocItemList { pub fn l_curly_token(&self) -> Option { support::token(&self.syntax, T!['{']) } pub fn assoc_items(&self) -> AstChildren { support::children(&self.syntax) } pub fn r_curly_token(&self) -> Option { support::token(&self.syntax, T!['}']) } @@ -1336,10 +1344,10 @@ pub enum AssocItem { FnDef(FnDef), TypeAliasDef(TypeAliasDef), ConstDef(ConstDef), + MacroCall(MacroCall), } impl ast::AttrsOwner for AssocItem {} impl ast::NameOwner for AssocItem {} -impl ast::VisibilityOwner for AssocItem {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum Pat { OrPat(OrPat), @@ -1574,8 +1582,8 @@ impl AstNode for Visibility { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for Abi { - fn can_cast(kind: SyntaxKind) -> bool { kind == ABI } +impl AstNode for Name { + fn can_cast(kind: SyntaxKind) -> bool { kind == NAME } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1585,8 +1593,19 @@ impl AstNode for Abi { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for Name { - fn can_cast(kind: SyntaxKind) -> bool { kind == NAME } +impl AstNode for ItemList { + fn can_cast(kind: SyntaxKind) -> bool { kind == ITEM_LIST } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} +impl AstNode for Abi { + fn can_cast(kind: SyntaxKind) -> bool { kind == ABI } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1728,8 +1747,8 @@ impl AstNode for TypeBoundList { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for ItemList { - fn can_cast(kind: SyntaxKind) -> bool { kind == ITEM_LIST } +impl AstNode for AssocItemList { + fn can_cast(kind: SyntaxKind) -> bool { kind == ASSOC_ITEM_LIST } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -3144,10 +3163,13 @@ impl From for AssocItem { impl From for AssocItem { fn from(node: ConstDef) -> AssocItem { AssocItem::ConstDef(node) } } +impl From for AssocItem { + fn from(node: MacroCall) -> AssocItem { AssocItem::MacroCall(node) } +} impl AstNode for AssocItem { fn can_cast(kind: SyntaxKind) -> bool { match kind { - FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true, + FN_DEF | TYPE_ALIAS_DEF | CONST_DEF | MACRO_CALL => true, _ => false, } } @@ -3156,6 +3178,7 @@ impl AstNode for AssocItem { FN_DEF => AssocItem::FnDef(FnDef { syntax }), TYPE_ALIAS_DEF => AssocItem::TypeAliasDef(TypeAliasDef { syntax }), CONST_DEF => AssocItem::ConstDef(ConstDef { syntax }), + MACRO_CALL => AssocItem::MacroCall(MacroCall { syntax }), _ => return None, }; Some(res) @@ -3165,6 +3188,7 @@ impl AstNode for AssocItem { AssocItem::FnDef(it) => &it.syntax, AssocItem::TypeAliasDef(it) => &it.syntax, AssocItem::ConstDef(it) => &it.syntax, + AssocItem::MacroCall(it) => &it.syntax, } } } @@ -3515,12 +3539,17 @@ impl std::fmt::Display for Visibility { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for Abi { +impl std::fmt::Display for Name { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for Name { +impl std::fmt::Display for ItemList { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for Abi { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -3585,7 +3614,7 @@ impl std::fmt::Display for TypeBoundList { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for ItemList { +impl std::fmt::Display for AssocItemList { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } -- cgit v1.2.3