From d4dac523d2546afc266eb9b5a7986690b5319c41 Mon Sep 17 00:00:00 2001 From: Murtaza Date: Sun, 28 Jan 2024 16:17:50 -0500 Subject: [PATCH] feat(groovy)!: switch to more complete parser (#5957) Co-authored-by: ObserverOfTime --- README.md | 2 +- lockfile.json | 2 +- lua/nvim-treesitter/parsers.lua | 5 +- queries/groovy/folds.scm | 6 + queries/groovy/highlights.scm | 286 +++++++++++++++++++++++++++----- queries/groovy/indents.scm | 35 ++++ queries/groovy/injections.scm | 4 +- queries/groovy/locals.scm | 6 + 8 files changed, 295 insertions(+), 51 deletions(-) create mode 100644 queries/groovy/folds.scm create mode 100644 queries/groovy/indents.scm create mode 100644 queries/groovy/locals.scm diff --git a/README.md b/README.md index e965db03d..786aa2276 100644 --- a/README.md +++ b/README.md @@ -252,7 +252,7 @@ We are looking for maintainers to add more parsers and to write query files for - [x] [gowork](https://github.com/omertuc/tree-sitter-go-work) (maintained by @omertuc) - [x] [gpg](https://github.com/ObserverOfTime/tree-sitter-gpg-config) (maintained by @ObserverOfTime) - [x] [graphql](https://github.com/bkegley/tree-sitter-graphql) (maintained by @bkegley) -- [x] [groovy](https://github.com/Decodetalkers/tree-sitter-groovy) (maintained by @Decodetalkers) +- [x] [groovy](https://github.com/murtaza64/tree-sitter-groovy) (maintained by @murtaza64) - [x] [gstlaunch](https://github.com/theHamsta/tree-sitter-gstlaunch) (maintained by @theHamsta) - [ ] [hack](https://github.com/slackhq/tree-sitter-hack) - [x] [hare](https://github.com/amaanq/tree-sitter-hare) (maintained by @amaanq) diff --git a/lockfile.json b/lockfile.json index 7a08271e6..705771637 100644 --- a/lockfile.json +++ b/lockfile.json @@ -237,7 +237,7 @@ "revision": "5e66e961eee421786bdda8495ed1db045e06b5fe" }, "groovy": { - "revision": "7e023227f46fee428b16a0288eeb0f65ee2523ec" + "revision": "e20f616e6223b66defabc82c29f52431ee66e269" }, "gstlaunch": { "revision": "2c0d9c94d35e37aa63fa5002163c8480985b3e5b" diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua index da83e0a22..e31f19747 100644 --- a/lua/nvim-treesitter/parsers.lua +++ b/lua/nvim-treesitter/parsers.lua @@ -737,11 +737,10 @@ list.gpg = { list.groovy = { install_info = { - url = "https://github.com/Decodetalkers/tree-sitter-groovy", + url = "https://github.com/murtaza64/tree-sitter-groovy", files = { "src/parser.c" }, - branch = "gh-pages", }, - maintainers = { "@Decodetalkers" }, + maintainers = { "@murtaza64" }, } list.graphql = { diff --git a/queries/groovy/folds.scm b/queries/groovy/folds.scm new file mode 100644 index 000000000..354861a61 --- /dev/null +++ b/queries/groovy/folds.scm @@ -0,0 +1,6 @@ +[ + (argument_list) + (closure) + (list) + (map) +] @fold diff --git a/queries/groovy/highlights.scm b/queries/groovy/highlights.scm index 4306f17a3..aadd04fe4 100644 --- a/queries/groovy/highlights.scm +++ b/queries/groovy/highlights.scm @@ -1,64 +1,86 @@ -(unit - (identifier) @variable) +[ + "!instanceof" + "assert" + "class" + "extends" + "instanceof" + "package" +] @keyword -(string - (identifier) @variable) +[ + "!in" + "as" + "in" +] @keyword.operator -(escape_sequence) @string.escape +[ + "case" + "default" + "else" + "if" + "switch" +] @keyword.conditional -(block - (unit - (identifier) @module)) +[ + "catch" + "finally" + "try" +] @keyword.exception -(func - (identifier) @function) +"def" @keyword.function -(number) @number +"import" @keyword.import -((identifier) @boolean - (#any-of? @boolean "true" "false" "True" "False")) +[ + "for" + "while" + (break) + (continue) +] @keyword.repeat -((identifier) @constant - (#lua-match? @constant "^[A-Z][A-Z%d_]*$")) +"return" @keyword.return -((identifier) @constant.builtin - (#eq? @constant.builtin "null")) +[ + "true" + "false" +] @boolean -((identifier) @type - (#any-of? @type "String" "Map" "Object" "Boolean" "Integer" "List")) +(null) @constant.builtin -((identifier) @function.builtin - (#any-of? @function.builtin "void" "id" "version" "apply" "implementation" "testImplementation" "androidTestImplementation" "debugImplementation")) +"this" @variable.builtin -((identifier) @keyword - (#any-of? @keyword "static" "class" "def" "import" "package" "assert" "extends" "implements" "instanceof" "interface" "new")) +[ + "int" + "char" + "short" + "long" + "boolean" + "float" + "double" + "void" +] @type.builtin -((identifier) @type.qualifier - (#any-of? @type.qualifier "abstract" "protected" "private" "public")) +[ + "final" + "private" + "protected" + "public" + "static" + "synchronized" +] @type.qualifier -((identifier) @keyword.exception - (#any-of? @keyword.exception "throw" "finally" "try" "catch")) +(comment) @comment @spell + +(shebang) @keyword.directive (string) @string -[ - (line_comment) - (block_comment) -] @comment @spell +(string + (escape_sequence) @string.escape) -((block_comment) @comment.documentation - (#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$")) - -((line_comment) @comment.documentation - (#lua-match? @comment.documentation "^///[^/]")) - -((line_comment) @comment.documentation - (#lua-match? @comment.documentation "^///$")) - -[ - (operators) - (leading_key) -] @operator +(string + (interpolation + "$" @punctuation.special)) [ "(" @@ -68,3 +90,179 @@ "{" "}" ] @punctuation.bracket + +[ + ":" + "," + "." +] @punctuation.delimiter + +(number_literal) @number + +(identifier) @variable + +((identifier) @constant + (#match? @constant "^[A-Z][A-Z_]+")) + +[ + "%" + "*" + "/" + "+" + "-" + "<<" + ">>" + ">>>" + ".." + "..<" + "<..<" + "<.." + "<" + "<=" + ">" + ">=" + "==" + "!=" + "<=>" + "===" + "!==" + "=~" + "==~" + "&" + "^" + "|" + "&&" + "||" + "?:" + "+" + "*" + ".&" + ".@" + "?." + "*." + "*" + "*:" + "++" + "--" + "!" +] @operator + +(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)) diff --git a/queries/groovy/indents.scm b/queries/groovy/indents.scm new file mode 100644 index 000000000..888d50107 --- /dev/null +++ b/queries/groovy/indents.scm @@ -0,0 +1,35 @@ +[ + (closure) + (map) + (list) + (argument_list) + (parameter_list) + (for_parameters) +] @indent.begin + +; (function_definition "(" @indent.begin) +(closure + "}" @indent.end) + +(argument_list + ")" @indent.end) + +(for_parameters + ")" @indent.end) + +((for_loop + body: (_) @_body) @indent.begin + (#not-has-type? @_body closure)) + +; TODO: while, try +(list + "]" @indent.end) + +(map + "]" @indent.end) + +[ + "}" + ")" + "]" +] @indent.branch diff --git a/queries/groovy/injections.scm b/queries/groovy/injections.scm index 14a5d393e..1c04c65fb 100644 --- a/queries/groovy/injections.scm +++ b/queries/groovy/injections.scm @@ -1,5 +1,5 @@ -((block_comment) @injection.content +((comment) @injection.content (#set! injection.language "comment")) -((line_comment) @injection.content +((groovy_doc) @injection.content (#set! injection.language "comment")) diff --git a/queries/groovy/locals.scm b/queries/groovy/locals.scm new file mode 100644 index 000000000..23cb5f0cb --- /dev/null +++ b/queries/groovy/locals.scm @@ -0,0 +1,6 @@ +(function_definition) @local.scope + +(parameter + name: (identifier) @local.definition.parameter) + +(identifier) @local.reference