mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Generate accessors
This commit is contained in:
parent
7581984601
commit
b18d2882f4
4 changed files with 42 additions and 20 deletions
|
@ -20,6 +20,14 @@ impl<R: TreeRoot> AstNode<R> for File<R> {
|
|||
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
|
||||
}
|
||||
|
||||
impl<R: TreeRoot> File<R> {
|
||||
pub fn functions<'a>(&'a self) -> impl Iterator<Item = Function<R>> + 'a {
|
||||
self.syntax()
|
||||
.children()
|
||||
.filter_map(Function::cast)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Function<R: TreeRoot = Arc<SyntaxRoot>> {
|
||||
|
@ -36,6 +44,15 @@ impl<R: TreeRoot> AstNode<R> for Function<R> {
|
|||
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
|
||||
}
|
||||
|
||||
impl<R: TreeRoot> Function<R> {
|
||||
pub fn name(&self) -> Option<Name<R>> {
|
||||
self.syntax()
|
||||
.children()
|
||||
.filter_map(Name::cast)
|
||||
.next()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Name<R: TreeRoot = Arc<SyntaxRoot>> {
|
||||
|
@ -52,3 +69,5 @@ impl<R: TreeRoot> AstNode<R> for Name<R> {
|
|||
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
|
||||
}
|
||||
|
||||
impl<R: TreeRoot> Name<R> {}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue