mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
TypeParamList Owner
This commit is contained in:
parent
55896aedb1
commit
8e3bec11eb
5 changed files with 118 additions and 26 deletions
|
@ -64,6 +64,7 @@ impl<'a> AstNode<'a> for ConstDef<'a> {
|
|||
}
|
||||
|
||||
impl<'a> ast::NameOwner<'a> for ConstDef<'a> {}
|
||||
impl<'a> ast::TypeParamsOwner<'a> for ConstDef<'a> {}
|
||||
impl<'a> ast::AttrsOwner<'a> for ConstDef<'a> {}
|
||||
impl<'a> ConstDef<'a> {}
|
||||
|
||||
|
@ -102,6 +103,7 @@ impl<'a> AstNode<'a> for EnumDef<'a> {
|
|||
}
|
||||
|
||||
impl<'a> ast::NameOwner<'a> for EnumDef<'a> {}
|
||||
impl<'a> ast::TypeParamsOwner<'a> for EnumDef<'a> {}
|
||||
impl<'a> ast::AttrsOwner<'a> for EnumDef<'a> {}
|
||||
impl<'a> EnumDef<'a> {}
|
||||
|
||||
|
@ -152,6 +154,7 @@ impl<'a> AstNode<'a> for FnDef<'a> {
|
|||
}
|
||||
|
||||
impl<'a> ast::NameOwner<'a> for FnDef<'a> {}
|
||||
impl<'a> ast::TypeParamsOwner<'a> for FnDef<'a> {}
|
||||
impl<'a> ast::AttrsOwner<'a> for FnDef<'a> {}
|
||||
impl<'a> FnDef<'a> {}
|
||||
|
||||
|
@ -351,6 +354,7 @@ impl<'a> AstNode<'a> for NominalDef<'a> {
|
|||
}
|
||||
|
||||
impl<'a> ast::AttrsOwner<'a> for NominalDef<'a> {}
|
||||
impl<'a> ast::TypeParamsOwner<'a> for NominalDef<'a> {}
|
||||
impl<'a> NominalDef<'a> {}
|
||||
|
||||
// ParenType
|
||||
|
@ -478,6 +482,7 @@ impl<'a> AstNode<'a> for StaticDef<'a> {
|
|||
}
|
||||
|
||||
impl<'a> ast::NameOwner<'a> for StaticDef<'a> {}
|
||||
impl<'a> ast::TypeParamsOwner<'a> for StaticDef<'a> {}
|
||||
impl<'a> ast::AttrsOwner<'a> for StaticDef<'a> {}
|
||||
impl<'a> StaticDef<'a> {}
|
||||
|
||||
|
@ -498,6 +503,7 @@ impl<'a> AstNode<'a> for StructDef<'a> {
|
|||
}
|
||||
|
||||
impl<'a> ast::NameOwner<'a> for StructDef<'a> {}
|
||||
impl<'a> ast::TypeParamsOwner<'a> for StructDef<'a> {}
|
||||
impl<'a> ast::AttrsOwner<'a> for StructDef<'a> {}
|
||||
impl<'a> StructDef<'a> {
|
||||
pub fn fields(self) -> impl Iterator<Item = NamedField<'a>> + 'a {
|
||||
|
@ -580,9 +586,28 @@ impl<'a> AstNode<'a> for TypeDef<'a> {
|
|||
}
|
||||
|
||||
impl<'a> ast::NameOwner<'a> for TypeDef<'a> {}
|
||||
impl<'a> ast::TypeParamsOwner<'a> for TypeDef<'a> {}
|
||||
impl<'a> ast::AttrsOwner<'a> for TypeDef<'a> {}
|
||||
impl<'a> TypeDef<'a> {}
|
||||
|
||||
// TypeParamList
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct TypeParamList<'a> {
|
||||
syntax: SyntaxNodeRef<'a>,
|
||||
}
|
||||
|
||||
impl<'a> AstNode<'a> for TypeParamList<'a> {
|
||||
fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
|
||||
match syntax.kind() {
|
||||
TYPE_PARAM_LIST => Some(TypeParamList { syntax }),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
|
||||
}
|
||||
|
||||
impl<'a> TypeParamList<'a> {}
|
||||
|
||||
// TypeRef
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum TypeRef<'a> {
|
||||
|
@ -641,21 +666,21 @@ impl<'a> AstNode<'a> for TypeRef<'a> {
|
|||
|
||||
impl<'a> TypeRef<'a> {}
|
||||
|
||||
// Whitespace
|
||||
// WhereClause
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Whitespace<'a> {
|
||||
pub struct WhereClause<'a> {
|
||||
syntax: SyntaxNodeRef<'a>,
|
||||
}
|
||||
|
||||
impl<'a> AstNode<'a> for Whitespace<'a> {
|
||||
impl<'a> AstNode<'a> for WhereClause<'a> {
|
||||
fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
|
||||
match syntax.kind() {
|
||||
WHITESPACE => Some(Whitespace { syntax }),
|
||||
WHERE_CLAUSE => Some(WhereClause { syntax }),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
|
||||
}
|
||||
|
||||
impl<'a> Whitespace<'a> {}
|
||||
impl<'a> WhereClause<'a> {}
|
||||
|
||||
|
|
|
@ -24,6 +24,22 @@ pub trait NameOwner<'a>: AstNode<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait TypeParamsOwner<'a>: AstNode<'a> {
|
||||
fn type_param_list(self) -> Option<TypeParamList<'a>> {
|
||||
self.syntax()
|
||||
.children()
|
||||
.filter_map(TypeParamList::cast)
|
||||
.next()
|
||||
}
|
||||
|
||||
fn where_clause(self) -> Option<WhereClause<'a>> {
|
||||
self.syntax()
|
||||
.children()
|
||||
.filter_map(WhereClause::cast)
|
||||
.next()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait AttrsOwner<'a>: AstNode<'a> {
|
||||
fn attrs(&self) -> Box<Iterator<Item=Attr<'a>> + 'a> {
|
||||
let it = self.syntax().children()
|
||||
|
|
|
@ -222,15 +222,27 @@ Grammar(
|
|||
["modules", "Module"],
|
||||
]
|
||||
),
|
||||
"FnDef": ( traits: ["NameOwner", "AttrsOwner"] ),
|
||||
"FnDef": ( traits: [
|
||||
"NameOwner",
|
||||
"TypeParamsOwner",
|
||||
"AttrsOwner",
|
||||
] ),
|
||||
"StructDef": (
|
||||
traits: ["NameOwner", "AttrsOwner"],
|
||||
traits: [
|
||||
"NameOwner",
|
||||
"TypeParamsOwner",
|
||||
"AttrsOwner",
|
||||
],
|
||||
collections: [
|
||||
["fields", "NamedField"]
|
||||
]
|
||||
),
|
||||
"NamedField": ( traits: ["NameOwner", "AttrsOwner"] ),
|
||||
"EnumDef": ( traits: ["NameOwner", "AttrsOwner"] ),
|
||||
"EnumDef": ( traits: [
|
||||
"NameOwner",
|
||||
"TypeParamsOwner",
|
||||
"AttrsOwner",
|
||||
] ),
|
||||
"TraitDef": ( traits: ["NameOwner", "AttrsOwner"] ),
|
||||
"Module": (
|
||||
traits: ["NameOwner", "AttrsOwner"],
|
||||
|
@ -238,16 +250,23 @@ Grammar(
|
|||
["modules", "Module"]
|
||||
]
|
||||
),
|
||||
"ConstDef": ( traits: ["NameOwner", "AttrsOwner"] ),
|
||||
"StaticDef": ( traits: ["NameOwner", "AttrsOwner"] ),
|
||||
"TypeDef": ( traits: ["NameOwner", "AttrsOwner"] ),
|
||||
"ConstDef": ( traits: [
|
||||
"NameOwner",
|
||||
"TypeParamsOwner",
|
||||
"AttrsOwner",
|
||||
] ),
|
||||
"StaticDef": ( traits: [
|
||||
"NameOwner",
|
||||
"TypeParamsOwner",
|
||||
"AttrsOwner",
|
||||
] ),
|
||||
"TypeDef": ( traits: [
|
||||
"NameOwner",
|
||||
"TypeParamsOwner",
|
||||
"AttrsOwner",
|
||||
] ),
|
||||
"ImplItem": (),
|
||||
|
||||
"Name": (),
|
||||
"NameRef": (),
|
||||
"Attr": ( options: [ ["value", "TokenTree"] ] ),
|
||||
"TokenTree": (),
|
||||
|
||||
"ParenType": (),
|
||||
"TupleType": (),
|
||||
"NeverType": (),
|
||||
|
@ -280,7 +299,14 @@ Grammar(
|
|||
|
||||
"NominalDef": (
|
||||
enum: ["StructDef", "EnumDef"],
|
||||
traits: [ "AttrsOwner" ],
|
||||
traits: [ "AttrsOwner", "TypeParamsOwner" ],
|
||||
),
|
||||
|
||||
"Name": (),
|
||||
"NameRef": (),
|
||||
"Attr": ( options: [ ["value", "TokenTree"] ] ),
|
||||
"TokenTree": (),
|
||||
"TypeParamList": (),
|
||||
"WhereClause": (),
|
||||
},
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue