Skip to content

Commit

Permalink
Improve tree-sitter queries for Scala (helix-editor#9475)
Browse files Browse the repository at this point in the history
- Simplify function highlighting
- Highlight extension methods
- Textobject query (mia/maa) for class/trait constructor parameters/arguments
- Textobject query (mif/maf) for Scala 3 braceless lambdas
  • Loading branch information
jpaju authored and postsolar committed Apr 4, 2024
1 parent 9f88245 commit c1351c8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
27 changes: 6 additions & 21 deletions runtime/queries/scala/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,13 @@
(var_declaration
name: (identifier) @variable)

; method definition
; function definitions/declarations

(class_definition
body: (template_body
[
(function_definition
name: (identifier) @function.method)
(function_declaration
name: (identifier) @function.method)
]))
(trait_definition
body: (template_body
[
(function_definition
name: (identifier) @function.method)
(function_declaration
name: (identifier) @function.method)
]))
(object_definition
body: (template_body
(function_definition
name: (identifier) @function.method)))
(function_declaration
name: (identifier) @function.method)

(function_definition
name: (identifier) @function.method)

; imports/exports

Expand Down
10 changes: 8 additions & 2 deletions runtime/queries/scala/textobjects.scm
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
; Function queries

(function_definition
body: (_) @function.inside) @function.around
body: (_) @function.inside) @function.around ; Does not include end marker

; Does not match block lambdas or Scala 3 braceless lambdas
(lambda_expression
(_) @function.inside) @function.around

; Scala 3 braceless lambda
(colon_argument
(_) @function.inside) @function.around


; Class queries

Expand All @@ -32,6 +35,9 @@
(parameters
((_) @parameter.inside . ","? @parameter.around) @parameter.around)

(class_parameters
((_) @parameter.inside . ","? @parameter.around) @parameter.around)

(parameter_types
((_) @parameter.inside . ","? @parameter.around) @parameter.around)

Expand Down

0 comments on commit c1351c8

Please sign in to comment.