From da0b348ae9f629c5cbe4a836a90ed85e36ca18e5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 8 Jan 2019 11:28:42 +0300 Subject: migrate ra_hir to rowan 2.0 --- crates/ra_syntax/src/ast.rs | 27 +++++++++++++++++++++++++++ crates/ra_syntax/src/yellow.rs | 11 +++++++++++ 2 files changed, 38 insertions(+) (limited to 'crates/ra_syntax/src') 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 { } } +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum ItemOrMacro<'a> { + Item(&'a ModuleItem), + Macro(&'a MacroCall), +} + pub trait ModuleItemOwner: AstNode { fn items(&self) -> AstChildren { children(self) } + fn items_with_macros(&self) -> ItemOrMacroIter { + ItemOrMacroIter(self.syntax().children()) + } +} + +#[derive(Debug)] +pub struct ItemOrMacroIter<'a>(SyntaxNodeChildren<'a>); + +impl<'a> Iterator for ItemOrMacroIter<'a> { + type Item = ItemOrMacro<'a>; + fn next(&mut self) -> Option> { + loop { + let n = self.0.next()?; + if let Some(item) = ModuleItem::cast(n) { + return Some(ItemOrMacro::Item(item)); + } + if let Some(call) = MacroCall::cast(n) { + return Some(ItemOrMacro::Macro(call)); + } + } + } } 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 } } +impl PartialEq for TreePtr +where + T: TransparentNewType>, + T: PartialEq, +{ + fn eq(&self, other: &T) -> bool { + let t: &T = self; + t == other + } +} + impl Clone for TreePtr where T: TransparentNewType>, -- cgit v1.2.3