mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 11:59:49 +00:00
add items from macros to modules
This commit is contained in:
parent
4a3f76d3bb
commit
756e878158
3 changed files with 67 additions and 12 deletions
|
@ -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<Self> {
|
||||
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> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue