aboutsummaryrefslogtreecommitdiff
path: root/crates/libeditor/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-11 12:44:12 +0100
committerAleksey Kladov <[email protected]>2018-08-11 12:44:12 +0100
commitf2291d6a760f8a2d15074b5874facb03f5f838bc (patch)
tree00faff0402a675c4a041966e71b1789bfb086dcc /crates/libeditor/src
parent7afd84febc76a75a3ed1be75c57ff35d7b8b3de6 (diff)
doc symbols
Diffstat (limited to 'crates/libeditor/src')
-rw-r--r--crates/libeditor/src/lib.rs39
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
8use libsyntax2::{ 8use 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
103pub 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
116pub fn runnables(file: &ast::File) -> Vec<Runnable> { 103pub 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
139struct Declaration<'f> (SyntaxNodeRef<'f>);
140
141impl<'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}