From f2291d6a760f8a2d15074b5874facb03f5f838bc Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 11 Aug 2018 14:44:12 +0300 Subject: doc symbols --- crates/libeditor/src/lib.rs | 39 +-------------------------------------- 1 file changed, 1 insertion(+), 38 deletions(-) (limited to 'crates/libeditor/src') 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; use libsyntax2::{ ast::{self, NameOwner}, - SyntaxNodeRef, AstNode, + AstNode, algo::walk, SyntaxKind::*, }; @@ -100,19 +100,6 @@ pub fn syntax_tree(file: &ast::File) -> String { ::libsyntax2::utils::dump_tree(&file.syntax()) } -pub fn symbols(file: &ast::File) -> Vec { - let syntax = file.syntax(); - let res: Vec = walk::preorder(syntax.as_ref()) - .filter_map(Declaration::cast) - .filter_map(|decl| { - let name = decl.name()?; - let range = decl.range(); - Some(Symbol { name, range }) - }) - .collect(); - res // NLL :-( -} - pub fn runnables(file: &ast::File) -> Vec { file .functions() @@ -134,27 +121,3 @@ pub fn runnables(file: &ast::File) -> Vec { }) .collect() } - - -struct Declaration<'f> (SyntaxNodeRef<'f>); - -impl<'f> Declaration<'f> { - fn cast(node: SyntaxNodeRef<'f>) -> Option> { - match node.kind() { - | STRUCT | ENUM | FUNCTION | TRAIT - | CONST_ITEM | STATIC_ITEM | MODULE | NAMED_FIELD - | TYPE_ITEM => Some(Declaration(node)), - _ => None - } - } - - fn name(&self) -> Option { - let name = self.0.children() - .find(|child| child.kind() == NAME)?; - Some(name.text()) - } - - fn range(&self) -> TextRange { - self.0.range() - } -} -- cgit v1.2.3