mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
nested mod completion
This commit is contained in:
parent
ff1c82216c
commit
127814d9a7
5 changed files with 68 additions and 46 deletions
|
@ -699,11 +699,8 @@ impl<'a> AstNode<'a> for ItemList<'a> {
|
|||
}
|
||||
|
||||
impl<'a> ast::FnDefOwner<'a> for ItemList<'a> {}
|
||||
impl<'a> ItemList<'a> {
|
||||
pub fn items(self) -> impl Iterator<Item = ModuleItem<'a>> + 'a {
|
||||
super::children(self)
|
||||
}
|
||||
}
|
||||
impl<'a> ast::ModuleItemOwner<'a> for ItemList<'a> {}
|
||||
impl<'a> ItemList<'a> {}
|
||||
|
||||
// Label
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
|
@ -979,7 +976,6 @@ impl<'a> AstNode<'a> for Module<'a> {
|
|||
|
||||
impl<'a> ast::NameOwner<'a> for Module<'a> {}
|
||||
impl<'a> ast::AttrsOwner<'a> for Module<'a> {}
|
||||
impl<'a> ast::FnDefOwner<'a> for Module<'a> {}
|
||||
impl<'a> Module<'a> {pub fn item_list(self) -> Option<ItemList<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
|
@ -1616,12 +1612,9 @@ impl<'a> AstNode<'a> for Root<'a> {
|
|||
fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
|
||||
}
|
||||
|
||||
impl<'a> ast::ModuleItemOwner<'a> for Root<'a> {}
|
||||
impl<'a> ast::FnDefOwner<'a> for Root<'a> {}
|
||||
impl<'a> Root<'a> {
|
||||
pub fn items(self) -> impl Iterator<Item = ModuleItem<'a>> + 'a {
|
||||
super::children(self)
|
||||
}
|
||||
|
||||
pub fn modules(self) -> impl Iterator<Item = Module<'a>> + 'a {
|
||||
super::children(self)
|
||||
}
|
||||
|
|
|
@ -36,7 +36,13 @@ pub trait ArgListOwner<'a>: AstNode<'a> {
|
|||
}
|
||||
|
||||
pub trait FnDefOwner<'a>: AstNode<'a> {
|
||||
fn functions(self) -> AstNodeChildren<'a, FnDef<'a>> {
|
||||
fn functions(self) -> AstChildren<'a, FnDef<'a>> {
|
||||
children(self)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ModuleItemOwner<'a>: AstNode<'a> {
|
||||
fn items(self) -> AstChildren<'a, ModuleItem<'a>> {
|
||||
children(self)
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +58,7 @@ pub trait TypeParamsOwner<'a>: AstNode<'a> {
|
|||
}
|
||||
|
||||
pub trait AttrsOwner<'a>: AstNode<'a> {
|
||||
fn attrs(self) -> AstNodeChildren<'a, Attr<'a>> {
|
||||
fn attrs(self) -> AstChildren<'a, Attr<'a>> {
|
||||
children(self)
|
||||
}
|
||||
}
|
||||
|
@ -158,7 +164,7 @@ impl<'a> IfExpr<'a> {
|
|||
pub fn else_branch(self) -> Option<Block<'a>> {
|
||||
self.blocks().nth(1)
|
||||
}
|
||||
fn blocks(self) -> AstNodeChildren<'a, Block<'a>> {
|
||||
fn blocks(self) -> AstChildren<'a, Block<'a>> {
|
||||
children(self)
|
||||
}
|
||||
}
|
||||
|
@ -167,27 +173,27 @@ fn child_opt<'a, P: AstNode<'a>, C: AstNode<'a>>(parent: P) -> Option<C> {
|
|||
children(parent).next()
|
||||
}
|
||||
|
||||
fn children<'a, P: AstNode<'a>, C: AstNode<'a>>(parent: P) -> AstNodeChildren<'a, C> {
|
||||
AstNodeChildren::new(parent.syntax())
|
||||
fn children<'a, P: AstNode<'a>, C: AstNode<'a>>(parent: P) -> AstChildren<'a, C> {
|
||||
AstChildren::new(parent.syntax())
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct AstNodeChildren<'a, N> {
|
||||
pub struct AstChildren<'a, N> {
|
||||
inner: SyntaxNodeChildren<RefRoot<'a>>,
|
||||
ph: PhantomData<N>,
|
||||
}
|
||||
|
||||
impl<'a, N> AstNodeChildren<'a, N> {
|
||||
impl<'a, N> AstChildren<'a, N> {
|
||||
fn new(parent: SyntaxNodeRef<'a>) -> Self {
|
||||
AstNodeChildren {
|
||||
AstChildren {
|
||||
inner: parent.children(),
|
||||
ph: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, N: AstNode<'a>> Iterator for AstNodeChildren<'a, N> {
|
||||
impl<'a, N: AstNode<'a>> Iterator for AstChildren<'a, N> {
|
||||
type Item = N;
|
||||
fn next(&mut self) -> Option<N> {
|
||||
loop {
|
||||
|
|
|
@ -238,9 +238,8 @@ Grammar(
|
|||
],
|
||||
ast: {
|
||||
"Root": (
|
||||
traits: [ "FnDefOwner" ],
|
||||
traits: [ "ModuleItemOwner", "FnDefOwner" ],
|
||||
collections: [
|
||||
["items", "ModuleItem"],
|
||||
["modules", "Module"],
|
||||
]
|
||||
),
|
||||
|
@ -271,12 +270,11 @@ Grammar(
|
|||
] ),
|
||||
"TraitDef": ( traits: ["NameOwner", "AttrsOwner"] ),
|
||||
"Module": (
|
||||
traits: ["NameOwner", "AttrsOwner", "FnDefOwner" ],
|
||||
traits: ["NameOwner", "AttrsOwner" ],
|
||||
options: [ "ItemList" ]
|
||||
),
|
||||
"ItemList": (
|
||||
traits: [ "FnDefOwner" ],
|
||||
collections: [ ["items", "ModuleItem"] ]
|
||||
traits: [ "FnDefOwner", "ModuleItemOwner" ],
|
||||
),
|
||||
"ConstDef": ( traits: [
|
||||
"NameOwner",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue