diff options
Diffstat (limited to 'crates/libeditor/src/symbols.rs')
-rw-r--r-- | crates/libeditor/src/symbols.rs | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/crates/libeditor/src/symbols.rs b/crates/libeditor/src/symbols.rs index cf5bd2a41..d7bd111e6 100644 --- a/crates/libeditor/src/symbols.rs +++ b/crates/libeditor/src/symbols.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use smol_str::SmolStr; | 1 | use smol_str::SmolStr; |
2 | use libsyntax2::{ | 2 | use libsyntax2::{ |
3 | SyntaxKind, SyntaxNodeRef, AstNode, RefRoot, | 3 | SyntaxKind, SyntaxNodeRef, AstNode, ParsedFile, |
4 | ast::{self, NameOwner}, | 4 | ast::{self, NameOwner}, |
5 | algo::{ | 5 | algo::{ |
6 | visit::{visitor, Visitor}, | 6 | visit::{visitor, Visitor}, |
@@ -25,14 +25,14 @@ pub struct FileSymbol { | |||
25 | pub kind: SyntaxKind, | 25 | pub kind: SyntaxKind, |
26 | } | 26 | } |
27 | 27 | ||
28 | pub fn file_symbols(file: &ast::File) -> Vec<FileSymbol> { | 28 | pub fn file_symbols(file: &ParsedFile) -> Vec<FileSymbol> { |
29 | preorder(file.syntax_ref()) | 29 | preorder(file.syntax()) |
30 | .filter_map(to_symbol) | 30 | .filter_map(to_symbol) |
31 | .collect() | 31 | .collect() |
32 | } | 32 | } |
33 | 33 | ||
34 | fn to_symbol(node: SyntaxNodeRef) -> Option<FileSymbol> { | 34 | fn to_symbol(node: SyntaxNodeRef) -> Option<FileSymbol> { |
35 | fn decl<'a, N: NameOwner<RefRoot<'a>>>(node: N) -> Option<FileSymbol> { | 35 | fn decl<'a, N: NameOwner<'a>>(node: N) -> Option<FileSymbol> { |
36 | let name = node.name()?; | 36 | let name = node.name()?; |
37 | Some(FileSymbol { | 37 | Some(FileSymbol { |
38 | name: name.text(), | 38 | name: name.text(), |
@@ -41,23 +41,23 @@ fn to_symbol(node: SyntaxNodeRef) -> Option<FileSymbol> { | |||
41 | }) | 41 | }) |
42 | } | 42 | } |
43 | visitor() | 43 | visitor() |
44 | .visit(decl::<ast::FnDef<_>>) | 44 | .visit(decl::<ast::FnDef>) |
45 | .visit(decl::<ast::StructDef<_>>) | 45 | .visit(decl::<ast::StructDef>) |
46 | .visit(decl::<ast::EnumDef<_>>) | 46 | .visit(decl::<ast::EnumDef>) |
47 | .visit(decl::<ast::TraitDef<_>>) | 47 | .visit(decl::<ast::TraitDef>) |
48 | .visit(decl::<ast::Module<_>>) | 48 | .visit(decl::<ast::Module>) |
49 | .visit(decl::<ast::TypeDef<_>>) | 49 | .visit(decl::<ast::TypeDef>) |
50 | .visit(decl::<ast::ConstDef<_>>) | 50 | .visit(decl::<ast::ConstDef>) |
51 | .visit(decl::<ast::StaticDef<_>>) | 51 | .visit(decl::<ast::StaticDef>) |
52 | .accept(node)? | 52 | .accept(node)? |
53 | } | 53 | } |
54 | 54 | ||
55 | 55 | ||
56 | pub fn file_structure(file: &ast::File) -> Vec<StructureNode> { | 56 | pub fn file_structure(file: &ParsedFile) -> Vec<StructureNode> { |
57 | let mut res = Vec::new(); | 57 | let mut res = Vec::new(); |
58 | let mut stack = Vec::new(); | 58 | let mut stack = Vec::new(); |
59 | 59 | ||
60 | for event in walk(file.syntax_ref()) { | 60 | for event in walk(file.syntax()) { |
61 | match event { | 61 | match event { |
62 | WalkEvent::Enter(node) => { | 62 | WalkEvent::Enter(node) => { |
63 | match structure_node(node) { | 63 | match structure_node(node) { |
@@ -80,7 +80,7 @@ pub fn file_structure(file: &ast::File) -> Vec<StructureNode> { | |||
80 | } | 80 | } |
81 | 81 | ||
82 | fn structure_node(node: SyntaxNodeRef) -> Option<StructureNode> { | 82 | fn structure_node(node: SyntaxNodeRef) -> Option<StructureNode> { |
83 | fn decl<'a, N: NameOwner<RefRoot<'a>>>(node: N) -> Option<StructureNode> { | 83 | fn decl<'a, N: NameOwner<'a>>(node: N) -> Option<StructureNode> { |
84 | let name = node.name()?; | 84 | let name = node.name()?; |
85 | Some(StructureNode { | 85 | Some(StructureNode { |
86 | parent: None, | 86 | parent: None, |
@@ -92,16 +92,16 @@ fn structure_node(node: SyntaxNodeRef) -> Option<StructureNode> { | |||
92 | } | 92 | } |
93 | 93 | ||
94 | visitor() | 94 | visitor() |
95 | .visit(decl::<ast::FnDef<_>>) | 95 | .visit(decl::<ast::FnDef>) |
96 | .visit(decl::<ast::StructDef<_>>) | 96 | .visit(decl::<ast::StructDef>) |
97 | .visit(decl::<ast::NamedField<_>>) | 97 | .visit(decl::<ast::NamedField>) |
98 | .visit(decl::<ast::EnumDef<_>>) | 98 | .visit(decl::<ast::EnumDef>) |
99 | .visit(decl::<ast::TraitDef<_>>) | 99 | .visit(decl::<ast::TraitDef>) |
100 | .visit(decl::<ast::Module<_>>) | 100 | .visit(decl::<ast::Module>) |
101 | .visit(decl::<ast::TypeDef<_>>) | 101 | .visit(decl::<ast::TypeDef>) |
102 | .visit(decl::<ast::ConstDef<_>>) | 102 | .visit(decl::<ast::ConstDef>) |
103 | .visit(decl::<ast::StaticDef<_>>) | 103 | .visit(decl::<ast::StaticDef>) |
104 | .visit(|im: ast::ImplItem<_>| { | 104 | .visit(|im: ast::ImplItem| { |
105 | let target_type = im.target_type()?; | 105 | let target_type = im.target_type()?; |
106 | let target_trait = im.target_trait(); | 106 | let target_trait = im.target_trait(); |
107 | let label = match target_trait { | 107 | let label = match target_trait { |