mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
heck
This commit is contained in:
parent
78f41ea707
commit
d5119133fc
5 changed files with 124 additions and 13 deletions
|
@ -4,6 +4,30 @@ use {
|
|||
SyntaxKind::*,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct ConstItem<R: TreeRoot = Arc<SyntaxRoot>> {
|
||||
syntax: SyntaxNode<R>,
|
||||
}
|
||||
|
||||
impl<R: TreeRoot> AstNode<R> for ConstItem<R> {
|
||||
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
|
||||
match syntax.kind() {
|
||||
CONST_ITEM => Some(ConstItem { syntax }),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
|
||||
}
|
||||
|
||||
impl<R: TreeRoot> ConstItem<R> {
|
||||
pub fn name(&self) -> Option<Name<R>> {
|
||||
self.syntax()
|
||||
.children()
|
||||
.filter_map(Name::cast)
|
||||
.next()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Enum<R: TreeRoot = Arc<SyntaxRoot>> {
|
||||
syntax: SyntaxNode<R>,
|
||||
|
@ -75,6 +99,30 @@ impl<R: TreeRoot> Function<R> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Module<R: TreeRoot = Arc<SyntaxRoot>> {
|
||||
syntax: SyntaxNode<R>,
|
||||
}
|
||||
|
||||
impl<R: TreeRoot> AstNode<R> for Module<R> {
|
||||
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
|
||||
match syntax.kind() {
|
||||
MODULE => Some(Module { syntax }),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
|
||||
}
|
||||
|
||||
impl<R: TreeRoot> Module<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>> {
|
||||
syntax: SyntaxNode<R>,
|
||||
|
@ -92,6 +140,30 @@ impl<R: TreeRoot> AstNode<R> for Name<R> {
|
|||
|
||||
impl<R: TreeRoot> Name<R> {}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct StaticItem<R: TreeRoot = Arc<SyntaxRoot>> {
|
||||
syntax: SyntaxNode<R>,
|
||||
}
|
||||
|
||||
impl<R: TreeRoot> AstNode<R> for StaticItem<R> {
|
||||
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
|
||||
match syntax.kind() {
|
||||
STATIC_ITEM => Some(StaticItem { syntax }),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
|
||||
}
|
||||
|
||||
impl<R: TreeRoot> StaticItem<R> {
|
||||
pub fn name(&self) -> Option<Name<R>> {
|
||||
self.syntax()
|
||||
.children()
|
||||
.filter_map(Name::cast)
|
||||
.next()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Struct<R: TreeRoot = Arc<SyntaxRoot>> {
|
||||
syntax: SyntaxNode<R>,
|
||||
|
@ -116,3 +188,27 @@ impl<R: TreeRoot> Struct<R> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Trait<R: TreeRoot = Arc<SyntaxRoot>> {
|
||||
syntax: SyntaxNode<R>,
|
||||
}
|
||||
|
||||
impl<R: TreeRoot> AstNode<R> for Trait<R> {
|
||||
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
|
||||
match syntax.kind() {
|
||||
TRAIT => Some(Trait { syntax }),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
|
||||
}
|
||||
|
||||
impl<R: TreeRoot> Trait<R> {
|
||||
pub fn name(&self) -> Option<Name<R>> {
|
||||
self.syntax()
|
||||
.children()
|
||||
.filter_map(Name::cast)
|
||||
.next()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue