aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-07-30 10:42:51 +0100
committerAleksey Kladov <[email protected]>2020-07-30 10:50:56 +0100
commit2984da672e0c73d56501c6b6e4d19fd28152b5eb (patch)
treeca9e499bd96c2273f90f27d43ba7282b5931f8df /crates/ra_syntax
parent72ffd851dd5b0fcdf3aa072131ba11009878b4ae (diff)
Split ItemList & AssocItemList
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/ast/edit.rs9
-rw-r--r--crates/ra_syntax/src/ast/generated/nodes.rs71
2 files changed, 56 insertions, 24 deletions
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
80 } 80 }
81} 81}
82 82
83impl ast::ItemList { 83impl ast::AssocItemList {
84 #[must_use] 84 #[must_use]
85 pub fn append_items(&self, items: impl IntoIterator<Item = ast::AssocItem>) -> ast::ItemList { 85 pub fn append_items(
86 &self,
87 items: impl IntoIterator<Item = ast::AssocItem>,
88 ) -> ast::AssocItemList {
86 let mut res = self.clone(); 89 let mut res = self.clone();
87 if !self.syntax().text().contains_char('\n') { 90 if !self.syntax().text().contains_char('\n') {
88 res = make_multiline(res); 91 res = make_multiline(res);
@@ -92,7 +95,7 @@ impl ast::ItemList {
92 } 95 }
93 96
94 #[must_use] 97 #[must_use]
95 pub fn append_item(&self, item: ast::AssocItem) -> ast::ItemList { 98 pub fn append_item(&self, item: ast::AssocItem) -> ast::AssocItemList {
96 let (indent, position) = match self.assoc_items().last() { 99 let (indent, position) = match self.assoc_items().last() {
97 Some(it) => ( 100 Some(it) => (
98 leading_indent(it.syntax()).unwrap_or_default().to_string(), 101 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 {
112 pub fn impl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![impl]) } 112 pub fn impl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![impl]) }
113 pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) } 113 pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) }
114 pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) } 114 pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) }
115 pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } 115 pub fn assoc_item_list(&self) -> Option<AssocItemList> { support::child(&self.syntax) }
116} 116}
117#[derive(Debug, Clone, PartialEq, Eq, Hash)] 117#[derive(Debug, Clone, PartialEq, Eq, Hash)]
118pub struct MacroCall { 118pub struct MacroCall {
@@ -180,7 +180,7 @@ impl TraitDef {
180 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) } 180 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) }
181 pub fn auto_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![auto]) } 181 pub fn auto_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![auto]) }
182 pub fn trait_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![trait]) } 182 pub fn trait_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![trait]) }
183 pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } 183 pub fn assoc_item_list(&self) -> Option<AssocItemList> { support::child(&self.syntax) }
184} 184}
185#[derive(Debug, Clone, PartialEq, Eq, Hash)] 185#[derive(Debug, Clone, PartialEq, Eq, Hash)]
186pub struct TypeAliasDef { 186pub struct TypeAliasDef {
@@ -238,11 +238,6 @@ impl Visibility {
238 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 238 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
239} 239}
240#[derive(Debug, Clone, PartialEq, Eq, Hash)] 240#[derive(Debug, Clone, PartialEq, Eq, Hash)]
241pub struct Abi {
242 pub(crate) syntax: SyntaxNode,
243}
244impl Abi {}
245#[derive(Debug, Clone, PartialEq, Eq, Hash)]
246pub struct Name { 241pub struct Name {
247 pub(crate) syntax: SyntaxNode, 242 pub(crate) syntax: SyntaxNode,
248} 243}
@@ -250,6 +245,20 @@ impl Name {
250 pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) } 245 pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) }
251} 246}
252#[derive(Debug, Clone, PartialEq, Eq, Hash)] 247#[derive(Debug, Clone, PartialEq, Eq, Hash)]
248pub struct ItemList {
249 pub(crate) syntax: SyntaxNode,
250}
251impl ast::ModuleItemOwner for ItemList {}
252impl ItemList {
253 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
254 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
255}
256#[derive(Debug, Clone, PartialEq, Eq, Hash)]
257pub struct Abi {
258 pub(crate) syntax: SyntaxNode,
259}
260impl Abi {}
261#[derive(Debug, Clone, PartialEq, Eq, Hash)]
253pub struct TypeParamList { 262pub struct TypeParamList {
254 pub(crate) syntax: SyntaxNode, 263 pub(crate) syntax: SyntaxNode,
255} 264}
@@ -367,11 +376,10 @@ impl TypeBoundList {
367 pub fn bounds(&self) -> AstChildren<TypeBound> { support::children(&self.syntax) } 376 pub fn bounds(&self) -> AstChildren<TypeBound> { support::children(&self.syntax) }
368} 377}
369#[derive(Debug, Clone, PartialEq, Eq, Hash)] 378#[derive(Debug, Clone, PartialEq, Eq, Hash)]
370pub struct ItemList { 379pub struct AssocItemList {
371 pub(crate) syntax: SyntaxNode, 380 pub(crate) syntax: SyntaxNode,
372} 381}
373impl ast::ModuleItemOwner for ItemList {} 382impl AssocItemList {
374impl ItemList {
375 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } 383 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
376 pub fn assoc_items(&self) -> AstChildren<AssocItem> { support::children(&self.syntax) } 384 pub fn assoc_items(&self) -> AstChildren<AssocItem> { support::children(&self.syntax) }
377 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } 385 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
@@ -1336,10 +1344,10 @@ pub enum AssocItem {
1336 FnDef(FnDef), 1344 FnDef(FnDef),
1337 TypeAliasDef(TypeAliasDef), 1345 TypeAliasDef(TypeAliasDef),
1338 ConstDef(ConstDef), 1346 ConstDef(ConstDef),
1347 MacroCall(MacroCall),
1339} 1348}
1340impl ast::AttrsOwner for AssocItem {} 1349impl ast::AttrsOwner for AssocItem {}
1341impl ast::NameOwner for AssocItem {} 1350impl ast::NameOwner for AssocItem {}
1342impl ast::VisibilityOwner for AssocItem {}
1343#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1351#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1344pub enum Pat { 1352pub enum Pat {
1345 OrPat(OrPat), 1353 OrPat(OrPat),
@@ -1574,8 +1582,8 @@ impl AstNode for Visibility {
1574 } 1582 }
1575 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1583 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1576} 1584}
1577impl AstNode for Abi { 1585impl AstNode for Name {
1578 fn can_cast(kind: SyntaxKind) -> bool { kind == ABI } 1586 fn can_cast(kind: SyntaxKind) -> bool { kind == NAME }
1579 fn cast(syntax: SyntaxNode) -> Option<Self> { 1587 fn cast(syntax: SyntaxNode) -> Option<Self> {
1580 if Self::can_cast(syntax.kind()) { 1588 if Self::can_cast(syntax.kind()) {
1581 Some(Self { syntax }) 1589 Some(Self { syntax })
@@ -1585,8 +1593,19 @@ impl AstNode for Abi {
1585 } 1593 }
1586 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1594 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1587} 1595}
1588impl AstNode for Name { 1596impl AstNode for ItemList {
1589 fn can_cast(kind: SyntaxKind) -> bool { kind == NAME } 1597 fn can_cast(kind: SyntaxKind) -> bool { kind == ITEM_LIST }
1598 fn cast(syntax: SyntaxNode) -> Option<Self> {
1599 if Self::can_cast(syntax.kind()) {
1600 Some(Self { syntax })
1601 } else {
1602 None
1603 }
1604 }
1605 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1606}
1607impl AstNode for Abi {
1608 fn can_cast(kind: SyntaxKind) -> bool { kind == ABI }
1590 fn cast(syntax: SyntaxNode) -> Option<Self> { 1609 fn cast(syntax: SyntaxNode) -> Option<Self> {
1591 if Self::can_cast(syntax.kind()) { 1610 if Self::can_cast(syntax.kind()) {
1592 Some(Self { syntax }) 1611 Some(Self { syntax })
@@ -1728,8 +1747,8 @@ impl AstNode for TypeBoundList {
1728 } 1747 }
1729 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1748 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1730} 1749}
1731impl AstNode for ItemList { 1750impl AstNode for AssocItemList {
1732 fn can_cast(kind: SyntaxKind) -> bool { kind == ITEM_LIST } 1751 fn can_cast(kind: SyntaxKind) -> bool { kind == ASSOC_ITEM_LIST }
1733 fn cast(syntax: SyntaxNode) -> Option<Self> { 1752 fn cast(syntax: SyntaxNode) -> Option<Self> {
1734 if Self::can_cast(syntax.kind()) { 1753 if Self::can_cast(syntax.kind()) {
1735 Some(Self { syntax }) 1754 Some(Self { syntax })
@@ -3144,10 +3163,13 @@ impl From<TypeAliasDef> for AssocItem {
3144impl From<ConstDef> for AssocItem { 3163impl From<ConstDef> for AssocItem {
3145 fn from(node: ConstDef) -> AssocItem { AssocItem::ConstDef(node) } 3164 fn from(node: ConstDef) -> AssocItem { AssocItem::ConstDef(node) }
3146} 3165}
3166impl From<MacroCall> for AssocItem {
3167 fn from(node: MacroCall) -> AssocItem { AssocItem::MacroCall(node) }
3168}
3147impl AstNode for AssocItem { 3169impl AstNode for AssocItem {
3148 fn can_cast(kind: SyntaxKind) -> bool { 3170 fn can_cast(kind: SyntaxKind) -> bool {
3149 match kind { 3171 match kind {
3150 FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true, 3172 FN_DEF | TYPE_ALIAS_DEF | CONST_DEF | MACRO_CALL => true,
3151 _ => false, 3173 _ => false,
3152 } 3174 }
3153 } 3175 }
@@ -3156,6 +3178,7 @@ impl AstNode for AssocItem {
3156 FN_DEF => AssocItem::FnDef(FnDef { syntax }), 3178 FN_DEF => AssocItem::FnDef(FnDef { syntax }),
3157 TYPE_ALIAS_DEF => AssocItem::TypeAliasDef(TypeAliasDef { syntax }), 3179 TYPE_ALIAS_DEF => AssocItem::TypeAliasDef(TypeAliasDef { syntax }),
3158 CONST_DEF => AssocItem::ConstDef(ConstDef { syntax }), 3180 CONST_DEF => AssocItem::ConstDef(ConstDef { syntax }),
3181 MACRO_CALL => AssocItem::MacroCall(MacroCall { syntax }),
3159 _ => return None, 3182 _ => return None,
3160 }; 3183 };
3161 Some(res) 3184 Some(res)
@@ -3165,6 +3188,7 @@ impl AstNode for AssocItem {
3165 AssocItem::FnDef(it) => &it.syntax, 3188 AssocItem::FnDef(it) => &it.syntax,
3166 AssocItem::TypeAliasDef(it) => &it.syntax, 3189 AssocItem::TypeAliasDef(it) => &it.syntax,
3167 AssocItem::ConstDef(it) => &it.syntax, 3190 AssocItem::ConstDef(it) => &it.syntax,
3191 AssocItem::MacroCall(it) => &it.syntax,
3168 } 3192 }
3169 } 3193 }
3170} 3194}
@@ -3515,12 +3539,17 @@ impl std::fmt::Display for Visibility {
3515 std::fmt::Display::fmt(self.syntax(), f) 3539 std::fmt::Display::fmt(self.syntax(), f)
3516 } 3540 }
3517} 3541}
3518impl std::fmt::Display for Abi { 3542impl std::fmt::Display for Name {
3519 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3543 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3520 std::fmt::Display::fmt(self.syntax(), f) 3544 std::fmt::Display::fmt(self.syntax(), f)
3521 } 3545 }
3522} 3546}
3523impl std::fmt::Display for Name { 3547impl std::fmt::Display for ItemList {
3548 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3549 std::fmt::Display::fmt(self.syntax(), f)
3550 }
3551}
3552impl std::fmt::Display for Abi {
3524 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3553 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3525 std::fmt::Display::fmt(self.syntax(), f) 3554 std::fmt::Display::fmt(self.syntax(), f)
3526 } 3555 }
@@ -3585,7 +3614,7 @@ impl std::fmt::Display for TypeBoundList {
3585 std::fmt::Display::fmt(self.syntax(), f) 3614 std::fmt::Display::fmt(self.syntax(), f)
3586 } 3615 }
3587} 3616}
3588impl std::fmt::Display for ItemList { 3617impl std::fmt::Display for AssocItemList {
3589 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3618 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3590 std::fmt::Display::fmt(self.syntax(), f) 3619 std::fmt::Display::fmt(self.syntax(), f)
3591 } 3620 }