aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/libeditor/src/symbols.rs1
-rw-r--r--crates/libeditor/tests/test.rs17
-rw-r--r--crates/libsyntax2/src/ast/generated.rs27
-rw-r--r--crates/libsyntax2/src/grammar.ron9
4 files changed, 44 insertions, 10 deletions
diff --git a/crates/libeditor/src/symbols.rs b/crates/libeditor/src/symbols.rs
index 8419f08e6..6f8853770 100644
--- a/crates/libeditor/src/symbols.rs
+++ b/crates/libeditor/src/symbols.rs
@@ -96,6 +96,7 @@ fn structure_node(node: SyntaxNodeRef) -> Option<StructureNode> {
96 visitor() 96 visitor()
97 .visit(decl::<ast::FnDef<_>>) 97 .visit(decl::<ast::FnDef<_>>)
98 .visit(decl::<ast::StructDef<_>>) 98 .visit(decl::<ast::StructDef<_>>)
99 .visit(decl::<ast::NamedField<_>>)
99 .visit(decl::<ast::EnumDef<_>>) 100 .visit(decl::<ast::EnumDef<_>>)
100 .visit(decl::<ast::TraitDef<_>>) 101 .visit(decl::<ast::TraitDef<_>>)
101 .visit(decl::<ast::Module<_>>) 102 .visit(decl::<ast::Module<_>>)
diff --git a/crates/libeditor/tests/test.rs b/crates/libeditor/tests/test.rs
index 91df74bd6..dd2c99c3f 100644
--- a/crates/libeditor/tests/test.rs
+++ b/crates/libeditor/tests/test.rs
@@ -88,14 +88,15 @@ impl fmt::Debug for E {}
88 let symbols = file_structure(&file); 88 let symbols = file_structure(&file);
89 dbg_eq( 89 dbg_eq(
90 r#"[StructureNode { parent: None, label: "Foo", navigation_range: [8; 11), node_range: [1; 26), kind: STRUCT_DEF }, 90 r#"[StructureNode { parent: None, label: "Foo", navigation_range: [8; 11), node_range: [1; 26), kind: STRUCT_DEF },
91 StructureNode { parent: None, label: "m", navigation_range: [32; 33), node_range: [28; 53), kind: MODULE }, 91 StructureNode { parent: Some(0), label: "x", navigation_range: [18; 19), node_range: [18; 24), kind: NAMED_FIELD },
92 StructureNode { parent: Some(1), label: "bar", navigation_range: [43; 46), node_range: [40; 51), kind: FN_DEF }, 92 StructureNode { parent: None, label: "m", navigation_range: [32; 33), node_range: [28; 53), kind: MODULE },
93 StructureNode { parent: None, label: "E", navigation_range: [60; 61), node_range: [55; 75), kind: ENUM_DEF }, 93 StructureNode { parent: Some(2), label: "bar", navigation_range: [43; 46), node_range: [40; 51), kind: FN_DEF },
94 StructureNode { parent: None, label: "T", navigation_range: [81; 82), node_range: [76; 88), kind: TYPE_DEF }, 94 StructureNode { parent: None, label: "E", navigation_range: [60; 61), node_range: [55; 75), kind: ENUM_DEF },
95 StructureNode { parent: None, label: "S", navigation_range: [96; 97), node_range: [89; 108), kind: STATIC_DEF }, 95 StructureNode { parent: None, label: "T", navigation_range: [81; 82), node_range: [76; 88), kind: TYPE_DEF },
96 StructureNode { parent: None, label: "C", navigation_range: [115; 116), node_range: [109; 127), kind: CONST_DEF }, 96 StructureNode { parent: None, label: "S", navigation_range: [96; 97), node_range: [89; 108), kind: STATIC_DEF },
97 StructureNode { parent: None, label: "impl E", navigation_range: [134; 135), node_range: [129; 138), kind: IMPL_ITEM }, 97 StructureNode { parent: None, label: "C", navigation_range: [115; 116), node_range: [109; 127), kind: CONST_DEF },
98 StructureNode { parent: None, label: "impl fmt::Debug for E", navigation_range: [160; 161), node_range: [140; 164), kind: IMPL_ITEM }]"#, 98 StructureNode { parent: None, label: "impl E", navigation_range: [134; 135), node_range: [129; 138), kind: IMPL_ITEM },
99 StructureNode { parent: None, label: "impl fmt::Debug for E", navigation_range: [160; 161), node_range: [140; 164), kind: IMPL_ITEM }]"#,
99 &symbols, 100 &symbols,
100 ) 101 )
101} 102}
diff --git a/crates/libsyntax2/src/ast/generated.rs b/crates/libsyntax2/src/ast/generated.rs
index 80670ce71..1ec05c950 100644
--- a/crates/libsyntax2/src/ast/generated.rs
+++ b/crates/libsyntax2/src/ast/generated.rs
@@ -249,6 +249,25 @@ impl<R: TreeRoot> AstNode<R> for NameRef<R> {
249 249
250impl<R: TreeRoot> NameRef<R> {} 250impl<R: TreeRoot> NameRef<R> {}
251 251
252// NamedField
253#[derive(Debug, Clone, Copy)]
254pub struct NamedField<R: TreeRoot = Arc<SyntaxRoot>> {
255 syntax: SyntaxNode<R>,
256}
257
258impl<R: TreeRoot> AstNode<R> for NamedField<R> {
259 fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
260 match syntax.kind() {
261 NAMED_FIELD => Some(NamedField { syntax }),
262 _ => None,
263 }
264 }
265 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
266}
267
268impl<R: TreeRoot> ast::NameOwner<R> for NamedField<R> {}
269impl<R: TreeRoot> NamedField<R> {}
270
252// NeverType 271// NeverType
253#[derive(Debug, Clone, Copy)] 272#[derive(Debug, Clone, Copy)]
254pub struct NeverType<R: TreeRoot = Arc<SyntaxRoot>> { 273pub struct NeverType<R: TreeRoot = Arc<SyntaxRoot>> {
@@ -436,7 +455,13 @@ impl<R: TreeRoot> AstNode<R> for StructDef<R> {
436} 455}
437 456
438impl<R: TreeRoot> ast::NameOwner<R> for StructDef<R> {} 457impl<R: TreeRoot> ast::NameOwner<R> for StructDef<R> {}
439impl<R: TreeRoot> StructDef<R> {} 458impl<R: TreeRoot> StructDef<R> {
459 pub fn fields<'a>(&'a self) -> impl Iterator<Item = NamedField<R>> + 'a {
460 self.syntax()
461 .children()
462 .filter_map(NamedField::cast)
463 }
464}
440 465
441// TraitDef 466// TraitDef
442#[derive(Debug, Clone, Copy)] 467#[derive(Debug, Clone, Copy)]
diff --git a/crates/libsyntax2/src/grammar.ron b/crates/libsyntax2/src/grammar.ron
index 3ae403bb5..aa28ab922 100644
--- a/crates/libsyntax2/src/grammar.ron
+++ b/crates/libsyntax2/src/grammar.ron
@@ -222,7 +222,13 @@ Grammar(
222 ] 222 ]
223 ), 223 ),
224 "FnDef": ( traits: ["NameOwner"] ), 224 "FnDef": ( traits: ["NameOwner"] ),
225 "StructDef": ( traits: ["NameOwner"] ), 225 "StructDef": (
226 traits: ["NameOwner"],
227 collections: [
228 ["fields", "NamedField"]
229 ]
230 ),
231 "NamedField": ( traits: ["NameOwner"] ),
226 "EnumDef": ( traits: ["NameOwner"] ), 232 "EnumDef": ( traits: ["NameOwner"] ),
227 "TraitDef": ( traits: ["NameOwner"] ), 233 "TraitDef": ( traits: ["NameOwner"] ),
228 "Module": ( traits: ["NameOwner"] ), 234 "Module": ( traits: ["NameOwner"] ),
@@ -230,6 +236,7 @@ Grammar(
230 "StaticDef": ( traits: ["NameOwner"] ), 236 "StaticDef": ( traits: ["NameOwner"] ),
231 "TypeDef": ( traits: ["NameOwner"] ), 237 "TypeDef": ( traits: ["NameOwner"] ),
232 "ImplItem": (), 238 "ImplItem": (),
239
233 "Name": (), 240 "Name": (),
234 "NameRef": (), 241 "NameRef": (),
235 242