mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-04 01:20:49 +00:00
visitor
This commit is contained in:
parent
d5119133fc
commit
7afd84febc
11 changed files with 211 additions and 86 deletions
|
@ -12,6 +12,15 @@ pub trait AstNode<R: TreeRoot>: Sized {
|
|||
fn syntax(&self) -> &SyntaxNode<R>;
|
||||
}
|
||||
|
||||
pub trait NameOwner<R: TreeRoot>: AstNode<R> {
|
||||
fn name(&self) -> Option<Name<R>> {
|
||||
self.syntax()
|
||||
.children()
|
||||
.filter_map(Name::cast)
|
||||
.next()
|
||||
}
|
||||
}
|
||||
|
||||
impl File<Arc<SyntaxRoot>> {
|
||||
pub fn parse(text: &str) -> Self {
|
||||
File::cast(::parse(text)).unwrap()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue