From 9f6f10ebae503b51cabc62393bca2e10a1eef40c Mon Sep 17 00:00:00 2001 From: Benedikt Ritter Date: Tue, 20 Feb 2024 16:05:12 +0100 Subject: [PATCH 1/5] Extend groovy support Use more complete parser introduced in nvm-treesitter in https://github.com/nvim-treesitter/nvim-treesitter/commit/d4dac523d2546afc266eb9b5a7986690b5319c41 --- book/src/generated/lang-support.md | 2 +- languages.toml | 2 +- runtime/queries/groovy/folds.scm | 6 + runtime/queries/groovy/highlights.scm | 330 ++++++++++++++++++++------ runtime/queries/groovy/indents.scm | 35 +++ runtime/queries/groovy/injections.scm | 7 +- runtime/queries/groovy/locals.scm | 6 + 7 files changed, 305 insertions(+), 83 deletions(-) create mode 100644 runtime/queries/groovy/folds.scm create mode 100644 runtime/queries/groovy/indents.scm create mode 100644 runtime/queries/groovy/locals.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 1bc6b0817036..6faf98408f6b 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -66,7 +66,7 @@ | gotmpl | ✓ | | | `gopls` | | gowork | ✓ | | | `gopls` | | graphql | ✓ | | | `graphql-lsp` | -| groovy | ✓ | | | | +| groovy | ✓ | | ✓ | | | hare | ✓ | | | | | haskell | ✓ | ✓ | | `haskell-language-server-wrapper` | | haskell-persistent | ✓ | | | | diff --git a/languages.toml b/languages.toml index ea2339f8bae3..4c585e5faee3 100644 --- a/languages.toml +++ b/languages.toml @@ -3224,7 +3224,7 @@ 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" } [[language]] name = "fidl" diff --git a/runtime/queries/groovy/folds.scm b/runtime/queries/groovy/folds.scm new file mode 100644 index 000000000000..354861a61105 --- /dev/null +++ b/runtime/queries/groovy/folds.scm @@ -0,0 +1,6 @@ +[ + (argument_list) + (closure) + (list) + (map) +] @fold diff --git a/runtime/queries/groovy/highlights.scm b/runtime/queries/groovy/highlights.scm index 4e94ccd3a1ee..aadd04fe453a 100644 --- a/runtime/queries/groovy/highlights.scm +++ b/runtime/queries/groovy/highlights.scm @@ -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)) diff --git a/runtime/queries/groovy/indents.scm b/runtime/queries/groovy/indents.scm new file mode 100644 index 000000000000..888d5010785e --- /dev/null +++ b/runtime/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/runtime/queries/groovy/injections.scm b/runtime/queries/groovy/injections.scm index e4509a5fd317..1c04c65fbb43 100644 --- a/runtime/queries/groovy/injections.scm +++ b/runtime/queries/groovy/injections.scm @@ -1,2 +1,5 @@ -([(line_comment) (block_comment)] @injection.content - (#set! injection.language "comment")) +((comment) @injection.content + (#set! injection.language "comment")) + +((groovy_doc) @injection.content + (#set! injection.language "comment")) diff --git a/runtime/queries/groovy/locals.scm b/runtime/queries/groovy/locals.scm new file mode 100644 index 000000000000..23cb5f0cb7e9 --- /dev/null +++ b/runtime/queries/groovy/locals.scm @@ -0,0 +1,6 @@ +(function_definition) @local.scope + +(parameter + name: (identifier) @local.definition.parameter) + +(identifier) @local.reference From 9e76f3f571fef391db6a3b89dbb36b691397867d Mon Sep 17 00:00:00 2001 From: Benedikt Ritter Date: Wed, 21 Feb 2024 08:43:41 +0100 Subject: [PATCH 2/5] Update runtime/queries/groovy/locals.scm Co-authored-by: Michael Davis --- runtime/queries/groovy/locals.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/queries/groovy/locals.scm b/runtime/queries/groovy/locals.scm index 23cb5f0cb7e9..380c4ad64f3d 100644 --- a/runtime/queries/groovy/locals.scm +++ b/runtime/queries/groovy/locals.scm @@ -1,6 +1,6 @@ (function_definition) @local.scope (parameter - name: (identifier) @local.definition.parameter) + name: (identifier) @local.definition) (identifier) @local.reference From e48b49f100dd84b2bbb4ab7cacaf6ff6e585f5dc Mon Sep 17 00:00:00 2001 From: Benedikt Ritter Date: Tue, 27 Feb 2024 13:54:44 +0100 Subject: [PATCH 3/5] Drop indent.scm for groovy It was copied from the tree-sitter repository but is not compatiblw with the way indent queries are implemented in Helix. --- runtime/queries/groovy/indents.scm | 35 ------------------------------ 1 file changed, 35 deletions(-) delete mode 100644 runtime/queries/groovy/indents.scm diff --git a/runtime/queries/groovy/indents.scm b/runtime/queries/groovy/indents.scm deleted file mode 100644 index 888d5010785e..000000000000 --- a/runtime/queries/groovy/indents.scm +++ /dev/null @@ -1,35 +0,0 @@ -[ - (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 From 74c3974f279ed5b1dcc6b7c543df30d2cf5441d0 Mon Sep 17 00:00:00 2001 From: Benedikt Ritter Date: Tue, 27 Feb 2024 20:45:48 +0100 Subject: [PATCH 4/5] Adapt groovy highlights to helix syntax --- runtime/queries/groovy/highlights.scm | 30 +++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/runtime/queries/groovy/highlights.scm b/runtime/queries/groovy/highlights.scm index aadd04fe453a..11fb8e46ed84 100644 --- a/runtime/queries/groovy/highlights.scm +++ b/runtime/queries/groovy/highlights.scm @@ -19,31 +19,31 @@ "else" "if" "switch" -] @keyword.conditional +] @keyword.control.conditional [ "catch" "finally" "try" -] @keyword.exception +] @keyword.control.exception "def" @keyword.function -"import" @keyword.import +"import" @keyword.control.import [ "for" "while" (break) (continue) -] @keyword.repeat +] @keyword.control.repeat -"return" @keyword.return +"return" @keyword.control.return [ "true" "false" -] @boolean +] @constant.builtin.boolean (null) @constant.builtin @@ -67,16 +67,16 @@ "public" "static" "synchronized" -] @type.qualifier +] @keyword.storage.modifier -(comment) @comment @spell +(comment) @comment (shebang) @keyword.directive (string) @string (string - (escape_sequence) @string.escape) + (escape_sequence) @constant.character.escape) (string (interpolation @@ -97,7 +97,7 @@ "." ] @punctuation.delimiter -(number_literal) @number +(number_literal) @constant.numeric (identifier) @variable @@ -154,7 +154,7 @@ ([ "?" ":" - ]) @keyword.conditional.ternary) + ]) @keyword.operator) (map (map_item @@ -250,19 +250,19 @@ "@interface" @function.macro -(groovy_doc) @comment.documentation @spell +(groovy_doc) @comment.block.documentation (groovy_doc [ (groovy_doc_param) (groovy_doc_throws) (groovy_doc_tag) - ] @string.special @nospell) + ] @string.special) (groovy_doc (groovy_doc_param - (identifier) @variable.parameter) @nospell) + (identifier) @variable.parameter)) (groovy_doc (groovy_doc_throws - (identifier) @type @nospell)) + (identifier) @type)) From 8ac1e3f57004ab634abd6eb24a4fac04b4293dc2 Mon Sep 17 00:00:00 2001 From: Benedikt Ritter Date: Wed, 28 Feb 2024 13:37:54 +0100 Subject: [PATCH 5/5] Update documentation --- book/src/generated/lang-support.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 6faf98408f6b..1bc6b0817036 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -66,7 +66,7 @@ | gotmpl | ✓ | | | `gopls` | | gowork | ✓ | | | `gopls` | | graphql | ✓ | | | `graphql-lsp` | -| groovy | ✓ | | ✓ | | +| groovy | ✓ | | | | | hare | ✓ | | | | | haskell | ✓ | ✓ | | `haskell-language-server-wrapper` | | haskell-persistent | ✓ | | | |