From c16530c988e817c5596fa38ebe9e12a302886a8f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 27 Aug 2018 10:12:28 +0300 Subject: visitor-less scopes --- crates/libeditor/src/completion.rs | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'crates/libeditor/src/completion.rs') diff --git a/crates/libeditor/src/completion.rs b/crates/libeditor/src/completion.rs index 6335dba17..ec9388ee3 100644 --- a/crates/libeditor/src/completion.rs +++ b/crates/libeditor/src/completion.rs @@ -5,7 +5,6 @@ use libsyntax2::{ ast::{self, NameOwner}, algo::{ ancestors, - visit::{visitor_ctx, VisitorCtx}, walk::preorder, generate, }, @@ -52,24 +51,24 @@ fn compute_scopes(fn_def: ast::FnDef) -> FnScopes { let mut scope = root; if let Some(body) = fn_def.body() { - for child in body.syntax().children() { - let _ = visitor_ctx((&mut scopes, &mut scope)) - .visit::(|stmt, (scopes, scope)| { - *scope = scopes.new_scope(*scope); + for stmt in body.statements() { + match stmt { + ast::Stmt::LetStmt(stmt) => { + scope = scopes.new_scope(scope); if let Some(pat) = stmt.pat() { - scopes.add_bindings(*scope, pat); + scopes.add_bindings(scope, pat); } if let Some(expr) = stmt.initializer() { - scopes.set_scope(expr.syntax(), *scope) + scopes.set_scope(expr.syntax(), scope) } - }) - .visit::(|expr, (scopes, scope)| { - scopes.set_scope(expr.syntax(), *scope) - }) - .visit::(|expr, (scopes, scope)| { - scopes.set_scope(expr.syntax(), *scope) - }) - .accept(child); + } + ast::Stmt::ExprStmt(expr) => { + scopes.set_scope(expr.syntax(), scope) + } + } + } + if let Some(expr) = body.expr() { + scopes.set_scope(expr.syntax(), scope) } } scopes -- cgit v1.2.3