diff options
Diffstat (limited to 'crates/libeditor/src')
-rw-r--r-- | crates/libeditor/src/scope/fn_scope.rs | 31 |
1 files changed, 26 insertions, 5 deletions
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::{ | |||
5 | 5 | ||
6 | use libsyntax2::{ | 6 | use libsyntax2::{ |
7 | SyntaxNodeRef, SyntaxNode, SmolStr, AstNode, | 7 | SyntaxNodeRef, SyntaxNode, SmolStr, AstNode, |
8 | ast::{self, NameOwner, LoopBodyOwner}, | 8 | ast::{self, NameOwner, LoopBodyOwner, ArgListOwner}, |
9 | algo::{ancestors, generate, walk::preorder} | 9 | algo::{ancestors, generate, walk::preorder} |
10 | }; | 10 | }; |
11 | 11 | ||
@@ -184,10 +184,10 @@ fn compute_expr_scopes(expr: ast::Expr, scopes: &mut FnScopes, scope: ScopeId) { | |||
184 | } | 184 | } |
185 | } | 185 | } |
186 | ast::Expr::CallExpr(e) => { | 186 | ast::Expr::CallExpr(e) => { |
187 | e.arg_list().into_iter() | 187 | compute_call_scopes(e.expr(), e.arg_list(), scopes, scope); |
188 | .flat_map(|it| it.args()) | 188 | } |
189 | .chain(e.expr()) | 189 | ast::Expr::MethodCallExpr(e) => { |
190 | .for_each(|expr| compute_expr_scopes(expr, scopes, scope)); | 190 | compute_call_scopes(e.expr(), e.arg_list(), scopes, scope); |
191 | } | 191 | } |
192 | ast::Expr::MatchExpr(e) => { | 192 | ast::Expr::MatchExpr(e) => { |
193 | if let Some(expr) = e.expr() { | 193 | if let Some(expr) = e.expr() { |
@@ -210,6 +210,17 @@ fn compute_expr_scopes(expr: ast::Expr, scopes: &mut FnScopes, scope: ScopeId) { | |||
210 | } | 210 | } |
211 | }; | 211 | }; |
212 | 212 | ||
213 | fn compute_call_scopes( | ||
214 | receiver: Option<ast::Expr>, | ||
215 | arg_list: Option<ast::ArgList>, | ||
216 | scopes: &mut FnScopes, scope: ScopeId, | ||
217 | ) { | ||
218 | arg_list.into_iter() | ||
219 | .flat_map(|it| it.args()) | ||
220 | .chain(receiver) | ||
221 | .for_each(|expr| compute_expr_scopes(expr, scopes, scope)); | ||
222 | } | ||
223 | |||
213 | fn compute_cond_scopes(cond: ast::Condition, scopes: &mut FnScopes, scope: ScopeId) -> Option<ScopeId> { | 224 | fn compute_cond_scopes(cond: ast::Condition, scopes: &mut FnScopes, scope: ScopeId) -> Option<ScopeId> { |
214 | if let Some(expr) = cond.expr() { | 225 | if let Some(expr) = cond.expr() { |
215 | compute_expr_scopes(expr, scopes, scope); | 226 | compute_expr_scopes(expr, scopes, scope); |
@@ -280,6 +291,16 @@ mod tests { | |||
280 | } | 291 | } |
281 | 292 | ||
282 | #[test] | 293 | #[test] |
294 | fn test_metod_call_scope() { | ||
295 | do_check(r" | ||
296 | fn quux() { | ||
297 | z.f(|x| <|> ); | ||
298 | }", | ||
299 | &["x"], | ||
300 | ); | ||
301 | } | ||
302 | |||
303 | #[test] | ||
283 | fn test_loop_scope() { | 304 | fn test_loop_scope() { |
284 | do_check(r" | 305 | do_check(r" |
285 | fn quux() { | 306 | fn quux() { |