tree-sitter-scala icon indicating copy to clipboard operation
tree-sitter-scala copied to clipboard

Sync locals from nvim-tree-sitter.

Open rwjblue opened this issue 2 years ago • 4 comments

  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/pull/4723
  • https://github.com/nvim-treesitter/nvim-treesitter/pull/4594

rwjblue avatar Sep 07 '23 21:09 rwjblue

  ✗ basics.scala
    Failure - row: 79, column: 24, expected highlight 'method', actual highlights: 'none'

eed3si9n avatar Sep 08 '23 02:09 eed3si9n

Thank you for reviewing, I'll dig into those failures!

rwjblue avatar Sep 08 '23 15:09 rwjblue

@eed3si9n - As far as I can tell (I'm still ramping up my debugging skills for tree-sitter), the failure here demonstrates a somewhat fundamental issue with how tree-sitter highlight actually works. This issue is discussed over in https://github.com/nvim-treesitter/nvim-treesitter/issues/170 (and resolved in https://github.com/nvim-treesitter/nvim-treesitter/pull/295 by allowing function definitions to specify that they are valid in the parent scope as well as their own child scope).

To illustrate the problem I just pushed a test that is being fixed by moving @local.scope from (function_declaration) to (function_definition).

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'

rwjblue avatar Sep 08 '23 19:09 rwjblue

FWIW, I created https://github.com/nvim-treesitter/nvim-treesitter/pull/5359 to ensure that the nvim-treesitter locals for scala are correct. As far as I can tell there is no corresponding feature for tree-sitter highlight that we could use. (Please correct me if I'm wrong!!)

rwjblue avatar Sep 08 '23 19:09 rwjblue