Skip to content

Commit

Permalink
Extend groovy support
Browse files Browse the repository at this point in the history
- Use more complete parser introduced in nvm-treesitter in
  nvim-treesitter/nvim-treesitter@d4dac52
- Use groovy support when working with *.gradle files
  • Loading branch information
britter committed Feb 20, 2024
1 parent 990378a commit 701b6c2
Show file tree
Hide file tree
Showing 6 changed files with 305 additions and 83 deletions.
4 changes: 2 additions & 2 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3130,11 +3130,11 @@ source = { git = "https://github.com/apple/tree-sitter-pkl", rev = "c03f04a313b7
name = "groovy"
language-id = "groovy"
scope = "source.groovy"
file-types = ["groovy", "jenkinsfile", { glob = "Jenkinsfile" }, { glob = "Jenkinsfile.*" }]
file-types = ["gradle", "groovy", "jenkinsfile", { glob = "Jenkinsfile" }, { glob = "Jenkinsfile.*" }]
shebangs = ["groovy"]
comment-token = "//"
indent = { tab-width = 2, unit = " " }

[[grammar]]
name = "groovy"
source = { git = "https://github.com/Decodetalkers/tree-sitter-groovy", rev = "7e023227f46fee428b16a0288eeb0f65ee2523ec" }
source = { git = "https://github.com/murtaza64/tree-sitter-groovy", rev = "235009aad0f580211fc12014bb0846c3910130c1" }
6 changes: 6 additions & 0 deletions runtime/queries/groovy/folds.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
(argument_list)
(closure)
(list)
(map)
] @fold
330 changes: 251 additions & 79 deletions runtime/queries/groovy/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,96 +1,268 @@
(unit
(identifier) @variable)
[
"!instanceof"
"assert"
"class"
"extends"
"instanceof"
"package"
] @keyword

(string
(identifier) @variable)
[
"!in"
"as"
"in"
] @keyword.operator

[
"case"
"default"
"else"
"if"
"switch"
] @keyword.conditional

(escape_sequence) @constant.character.escape
[
"catch"
"finally"
"try"
] @keyword.exception

(block
(unit
(identifier) @namespace))
"def" @keyword.function

(func
(identifier) @function)
"import" @keyword.import

(number) @constant.numeric
[
"for"
"while"
(break)
(continue)
] @keyword.repeat

((identifier) @constant.builtin.boolean
(#any-of? @constant.builtin.boolean "true" "false"))
"return" @keyword.return

((identifier) @constant
(#match? @constant "^[A-Z][A-Z\\d_]*$"))

((identifier) @constant.builtin
(#eq? @constant.builtin "null"))

((identifier) @type
(#any-of? @type
"String"
"Map"
"Object"
"Boolean"
"Integer"
"List"))

((identifier) @function.builtin
(#any-of? @function.builtin
"void"
"id"
"version"
"apply"
"implementation"
"testImplementation"
"androidTestImplementation"
"debugImplementation"))

((identifier) @keyword.storage.modifier
(#eq? @keyword.storage.modifier "static"))

((identifier) @keyword.storage.type
(#any-of? @keyword.storage.type "class" "def" "interface"))

((identifier) @keyword
(#any-of? @keyword
"assert"
"new"
"extends"
"implements"
"instanceof"))

((identifier) @keyword.control.import
(#any-of? @keyword.control.import "import" "package"))

((identifier) @keyword.storage.modifier
(#any-of? @keyword.storage.modifier
"abstract"
"protected"
"private"
"public"))

((identifier) @keyword.control.exception
(#any-of? @keyword.control.exception
"throw"
"finally"
"try"
"catch"))
[
"true"
"false"
] @boolean

(null) @constant.builtin

"this" @variable.builtin

[
"int"
"char"
"short"
"long"
"boolean"
"float"
"double"
"void"
] @type.builtin

[
"final"
"private"
"protected"
"public"
"static"
"synchronized"
] @type.qualifier

(comment) @comment @spell

(shebang) @keyword.directive

(string) @string

(string
(escape_sequence) @string.escape)

(string
(interpolation
"$" @punctuation.special))

[
"("
")"
"["
"]"
"{"
"}"
] @punctuation.bracket

[
(line_comment)
(block_comment)
] @comment
":"
","
"."
] @punctuation.delimiter

(number_literal) @number

((block_comment) @comment.block.documentation
(#match? @comment.block.documentation "^/[*][*][^*](?s:.)*[*]/$"))
(identifier) @variable

((line_comment) @comment.block.documentation
(#match? @comment.block.documentation "^///[^/]*.*$"))
((identifier) @constant
(#match? @constant "^[A-Z][A-Z_]+"))

[
(operators)
(leading_key)
"%"
"*"
"/"
"+"
"-"
"<<"
">>"
">>>"
".."
"..<"
"<..<"
"<.."
"<"
"<="
">"
">="
"=="
"!="
"<=>"
"==="
"!=="
"=~"
"==~"
"&"
"^"
"|"
"&&"
"||"
"?:"
"+"
"*"
".&"
".@"
"?."
"*."
"*"
"*:"
"++"
"--"
"!"
] @operator

["(" ")" "[" "]" "{" "}"] @punctuation.bracket
(string
"/" @string)

(ternary_op
([
"?"
":"
]) @keyword.conditional.ternary)

(map
(map_item
key: (identifier) @variable.parameter))

(parameter
type: (identifier) @type
name: (identifier) @variable.parameter)

(generic_param
name: (identifier) @variable.parameter)

(declaration
type: (identifier) @type)

(function_definition
type: (identifier) @type)

(function_declaration
type: (identifier) @type)

(class_definition
name: (identifier) @type)

(class_definition
superclass: (identifier) @type)

(generic_param
superclass: (identifier) @type)

(type_with_generics
(identifier) @type)

(type_with_generics
(generics
(identifier) @type))

(generics
[
"<"
">"
] @punctuation.bracket)

(generic_parameters
[
"<"
">"
] @punctuation.bracket)

; TODO: Class literals with PascalCase
(declaration
"=" @operator)

(assignment
"=" @operator)

(function_call
function: (identifier) @function)

(function_call
function:
(dotted_identifier
(identifier) @function .))

(function_call
(argument_list
(map_item
key: (identifier) @variable.parameter)))

(juxt_function_call
function: (identifier) @function)

(juxt_function_call
function:
(dotted_identifier
(identifier) @function .))

(juxt_function_call
(argument_list
(map_item
key: (identifier) @variable.parameter)))

(function_definition
function: (identifier) @function)

(function_declaration
function: (identifier) @function)

(annotation) @function.macro

(annotation
(identifier) @function.macro)

"@interface" @function.macro

(groovy_doc) @comment.documentation @spell

(groovy_doc
[
(groovy_doc_param)
(groovy_doc_throws)
(groovy_doc_tag)
] @string.special @nospell)

(groovy_doc
(groovy_doc_param
(identifier) @variable.parameter) @nospell)

(groovy_doc
(groovy_doc_throws
(identifier) @type @nospell))
Loading

0 comments on commit 701b6c2

Please sign in to comment.