From 58480b9190d8851abf7f634820188e33efed286d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 3 Sep 2018 02:01:43 +0300 Subject: method call scope --- crates/libeditor/src/scope/fn_scope.rs | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'crates/libeditor/src/scope/fn_scope.rs') diff --git a/crates/libeditor/src/scope/fn_scope.rs b/crates/libeditor/src/scope/fn_scope.rs index abc8d34e7..60b8ce919 100644 --- a/crates/libeditor/src/scope/fn_scope.rs +++ b/crates/libeditor/src/scope/fn_scope.rs @@ -5,7 +5,7 @@ use std::{ use libsyntax2::{ SyntaxNodeRef, SyntaxNode, SmolStr, AstNode, - ast::{self, NameOwner, LoopBodyOwner}, + ast::{self, NameOwner, LoopBodyOwner, ArgListOwner}, algo::{ancestors, generate, walk::preorder} }; @@ -184,10 +184,10 @@ fn compute_expr_scopes(expr: ast::Expr, scopes: &mut FnScopes, scope: ScopeId) { } } ast::Expr::CallExpr(e) => { - e.arg_list().into_iter() - .flat_map(|it| it.args()) - .chain(e.expr()) - .for_each(|expr| compute_expr_scopes(expr, scopes, scope)); + compute_call_scopes(e.expr(), e.arg_list(), scopes, scope); + } + ast::Expr::MethodCallExpr(e) => { + compute_call_scopes(e.expr(), e.arg_list(), scopes, scope); } ast::Expr::MatchExpr(e) => { if let Some(expr) = e.expr() { @@ -210,6 +210,17 @@ fn compute_expr_scopes(expr: ast::Expr, scopes: &mut FnScopes, scope: ScopeId) { } }; + fn compute_call_scopes( + receiver: Option, + arg_list: Option, + scopes: &mut FnScopes, scope: ScopeId, + ) { + arg_list.into_iter() + .flat_map(|it| it.args()) + .chain(receiver) + .for_each(|expr| compute_expr_scopes(expr, scopes, scope)); + } + fn compute_cond_scopes(cond: ast::Condition, scopes: &mut FnScopes, scope: ScopeId) -> Option { if let Some(expr) = cond.expr() { compute_expr_scopes(expr, scopes, scope); @@ -279,6 +290,16 @@ mod tests { ); } + #[test] + fn test_metod_call_scope() { + do_check(r" + fn quux() { + z.f(|x| <|> ); + }", + &["x"], + ); + } + #[test] fn test_loop_scope() { do_check(r" -- cgit v1.2.3