From d3c90ded2b9a4f75e101fa3abc60cd3aebc439c9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 17 Aug 2018 22:00:13 +0300 Subject: Borrowed AST --- crates/libeditor/src/symbols.rs | 50 ++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'crates/libeditor/src/symbols.rs') 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 @@ use smol_str::SmolStr; use libsyntax2::{ - SyntaxKind, SyntaxNodeRef, AstNode, RefRoot, + SyntaxKind, SyntaxNodeRef, AstNode, ParsedFile, ast::{self, NameOwner}, algo::{ visit::{visitor, Visitor}, @@ -25,14 +25,14 @@ pub struct FileSymbol { pub kind: SyntaxKind, } -pub fn file_symbols(file: &ast::File) -> Vec { - preorder(file.syntax_ref()) +pub fn file_symbols(file: &ParsedFile) -> Vec { + preorder(file.syntax()) .filter_map(to_symbol) .collect() } fn to_symbol(node: SyntaxNodeRef) -> Option { - fn decl<'a, N: NameOwner>>(node: N) -> Option { + fn decl<'a, N: NameOwner<'a>>(node: N) -> Option { let name = node.name()?; Some(FileSymbol { name: name.text(), @@ -41,23 +41,23 @@ fn to_symbol(node: SyntaxNodeRef) -> Option { }) } visitor() - .visit(decl::>) - .visit(decl::>) - .visit(decl::>) - .visit(decl::>) - .visit(decl::>) - .visit(decl::>) - .visit(decl::>) - .visit(decl::>) + .visit(decl::) + .visit(decl::) + .visit(decl::) + .visit(decl::) + .visit(decl::) + .visit(decl::) + .visit(decl::) + .visit(decl::) .accept(node)? } -pub fn file_structure(file: &ast::File) -> Vec { +pub fn file_structure(file: &ParsedFile) -> Vec { let mut res = Vec::new(); let mut stack = Vec::new(); - for event in walk(file.syntax_ref()) { + for event in walk(file.syntax()) { match event { WalkEvent::Enter(node) => { match structure_node(node) { @@ -80,7 +80,7 @@ pub fn file_structure(file: &ast::File) -> Vec { } fn structure_node(node: SyntaxNodeRef) -> Option { - fn decl<'a, N: NameOwner>>(node: N) -> Option { + fn decl<'a, N: NameOwner<'a>>(node: N) -> Option { let name = node.name()?; Some(StructureNode { parent: None, @@ -92,16 +92,16 @@ fn structure_node(node: SyntaxNodeRef) -> Option { } visitor() - .visit(decl::>) - .visit(decl::>) - .visit(decl::>) - .visit(decl::>) - .visit(decl::>) - .visit(decl::>) - .visit(decl::>) - .visit(decl::>) - .visit(decl::>) - .visit(|im: ast::ImplItem<_>| { + .visit(decl::) + .visit(decl::) + .visit(decl::) + .visit(decl::) + .visit(decl::) + .visit(decl::) + .visit(decl::) + .visit(decl::) + .visit(decl::) + .visit(|im: ast::ImplItem| { let target_type = im.target_type()?; let target_trait = im.target_trait(); let label = match target_trait { -- cgit v1.2.3