From 7dc45745a378c6feb6af524e8bd40e89bab7a822 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 1 Jan 2019 19:51:11 +0300 Subject: save top-level macros in module items --- crates/ra_syntax/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_syntax/src') 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; use crate::yellow::GreenNode; /// `SourceFileNode` represents a parse tree for a single Rust file. -pub use crate::ast::SourceFileNode; +pub use crate::ast::{SourceFile, SourceFileNode}; impl SourceFileNode { fn new(green: GreenNode, errors: Vec) -> SourceFileNode { -- cgit v1.2.3 From 756e8781584fb28af208218615bafbbd9164dfbc Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 1 Jan 2019 21:52:07 +0300 Subject: add items from macros to modules --- crates/ra_syntax/src/ast.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'crates/ra_syntax/src') 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> { } } +// ModuleItem +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum ItemOrMacro<'a> { + Item(ModuleItem<'a>), + Macro(MacroCall<'a>), +} + +impl<'a> AstNode<'a> for ItemOrMacro<'a> { + fn cast(syntax: SyntaxNodeRef<'a>) -> Option { + let res = if let Some(item) = ModuleItem::cast(syntax) { + ItemOrMacro::Item(item) + } else if let Some(macro_call) = MacroCall::cast(syntax) { + ItemOrMacro::Macro(macro_call) + } else { + return None; + }; + Some(res) + } + fn syntax(self) -> SyntaxNodeRef<'a> { + match self { + ItemOrMacro::Item(it) => it.syntax(), + ItemOrMacro::Macro(it) => it.syntax(), + } + } +} + pub trait ModuleItemOwner<'a>: AstNode<'a> { fn items(self) -> AstChildren<'a, ModuleItem<'a>> { children(self) } + + fn items_with_macros(self) -> AstChildren<'a, ItemOrMacro<'a>> { + children(self) + } } pub trait TypeParamsOwner<'a>: AstNode<'a> { -- cgit v1.2.3