aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/libeditor/src/scope/fn_scope.rs31
-rw-r--r--crates/libsyntax2/src/ast/generated.rs10
-rw-r--r--crates/libsyntax2/src/ast/mod.rs6
-rw-r--r--crates/libsyntax2/src/grammar.ron8
4 files changed, 44 insertions, 11 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
6use libsyntax2::{ 6use 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() {
diff --git a/crates/libsyntax2/src/ast/generated.rs b/crates/libsyntax2/src/ast/generated.rs
index bdee635ae..11306a835 100644
--- a/crates/libsyntax2/src/ast/generated.rs
+++ b/crates/libsyntax2/src/ast/generated.rs
@@ -200,12 +200,10 @@ impl<'a> AstNode<'a> for CallExpr<'a> {
200 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 200 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
201} 201}
202 202
203impl<'a> ast::ArgListOwner<'a> for CallExpr<'a> {}
203impl<'a> CallExpr<'a> {pub fn expr(self) -> Option<Expr<'a>> { 204impl<'a> CallExpr<'a> {pub fn expr(self) -> Option<Expr<'a>> {
204 super::child_opt(self) 205 super::child_opt(self)
205 } 206 }
206pub fn arg_list(self) -> Option<ArgList<'a>> {
207 super::child_opt(self)
208 }
209} 207}
210 208
211// CastExpr 209// CastExpr
@@ -934,7 +932,11 @@ impl<'a> AstNode<'a> for MethodCallExpr<'a> {
934 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 932 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
935} 933}
936 934
937impl<'a> MethodCallExpr<'a> {} 935impl<'a> ast::ArgListOwner<'a> for MethodCallExpr<'a> {}
936impl<'a> MethodCallExpr<'a> {pub fn expr(self) -> Option<Expr<'a>> {
937 super::child_opt(self)
938 }
939}
938 940
939// Module 941// Module
940#[derive(Debug, Clone, Copy)] 942#[derive(Debug, Clone, Copy)]
diff --git a/crates/libsyntax2/src/ast/mod.rs b/crates/libsyntax2/src/ast/mod.rs
index 49e283f5e..274996171 100644
--- a/crates/libsyntax2/src/ast/mod.rs
+++ b/crates/libsyntax2/src/ast/mod.rs
@@ -26,6 +26,12 @@ pub trait LoopBodyOwner<'a>: AstNode<'a> {
26 } 26 }
27} 27}
28 28
29pub trait ArgListOwner<'a>: AstNode<'a> {
30 fn arg_list(self) -> Option<ArgList<'a>> {
31 child_opt(self)
32 }
33}
34
29pub trait TypeParamsOwner<'a>: AstNode<'a> { 35pub trait TypeParamsOwner<'a>: AstNode<'a> {
30 fn type_param_list(self) -> Option<TypeParamList<'a>> { 36 fn type_param_list(self) -> Option<TypeParamList<'a>> {
31 child_opt(self) 37 child_opt(self)
diff --git a/crates/libsyntax2/src/grammar.ron b/crates/libsyntax2/src/grammar.ron
index 798725f7e..683623a5d 100644
--- a/crates/libsyntax2/src/grammar.ron
+++ b/crates/libsyntax2/src/grammar.ron
@@ -388,10 +388,14 @@ Grammar(
388 "NamedFieldList": (), 388 "NamedFieldList": (),
389 "NamedField": (), 389 "NamedField": (),
390 "CallExpr": ( 390 "CallExpr": (
391 options: [ "Expr", "ArgList" ] 391 traits: ["ArgListOwner"],
392 options: [ "Expr" ],
393 ),
394 "MethodCallExpr": (
395 traits: ["ArgListOwner"],
396 options: [ "Expr" ],
392 ), 397 ),
393 "IndexExpr": (), 398 "IndexExpr": (),
394 "MethodCallExpr": (),
395 "FieldExpr": (), 399 "FieldExpr": (),
396 "TryExpr": (), 400 "TryExpr": (),
397 "CastExpr": (), 401 "CastExpr": (),