diff options
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r-- | crates/ra_syntax/src/ast.rs | 27 | ||||
-rw-r--r-- | crates/ra_syntax/src/yellow.rs | 11 |
2 files changed, 38 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index 285dda1e0..0e303ee98 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs | |||
@@ -53,10 +53,37 @@ pub trait FnDefOwner: AstNode { | |||
53 | } | 53 | } |
54 | } | 54 | } |
55 | 55 | ||
56 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
57 | pub enum ItemOrMacro<'a> { | ||
58 | Item(&'a ModuleItem), | ||
59 | Macro(&'a MacroCall), | ||
60 | } | ||
61 | |||
56 | pub trait ModuleItemOwner: AstNode { | 62 | pub trait ModuleItemOwner: AstNode { |
57 | fn items(&self) -> AstChildren<ModuleItem> { | 63 | fn items(&self) -> AstChildren<ModuleItem> { |
58 | children(self) | 64 | children(self) |
59 | } | 65 | } |
66 | fn items_with_macros(&self) -> ItemOrMacroIter { | ||
67 | ItemOrMacroIter(self.syntax().children()) | ||
68 | } | ||
69 | } | ||
70 | |||
71 | #[derive(Debug)] | ||
72 | pub struct ItemOrMacroIter<'a>(SyntaxNodeChildren<'a>); | ||
73 | |||
74 | impl<'a> Iterator for ItemOrMacroIter<'a> { | ||
75 | type Item = ItemOrMacro<'a>; | ||
76 | fn next(&mut self) -> Option<ItemOrMacro<'a>> { | ||
77 | loop { | ||
78 | let n = self.0.next()?; | ||
79 | if let Some(item) = ModuleItem::cast(n) { | ||
80 | return Some(ItemOrMacro::Item(item)); | ||
81 | } | ||
82 | if let Some(call) = MacroCall::cast(n) { | ||
83 | return Some(ItemOrMacro::Macro(call)); | ||
84 | } | ||
85 | } | ||
86 | } | ||
60 | } | 87 | } |
61 | 88 | ||
62 | pub trait TypeParamsOwner: AstNode { | 89 | pub trait TypeParamsOwner: AstNode { |
diff --git a/crates/ra_syntax/src/yellow.rs b/crates/ra_syntax/src/yellow.rs index f31efa174..1bf1806b9 100644 --- a/crates/ra_syntax/src/yellow.rs +++ b/crates/ra_syntax/src/yellow.rs | |||
@@ -47,6 +47,17 @@ where | |||
47 | } | 47 | } |
48 | } | 48 | } |
49 | 49 | ||
50 | impl<T> PartialEq<T> for TreePtr<T> | ||
51 | where | ||
52 | T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, | ||
53 | T: PartialEq<T>, | ||
54 | { | ||
55 | fn eq(&self, other: &T) -> bool { | ||
56 | let t: &T = self; | ||
57 | t == other | ||
58 | } | ||
59 | } | ||
60 | |||
50 | impl<T> Clone for TreePtr<T> | 61 | impl<T> Clone for TreePtr<T> |
51 | where | 62 | where |
52 | T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, | 63 | T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, |