From bea095afab05e68a9b456a9537e92eb3536d4093 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Thu, 7 Sep 2023 15:52:42 -0400 Subject: [PATCH 1/2] Sync locals from nvim-tree-sitter. 1. Add `(block)` as a `@local.scope` 2. Fix the scope for functions. `function_declaration` is used for abstract functions, while `function_definition` is used for the actual concrete functions (along with their function bodies). 3. Add `(class_parameter)`'s `name` as a local definition. References: - https://github.com/nvim-treesitter/nvim-treesitter/commit/ee64345a3774eaecee5ddec8648390e86450eec8 - https://github.com/nvim-treesitter/nvim-treesitter/commit/06075ecd04892271e6a3fbd5c0d4e89ca6fb8375 --- queries/scala/locals.scm | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/queries/scala/locals.scm b/queries/scala/locals.scm index c5027b5e..ce61fcbc 100644 --- a/queries/scala/locals.scm +++ b/queries/scala/locals.scm @@ -1,16 +1,19 @@ (template_body) @local.scope (lambda_expression) @local.scope - +(block) @local.scope (function_declaration - name: (identifier) @local.definition) @local.scope + name: (identifier) @local.definition) (function_definition - name: (identifier) @local.definition) + name: (identifier) @local.definition) @local.scope (parameter name: (identifier) @local.definition) +(class_parameter + name: (identifier) @local.definition) + (binding name: (identifier) @local.definition) From 3f89d50650131a51a06b2b8079d47807b016cbaa Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Fri, 8 Sep 2023 14:56:50 -0400 Subject: [PATCH 2/2] Add test for `(function_definition) @local.scope` change. This adds a test that illustrates the problem being fixed by moving `@local.scope` from `(function_declaration)` to `(function_definition)`. ```scala def meth_with_params(localParam: Int) { var ref_param = c"$localParam $meth_with_params" // ^parameter // ^method } var okay1 = s"hello" var okay = c"$localParam $okay1" // ^none // ^variable ``` Specifically, the local function parameter (named `localParam`) should only be in scope within the body of `meth_with_params`, but on master (e.g. without the `@local.scope` move to `(function_definition)`) for `var okay = c"$localParam $okay1"` the `localParam` is highlighted as a **parameter**!. Here is the failure for the new test when ran against `master`: ``` Failure - row: 6, column: 14, expected highlight 'none', actual highlights: 'parameter' ``` --- test/highlight/parameter_scope.scala | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 test/highlight/parameter_scope.scala diff --git a/test/highlight/parameter_scope.scala b/test/highlight/parameter_scope.scala new file mode 100644 index 00000000..36719d6a --- /dev/null +++ b/test/highlight/parameter_scope.scala @@ -0,0 +1,9 @@ +def meth_with_params(localParam: Int) { + var ref_param = c"$localParam $meth_with_params" +// ^parameter +// ^method +} +var okay1 = s"hello" +var okay = c"$localParam $okay1" +// ^none +// ^variable