diff options
Diffstat (limited to 'crates/libeditor/src')
-rw-r--r-- | crates/libeditor/src/lib.rs | 39 |
1 files changed, 1 insertions, 38 deletions
diff --git a/crates/libeditor/src/lib.rs b/crates/libeditor/src/lib.rs index 4ea344b17..013d27450 100644 --- a/crates/libeditor/src/lib.rs +++ b/crates/libeditor/src/lib.rs | |||
@@ -7,7 +7,7 @@ mod line_index; | |||
7 | 7 | ||
8 | use libsyntax2::{ | 8 | use libsyntax2::{ |
9 | ast::{self, NameOwner}, | 9 | ast::{self, NameOwner}, |
10 | SyntaxNodeRef, AstNode, | 10 | AstNode, |
11 | algo::walk, | 11 | algo::walk, |
12 | SyntaxKind::*, | 12 | SyntaxKind::*, |
13 | }; | 13 | }; |
@@ -100,19 +100,6 @@ pub fn syntax_tree(file: &ast::File) -> String { | |||
100 | ::libsyntax2::utils::dump_tree(&file.syntax()) | 100 | ::libsyntax2::utils::dump_tree(&file.syntax()) |
101 | } | 101 | } |
102 | 102 | ||
103 | pub fn symbols(file: &ast::File) -> Vec<Symbol> { | ||
104 | let syntax = file.syntax(); | ||
105 | let res: Vec<Symbol> = walk::preorder(syntax.as_ref()) | ||
106 | .filter_map(Declaration::cast) | ||
107 | .filter_map(|decl| { | ||
108 | let name = decl.name()?; | ||
109 | let range = decl.range(); | ||
110 | Some(Symbol { name, range }) | ||
111 | }) | ||
112 | .collect(); | ||
113 | res // NLL :-( | ||
114 | } | ||
115 | |||
116 | pub fn runnables(file: &ast::File) -> Vec<Runnable> { | 103 | pub fn runnables(file: &ast::File) -> Vec<Runnable> { |
117 | file | 104 | file |
118 | .functions() | 105 | .functions() |
@@ -134,27 +121,3 @@ pub fn runnables(file: &ast::File) -> Vec<Runnable> { | |||
134 | }) | 121 | }) |
135 | .collect() | 122 | .collect() |
136 | } | 123 | } |
137 | |||
138 | |||
139 | struct Declaration<'f> (SyntaxNodeRef<'f>); | ||
140 | |||
141 | impl<'f> Declaration<'f> { | ||
142 | fn cast(node: SyntaxNodeRef<'f>) -> Option<Declaration<'f>> { | ||
143 | match node.kind() { | ||
144 | | STRUCT | ENUM | FUNCTION | TRAIT | ||
145 | | CONST_ITEM | STATIC_ITEM | MODULE | NAMED_FIELD | ||
146 | | TYPE_ITEM => Some(Declaration(node)), | ||
147 | _ => None | ||
148 | } | ||
149 | } | ||
150 | |||
151 | fn name(&self) -> Option<String> { | ||
152 | let name = self.0.children() | ||
153 | .find(|child| child.kind() == NAME)?; | ||
154 | Some(name.text()) | ||
155 | } | ||
156 | |||
157 | fn range(&self) -> TextRange { | ||
158 | self.0.range() | ||
159 | } | ||
160 | } | ||