aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/ast/generated.rs10
-rw-r--r--crates/ra_syntax/src/ast/traits.rs31
2 files changed, 10 insertions, 31 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs
index 002f453cd..7204ca5b1 100644
--- a/crates/ra_syntax/src/ast/generated.rs
+++ b/crates/ra_syntax/src/ast/generated.rs
@@ -4135,6 +4135,7 @@ pub enum ModuleItem {
4135 ConstDef(ConstDef), 4135 ConstDef(ConstDef),
4136 StaticDef(StaticDef), 4136 StaticDef(StaticDef),
4137 Module(Module), 4137 Module(Module),
4138 MacroCall(MacroCall),
4138} 4139}
4139impl From<StructDef> for ModuleItem { 4140impl From<StructDef> for ModuleItem {
4140 fn from(node: StructDef) -> ModuleItem { 4141 fn from(node: StructDef) -> ModuleItem {
@@ -4196,6 +4197,11 @@ impl From<Module> for ModuleItem {
4196 ModuleItem::Module(node) 4197 ModuleItem::Module(node)
4197 } 4198 }
4198} 4199}
4200impl From<MacroCall> for ModuleItem {
4201 fn from(node: MacroCall) -> ModuleItem {
4202 ModuleItem::MacroCall(node)
4203 }
4204}
4199impl std::fmt::Display for ModuleItem { 4205impl std::fmt::Display for ModuleItem {
4200 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { 4206 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
4201 std::fmt::Display::fmt(self.syntax(), f) 4207 std::fmt::Display::fmt(self.syntax(), f)
@@ -4205,7 +4211,7 @@ impl AstNode for ModuleItem {
4205 fn can_cast(kind: SyntaxKind) -> bool { 4211 fn can_cast(kind: SyntaxKind) -> bool {
4206 match kind { 4212 match kind {
4207 STRUCT_DEF | UNION_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | IMPL_DEF 4213 STRUCT_DEF | UNION_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | IMPL_DEF
4208 | USE_ITEM | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE => true, 4214 | USE_ITEM | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE | MACRO_CALL => true,
4209 _ => false, 4215 _ => false,
4210 } 4216 }
4211 } 4217 }
@@ -4223,6 +4229,7 @@ impl AstNode for ModuleItem {
4223 CONST_DEF => ModuleItem::ConstDef(ConstDef { syntax }), 4229 CONST_DEF => ModuleItem::ConstDef(ConstDef { syntax }),
4224 STATIC_DEF => ModuleItem::StaticDef(StaticDef { syntax }), 4230 STATIC_DEF => ModuleItem::StaticDef(StaticDef { syntax }),
4225 MODULE => ModuleItem::Module(Module { syntax }), 4231 MODULE => ModuleItem::Module(Module { syntax }),
4232 MACRO_CALL => ModuleItem::MacroCall(MacroCall { syntax }),
4226 _ => return None, 4233 _ => return None,
4227 }; 4234 };
4228 Some(res) 4235 Some(res)
@@ -4241,6 +4248,7 @@ impl AstNode for ModuleItem {
4241 ModuleItem::ConstDef(it) => &it.syntax, 4248 ModuleItem::ConstDef(it) => &it.syntax,
4242 ModuleItem::StaticDef(it) => &it.syntax, 4249 ModuleItem::StaticDef(it) => &it.syntax,
4243 ModuleItem::Module(it) => &it.syntax, 4250 ModuleItem::Module(it) => &it.syntax,
4251 ModuleItem::MacroCall(it) => &it.syntax,
4244 } 4252 }
4245 } 4253 }
4246} 4254}
diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs
index f8cf1e3eb..576378306 100644
--- a/crates/ra_syntax/src/ast/traits.rs
+++ b/crates/ra_syntax/src/ast/traits.rs
@@ -6,8 +6,7 @@ use itertools::Itertools;
6 6
7use crate::{ 7use crate::{
8 ast::{self, child_opt, children, AstChildren, AstNode, AstToken}, 8 ast::{self, child_opt, children, AstChildren, AstNode, AstToken},
9 match_ast, 9 syntax_node::SyntaxElementChildren,
10 syntax_node::{SyntaxElementChildren, SyntaxNodeChildren},
11}; 10};
12 11
13pub trait TypeAscriptionOwner: AstNode { 12pub trait TypeAscriptionOwner: AstNode {
@@ -46,38 +45,10 @@ pub trait FnDefOwner: AstNode {
46 } 45 }
47} 46}
48 47
49#[derive(Debug, Clone, PartialEq, Eq)]
50pub enum ItemOrMacro {
51 Item(ast::ModuleItem),
52 Macro(ast::MacroCall),
53}
54
55pub trait ModuleItemOwner: AstNode { 48pub trait ModuleItemOwner: AstNode {
56 fn items(&self) -> AstChildren<ast::ModuleItem> { 49 fn items(&self) -> AstChildren<ast::ModuleItem> {
57 children(self) 50 children(self)
58 } 51 }
59 fn items_with_macros(&self) -> ItemOrMacroIter {
60 ItemOrMacroIter(self.syntax().children())
61 }
62}
63
64#[derive(Debug)]
65pub struct ItemOrMacroIter(SyntaxNodeChildren);
66
67impl Iterator for ItemOrMacroIter {
68 type Item = ItemOrMacro;
69 fn next(&mut self) -> Option<ItemOrMacro> {
70 loop {
71 let n = self.0.next()?;
72 match_ast! {
73 match n {
74 ast::ModuleItem(it) => { return Some(ItemOrMacro::Item(it)) },
75 ast::MacroCall(it) => { return Some(ItemOrMacro::Macro(it)) },
76 _ => {},
77 }
78 }
79 }
80 }
81} 52}
82 53
83pub trait TypeParamsOwner: AstNode { 54pub trait TypeParamsOwner: AstNode {