From 541d79b40589c51505fe2b80be57443b7dda7370 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Thu, 7 Sep 2023 18:18:37 -0400 Subject: [PATCH] Add `(for_expression)` to locals.scm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change does two main things: 1. Indicate that `(for_expression)`'s introduce a `@local.scope` (this is the scope for the enumerators to be used within the loop). 2. Indicate that the `(identifiers)` within the `(enumerators)` are `@local.definition`s. --- For the following example snippet: ```scala val fruits = List("apple", "banana", "avocado", "papaya") val countsToFruits = fruits.groupBy(fruit => fruit.count(_ == 'a')) for ((count, fruits) <- countsToFruits) { println(s"with (fruits) 'a' × $count = $fruits") } ``` The `count` and `fruits` identifiers are new definitions introduced by the `for` expressions scope. --- queries/scala/locals.scm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/queries/scala/locals.scm b/queries/scala/locals.scm index c5027b5..9d4098c 100644 --- a/queries/scala/locals.scm +++ b/queries/scala/locals.scm @@ -1,6 +1,6 @@ (template_body) @local.scope (lambda_expression) @local.scope - +(for_expression) @local.scope (function_declaration name: (identifier) @local.definition) @local.scope @@ -26,5 +26,11 @@ (var_declaration name: (identifier) @local.definition) +(for_expression + enumerators: (enumerators + (enumerator + (tuple_pattern + (identifier) @local.definition)))) + (identifier) @local.reference