From f7913c1a3bc7609c9c1d6eaa0fbd0e3dda18be63 Mon Sep 17 00:00:00 2001 From: Benedikt Ritter Date: Mon, 18 Mar 2024 00:01:11 +0100 Subject: [PATCH] Extend groovy support (#9677) * Extend groovy support Use more complete parser introduced in nvm-treesitter in https://github.com/nvim-treesitter/nvim-treesitter/commit/d4dac523d2546afc266eb9b5a7986690b5319c41 * Update runtime/queries/groovy/locals.scm Co-authored-by: Michael Davis * 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. * Adapt groovy highlights to helix syntax * Update documentation --------- Co-authored-by: Michael Davis --- languages.toml | 2 +- runtime/queries/groovy/folds.scm | 6 + runtime/queries/groovy/highlights.scm | 320 ++++++++++++++++++++------ runtime/queries/groovy/injections.scm | 7 +- runtime/queries/groovy/locals.scm | 6 + 5 files changed, 264 insertions(+), 77 deletions(-) create mode 100644 runtime/queries/groovy/folds.scm create mode 100644 runtime/queries/groovy/locals.scm diff --git a/languages.toml b/languages.toml index 4018fbe0..e4684298 100644 --- a/languages.toml +++ b/languages.toml @@ -3247,7 +3247,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 00000000..354861a6 --- /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 4e94ccd3..11fb8e46 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 -(escape_sequence) @constant.character.escape +[ + "case" + "default" + "else" + "if" + "switch" +] @keyword.control.conditional -(block - (unit - (identifier) @namespace)) +[ + "catch" + "finally" + "try" +] @keyword.control.exception -(func - (identifier) @function) +"def" @keyword.function -(number) @constant.numeric +"import" @keyword.control.import -((identifier) @constant.builtin.boolean - (#any-of? @constant.builtin.boolean "true" "false")) +[ + "for" + "while" + (break) + (continue) +] @keyword.control.repeat -((identifier) @constant - (#match? @constant "^[A-Z][A-Z\\d_]*$")) +"return" @keyword.control.return -((identifier) @constant.builtin - (#eq? @constant.builtin "null")) +[ + "true" + "false" +] @constant.builtin.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.storage.modifier - (#eq? @keyword.storage.modifier "static")) +[ + "int" + "char" + "short" + "long" + "boolean" + "float" + "double" + "void" +] @type.builtin -((identifier) @keyword.storage.type - (#any-of? @keyword.storage.type "class" "def" "interface")) +[ + "final" + "private" + "protected" + "public" + "static" + "synchronized" +] @keyword.storage.modifier -((identifier) @keyword - (#any-of? @keyword - "assert" - "new" - "extends" - "implements" - "instanceof")) +(comment) @comment -((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")) +(shebang) @keyword.directive (string) @string -[ - (line_comment) - (block_comment) -] @comment +(string + (escape_sequence) @constant.character.escape) -((block_comment) @comment.block.documentation - (#match? @comment.block.documentation "^/[*][*][^*](?s:.)*[*]/$")) - -((line_comment) @comment.block.documentation - (#match? @comment.block.documentation "^///[^/]*.*$")) +(string + (interpolation + "$" @punctuation.special)) [ - (operators) - (leading_key) + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +[ + ":" + "," + "." +] @punctuation.delimiter + +(number_literal) @constant.numeric + +(identifier) @variable + +((identifier) @constant + (#match? @constant "^[A-Z][A-Z_]+")) + +[ + "%" + "*" + "/" + "+" + "-" + "<<" + ">>" + ">>>" + ".." + "..<" + "<..<" + "<.." + "<" + "<=" + ">" + ">=" + "==" + "!=" + "<=>" + "===" + "!==" + "=~" + "==~" + "&" + "^" + "|" + "&&" + "||" + "?:" + "+" + "*" + ".&" + ".@" + "?." + "*." + "*" + "*:" + "++" + "--" + "!" ] @operator -["(" ")" "[" "]" "{" "}"] @punctuation.bracket +(string + "/" @string) + +(ternary_op + ([ + "?" + ":" + ]) @keyword.operator) + +(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.block.documentation + +(groovy_doc + [ + (groovy_doc_param) + (groovy_doc_throws) + (groovy_doc_tag) + ] @string.special) + +(groovy_doc + (groovy_doc_param + (identifier) @variable.parameter)) + +(groovy_doc + (groovy_doc_throws + (identifier) @type)) diff --git a/runtime/queries/groovy/injections.scm b/runtime/queries/groovy/injections.scm index e4509a5f..1c04c65f 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 00000000..380c4ad6 --- /dev/null +++ b/runtime/queries/groovy/locals.scm @@ -0,0 +1,6 @@ +(function_definition) @local.scope + +(parameter + name: (identifier) @local.definition) + +(identifier) @local.reference