diff options
author | Aleksey Kladov <[email protected]> | 2019-01-01 18:52:07 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-01 19:15:35 +0000 |
commit | 756e8781584fb28af208218615bafbbd9164dfbc (patch) | |
tree | 3dd70c1707ccc2c16b65b6ff3396c3b3a25e526f /crates/ra_syntax/src | |
parent | 4a3f76d3bb6cf75ab5a9ba3384c312a76c70564b (diff) |
add items from macros to modules
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r-- | crates/ra_syntax/src/ast.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index 8fb6b6408..3e948800e 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs | |||
@@ -48,10 +48,40 @@ pub trait FnDefOwner<'a>: AstNode<'a> { | |||
48 | } | 48 | } |
49 | } | 49 | } |
50 | 50 | ||
51 | // ModuleItem | ||
52 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
53 | pub enum ItemOrMacro<'a> { | ||
54 | Item(ModuleItem<'a>), | ||
55 | Macro(MacroCall<'a>), | ||
56 | } | ||
57 | |||
58 | impl<'a> AstNode<'a> for ItemOrMacro<'a> { | ||
59 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | ||
60 | let res = if let Some(item) = ModuleItem::cast(syntax) { | ||
61 | ItemOrMacro::Item(item) | ||
62 | } else if let Some(macro_call) = MacroCall::cast(syntax) { | ||
63 | ItemOrMacro::Macro(macro_call) | ||
64 | } else { | ||
65 | return None; | ||
66 | }; | ||
67 | Some(res) | ||
68 | } | ||
69 | fn syntax(self) -> SyntaxNodeRef<'a> { | ||
70 | match self { | ||
71 | ItemOrMacro::Item(it) => it.syntax(), | ||
72 | ItemOrMacro::Macro(it) => it.syntax(), | ||
73 | } | ||
74 | } | ||
75 | } | ||
76 | |||
51 | pub trait ModuleItemOwner<'a>: AstNode<'a> { | 77 | pub trait ModuleItemOwner<'a>: AstNode<'a> { |
52 | fn items(self) -> AstChildren<'a, ModuleItem<'a>> { | 78 | fn items(self) -> AstChildren<'a, ModuleItem<'a>> { |
53 | children(self) | 79 | children(self) |
54 | } | 80 | } |
81 | |||
82 | fn items_with_macros(self) -> AstChildren<'a, ItemOrMacro<'a>> { | ||
83 | children(self) | ||
84 | } | ||
55 | } | 85 | } |
56 | 86 | ||
57 | pub trait TypeParamsOwner<'a>: AstNode<'a> { | 87 | pub trait TypeParamsOwner<'a>: AstNode<'a> { |