From 6290349d8ae0ac8a834ead5bfcd0155ee8f795a9 Mon Sep 17 00:00:00 2001 From: Volodymyr Chernetskyi <19735328+chernetskyi@users.noreply.github.com> Date: Tue, 16 Jan 2024 12:03:51 +0100 Subject: [PATCH 1/6] Add Groovy grammar --- book/src/generated/lang-support.md | 1 + languages.toml | 14 ++++ runtime/queries/groovy/highlights.scm | 95 +++++++++++++++++++++++++++ runtime/queries/groovy/injections.scm | 5 ++ 4 files changed, 115 insertions(+) create mode 100644 runtime/queries/groovy/highlights.scm create mode 100644 runtime/queries/groovy/injections.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index f46c9f5e2de2..7aec37778080 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -65,6 +65,7 @@ | gotmpl | ✓ | | | `gopls` | | gowork | ✓ | | | `gopls` | | graphql | ✓ | | | `graphql-lsp` | +| groovy | ✓ | | | | | hare | ✓ | | | | | haskell | ✓ | ✓ | | `haskell-language-server-wrapper` | | haskell-persistent | ✓ | | | | diff --git a/languages.toml b/languages.toml index e52dcabbcf0a..ae99bd89feb2 100644 --- a/languages.toml +++ b/languages.toml @@ -3125,3 +3125,17 @@ indent = { tab-width = 2, unit = " " } [[grammar]] name = "pkl" source = { git = "https://github.com/apple/tree-sitter-pkl", rev = "c03f04a313b712f8ab00a2d862c10b37318699ae" } + +[[language]] +name = "groovy" +language-id = "groovy" +scope = "source.groovy" +file-types = ["groovy", "Jenkinsfile", "jenkinsfile"] +shebangs = ["groovy"] +roots = [] +comment-token = "//" +indent = { tab-width = 2, unit = " " } + +[[grammar]] +name = "groovy" +source = { git = "https://github.com/Decodetalkers/tree-sitter-groovy", rev = "7e023227f46fee428b16a0288eeb0f65ee2523ec" } diff --git a/runtime/queries/groovy/highlights.scm b/runtime/queries/groovy/highlights.scm new file mode 100644 index 000000000000..a9b38ef5b286 --- /dev/null +++ b/runtime/queries/groovy/highlights.scm @@ -0,0 +1,95 @@ +(unit + (identifier) @variable) +(string + (identifier) @variable) + +(escape_sequence) @string.escape + +(block + (unit + (identifier) @namespace)) + +(func + (identifier) @function) + +(number) @number + +((identifier) @boolean + (#any-of? @boolean "true" "false" "True" "False")) + +((identifier) @constant + (#lua-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 + (#any-of? @keyword + "static" + "class" + "def" + "import" + "package" + "assert" + "extends" + "implements" + "instanceof" + "interface" + "new")) + +((identifier) @type.qualifier + (#any-of? @type.qualifier + "abstract" + "protected" + "private" + "public")) + +((identifier) @exception + (#any-of? @exception + "throw" + "finally" + "try" + "catch")) + +(string) @string + +[ + (line_comment) + (block_comment) +] @comment @spell + +((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 + +["(" ")" "[" "]" "{" "}"] @punctuation.bracket diff --git a/runtime/queries/groovy/injections.scm b/runtime/queries/groovy/injections.scm new file mode 100644 index 000000000000..9a3afbc1f40f --- /dev/null +++ b/runtime/queries/groovy/injections.scm @@ -0,0 +1,5 @@ +((block_comment) @injection.content + (#set! injection.language "comment")) + +((line_comment) @injection.content + (#set! injection.language "comment")) From 078725154a242378d96c783d49fbf3e6715abbdb Mon Sep 17 00:00:00 2001 From: Volodymyr Chernetskyi <19735328+chernetskyi@users.noreply.github.com> Date: Tue, 16 Jan 2024 17:21:14 +0100 Subject: [PATCH 2/6] Rewrite Neovim captures into Helix for Groovy --- runtime/queries/groovy/highlights.scm | 49 ++++++++++++++------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/runtime/queries/groovy/highlights.scm b/runtime/queries/groovy/highlights.scm index a9b38ef5b286..82c5e8ea991f 100644 --- a/runtime/queries/groovy/highlights.scm +++ b/runtime/queries/groovy/highlights.scm @@ -1,9 +1,10 @@ (unit (identifier) @variable) + (string (identifier) @variable) -(escape_sequence) @string.escape +(escape_sequence) @constant.character.escape (block (unit @@ -12,13 +13,13 @@ (func (identifier) @function) -(number) @number +(number) @constant.numeric -((identifier) @boolean - (#any-of? @boolean "true" "false" "True" "False")) +((identifier) @constant.builtin.boolean + (#any-of? @constant.builtin.boolean "true" "false")) ((identifier) @constant - (#lua-match? @constant "^[A-Z][A-Z%d_]*$")) + (#match? @constant "^[A-Z][A-Z\d_]*$")) ((identifier) @constant.builtin (#eq? @constant.builtin "null")) @@ -43,29 +44,32 @@ "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 - "static" - "class" - "def" - "import" - "package" "assert" + "new" "extends" "implements" - "instanceof" - "interface" - "new")) + "instanceof")) -((identifier) @type.qualifier - (#any-of? @type.qualifier +((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) @exception - (#any-of? @exception +((identifier) @keyword.control.exception + (#any-of? @keyword.control.exception "throw" "finally" "try" @@ -78,14 +82,11 @@ (block_comment) ] @comment @spell -((block_comment) @comment.documentation - (#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$")) - -((line_comment) @comment.documentation - (#lua-match? @comment.documentation "^///[^/]")) +((block_comment) @comment.block.documentation + (#match? @comment.block.documentation "^/[*][*][^*](?s:.)*[*]/$")) -((line_comment) @comment.documentation - (#lua-match? @comment.documentation "^///$")) +((line_comment) @comment.block.documentation + (#match? @comment.block.documentation "^///[^/]*.*$")) [ (operators) From 53570dbf60aeb23d93df9421329a811131082fb7 Mon Sep 17 00:00:00 2001 From: Volodymyr Chernetskyi Date: Tue, 16 Jan 2024 19:44:28 +0200 Subject: [PATCH 3/6] Simplify Groovy injections Co-authored-by: Michael Davis --- runtime/queries/groovy/injections.scm | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/runtime/queries/groovy/injections.scm b/runtime/queries/groovy/injections.scm index 9a3afbc1f40f..e4509a5fd317 100644 --- a/runtime/queries/groovy/injections.scm +++ b/runtime/queries/groovy/injections.scm @@ -1,5 +1,2 @@ -((block_comment) @injection.content - (#set! injection.language "comment")) - -((line_comment) @injection.content +([(line_comment) (block_comment)] @injection.content (#set! injection.language "comment")) From 2544b1c94f5e57aa17b65e9be381a1271492ecda Mon Sep 17 00:00:00 2001 From: Volodymyr Chernetskyi Date: Tue, 16 Jan 2024 19:45:43 +0200 Subject: [PATCH 4/6] Remove Neovim's spell from Groovy highlights Co-authored-by: Michael Davis --- runtime/queries/groovy/highlights.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/queries/groovy/highlights.scm b/runtime/queries/groovy/highlights.scm index 82c5e8ea991f..c8620c2f803b 100644 --- a/runtime/queries/groovy/highlights.scm +++ b/runtime/queries/groovy/highlights.scm @@ -80,7 +80,7 @@ [ (line_comment) (block_comment) -] @comment @spell +] @comment ((block_comment) @comment.block.documentation (#match? @comment.block.documentation "^/[*][*][^*](?s:.)*[*]/$")) From fd9767993e8bddd2be4b3b4ff26160e0df5c45dd Mon Sep 17 00:00:00 2001 From: Volodymyr Chernetskyi <19735328+chernetskyi@users.noreply.github.com> Date: Mon, 19 Feb 2024 18:01:47 +0100 Subject: [PATCH 5/6] Apply suggestions to languages.toml --- languages.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/languages.toml b/languages.toml index ae99bd89feb2..1c4c612673af 100644 --- a/languages.toml +++ b/languages.toml @@ -3130,9 +3130,8 @@ source = { git = "https://github.com/apple/tree-sitter-pkl", rev = "c03f04a313b7 name = "groovy" language-id = "groovy" scope = "source.groovy" -file-types = ["groovy", "Jenkinsfile", "jenkinsfile"] +file-types = ["groovy", "jenkinsfile", { glob = "Jenkinsfile" }, { glob = "Jenkinsfile.*" }] shebangs = ["groovy"] -roots = [] comment-token = "//" indent = { tab-width = 2, unit = " " } From f7bab1253364238ba851877006d98f1abdd176cd Mon Sep 17 00:00:00 2001 From: Volodymyr Chernetskyi <19735328+chernetskyi@users.noreply.github.com> Date: Mon, 19 Feb 2024 18:02:44 +0100 Subject: [PATCH 6/6] Escape backslash in groovy highlights.scm --- runtime/queries/groovy/highlights.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/queries/groovy/highlights.scm b/runtime/queries/groovy/highlights.scm index c8620c2f803b..4e94ccd3a1ee 100644 --- a/runtime/queries/groovy/highlights.scm +++ b/runtime/queries/groovy/highlights.scm @@ -19,7 +19,7 @@ (#any-of? @constant.builtin.boolean "true" "false")) ((identifier) @constant - (#match? @constant "^[A-Z][A-Z\d_]*$")) + (#match? @constant "^[A-Z][A-Z\\d_]*$")) ((identifier) @constant.builtin (#eq? @constant.builtin "null"))