diff options
author | Aleksey Kladov <[email protected]> | 2018-08-27 08:12:28 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-27 08:12:28 +0100 |
commit | c16530c988e817c5596fa38ebe9e12a302886a8f (patch) | |
tree | fabd59d72906ef169665357dd219a2b862f623f2 /crates/libeditor | |
parent | 8b0298ce095b6dd635f7ed35dc97f1874157040b (diff) |
visitor-less scopes
Diffstat (limited to 'crates/libeditor')
-rw-r--r-- | crates/libeditor/src/completion.rs | 29 |
1 files changed, 14 insertions, 15 deletions
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::{ | |||
5 | ast::{self, NameOwner}, | 5 | ast::{self, NameOwner}, |
6 | algo::{ | 6 | algo::{ |
7 | ancestors, | 7 | ancestors, |
8 | visit::{visitor_ctx, VisitorCtx}, | ||
9 | walk::preorder, | 8 | walk::preorder, |
10 | generate, | 9 | generate, |
11 | }, | 10 | }, |
@@ -52,24 +51,24 @@ fn compute_scopes(fn_def: ast::FnDef) -> FnScopes { | |||
52 | 51 | ||
53 | let mut scope = root; | 52 | let mut scope = root; |
54 | if let Some(body) = fn_def.body() { | 53 | if let Some(body) = fn_def.body() { |
55 | for child in body.syntax().children() { | 54 | for stmt in body.statements() { |
56 | let _ = visitor_ctx((&mut scopes, &mut scope)) | 55 | match stmt { |
57 | .visit::<ast::LetStmt, _>(|stmt, (scopes, scope)| { | 56 | ast::Stmt::LetStmt(stmt) => { |
58 | *scope = scopes.new_scope(*scope); | 57 | scope = scopes.new_scope(scope); |
59 | if let Some(pat) = stmt.pat() { | 58 | if let Some(pat) = stmt.pat() { |
60 | scopes.add_bindings(*scope, pat); | 59 | scopes.add_bindings(scope, pat); |
61 | } | 60 | } |
62 | if let Some(expr) = stmt.initializer() { | 61 | if let Some(expr) = stmt.initializer() { |
63 | scopes.set_scope(expr.syntax(), *scope) | 62 | scopes.set_scope(expr.syntax(), scope) |
64 | } | 63 | } |
65 | }) | 64 | } |
66 | .visit::<ast::ExprStmt, _>(|expr, (scopes, scope)| { | 65 | ast::Stmt::ExprStmt(expr) => { |
67 | scopes.set_scope(expr.syntax(), *scope) | 66 | scopes.set_scope(expr.syntax(), scope) |
68 | }) | 67 | } |
69 | .visit::<ast::Expr, _>(|expr, (scopes, scope)| { | 68 | } |
70 | scopes.set_scope(expr.syntax(), *scope) | 69 | } |
71 | }) | 70 | if let Some(expr) = body.expr() { |
72 | .accept(child); | 71 | scopes.set_scope(expr.syntax(), scope) |
73 | } | 72 | } |
74 | } | 73 | } |
75 | scopes | 74 | scopes |