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.rs30
-rw-r--r--crates/ra_syntax/src/lib.rs2
2 files changed, 31 insertions, 1 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)]
53pub enum ItemOrMacro<'a> {
54 Item(ModuleItem<'a>),
55 Macro(MacroCall<'a>),
56}
57
58impl<'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
51pub trait ModuleItemOwner<'a>: AstNode<'a> { 77pub 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
57pub trait TypeParamsOwner<'a>: AstNode<'a> { 87pub trait TypeParamsOwner<'a>: AstNode<'a> {
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs
index 34a3aabef..6753c513f 100644
--- a/crates/ra_syntax/src/lib.rs
+++ b/crates/ra_syntax/src/lib.rs
@@ -51,7 +51,7 @@ use ra_text_edit::AtomTextEdit;
51use crate::yellow::GreenNode; 51use crate::yellow::GreenNode;
52 52
53/// `SourceFileNode` represents a parse tree for a single Rust file. 53/// `SourceFileNode` represents a parse tree for a single Rust file.
54pub use crate::ast::SourceFileNode; 54pub use crate::ast::{SourceFile, SourceFileNode};
55 55
56impl SourceFileNode { 56impl SourceFileNode {
57 fn new(green: GreenNode, errors: Vec<SyntaxError>) -> SourceFileNode { 57 fn new(green: GreenNode, errors: Vec<SyntaxError>) -> SourceFileNode {