mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
fields are part of the structure
This commit is contained in:
parent
1141d448d9
commit
199e3b73c7
4 changed files with 44 additions and 10 deletions
|
@ -249,6 +249,25 @@ impl<R: TreeRoot> AstNode<R> for NameRef<R> {
|
|||
|
||||
impl<R: TreeRoot> NameRef<R> {}
|
||||
|
||||
// NamedField
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct NamedField<R: TreeRoot = Arc<SyntaxRoot>> {
|
||||
syntax: SyntaxNode<R>,
|
||||
}
|
||||
|
||||
impl<R: TreeRoot> AstNode<R> for NamedField<R> {
|
||||
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
|
||||
match syntax.kind() {
|
||||
NAMED_FIELD => Some(NamedField { syntax }),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
|
||||
}
|
||||
|
||||
impl<R: TreeRoot> ast::NameOwner<R> for NamedField<R> {}
|
||||
impl<R: TreeRoot> NamedField<R> {}
|
||||
|
||||
// NeverType
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct NeverType<R: TreeRoot = Arc<SyntaxRoot>> {
|
||||
|
@ -436,7 +455,13 @@ impl<R: TreeRoot> AstNode<R> for StructDef<R> {
|
|||
}
|
||||
|
||||
impl<R: TreeRoot> ast::NameOwner<R> for StructDef<R> {}
|
||||
impl<R: TreeRoot> StructDef<R> {}
|
||||
impl<R: TreeRoot> StructDef<R> {
|
||||
pub fn fields<'a>(&'a self) -> impl Iterator<Item = NamedField<R>> + 'a {
|
||||
self.syntax()
|
||||
.children()
|
||||
.filter_map(NamedField::cast)
|
||||
}
|
||||
}
|
||||
|
||||
// TraitDef
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
|
|
|
@ -222,7 +222,13 @@ Grammar(
|
|||
]
|
||||
),
|
||||
"FnDef": ( traits: ["NameOwner"] ),
|
||||
"StructDef": ( traits: ["NameOwner"] ),
|
||||
"StructDef": (
|
||||
traits: ["NameOwner"],
|
||||
collections: [
|
||||
["fields", "NamedField"]
|
||||
]
|
||||
),
|
||||
"NamedField": ( traits: ["NameOwner"] ),
|
||||
"EnumDef": ( traits: ["NameOwner"] ),
|
||||
"TraitDef": ( traits: ["NameOwner"] ),
|
||||
"Module": ( traits: ["NameOwner"] ),
|
||||
|
@ -230,6 +236,7 @@ Grammar(
|
|||
"StaticDef": ( traits: ["NameOwner"] ),
|
||||
"TypeDef": ( traits: ["NameOwner"] ),
|
||||
"ImplItem": (),
|
||||
|
||||
"Name": (),
|
||||
"NameRef": (),
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue