From 43c45f1e9429504649482aa948b1a595361f3782 Mon Sep 17 00:00:00 2001 From: Lennard Hofmann Date: Sat, 19 Nov 2022 19:46:10 +0100 Subject: [PATCH] Update tree-sitter-java and add Java textobjects --- book/src/generated/lang-support.md | 2 +- languages.toml | 2 +- runtime/queries/java/highlights.scm | 19 +++++++++++++-- runtime/queries/java/injections.scm | 2 +- runtime/queries/java/textobjects.scm | 35 ++++++++++++++++++++++++++++ 5 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 runtime/queries/java/textobjects.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 086cd3c68f43..f985d0279e85 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -55,7 +55,7 @@ | idris | | | | `idris2-lsp` | | iex | ✓ | | | | | ini | ✓ | | | | -| java | ✓ | | | `jdtls` | +| java | ✓ | ✓ | | `jdtls` | | javascript | ✓ | ✓ | ✓ | `typescript-language-server` | | jsdoc | ✓ | | | | | json | ✓ | | ✓ | `vscode-json-language-server` | diff --git a/languages.toml b/languages.toml index 839b6223af99..6d9a2d94e176 100644 --- a/languages.toml +++ b/languages.toml @@ -617,7 +617,7 @@ indent = { tab-width = 4, unit = " " } [[grammar]] name = "java" -source = { git = "https://github.com/tree-sitter/tree-sitter-java", rev = "bd6186c24d5eb13b4623efac9d944dcc095c0dad" } +source = { git = "https://github.com/tree-sitter/tree-sitter-java", rev = "09d650def6cdf7f479f4b78f595e9ef5b58ce31e" } [[language]] name = "ledger" diff --git a/runtime/queries/java/highlights.scm b/runtime/queries/java/highlights.scm index 77902fce3221..f049b8d252b2 100644 --- a/runtime/queries/java/highlights.scm +++ b/runtime/queries/java/highlights.scm @@ -21,6 +21,8 @@ name: (identifier) @type) (class_declaration name: (identifier) @type) +(record_declaration + name: (identifier) @type) (enum_declaration name: (identifier) @type) @@ -33,6 +35,8 @@ (constructor_declaration name: (identifier) @type) +(compact_constructor_declaration + name: (identifier) @type) (type_identifier) @type @@ -59,6 +63,7 @@ (hex_integer_literal) (decimal_integer_literal) (octal_integer_literal) + (binary_integer_literal) ] @constant.numeric.integer [ @@ -67,7 +72,11 @@ ] @constant.numeric.float (character_literal) @constant.character -(string_literal) @string + +[ + (string_literal) + (text_block) +] @string [ (true) @@ -75,7 +84,8 @@ (null_literal) ] @constant.builtin -(comment) @comment +(line_comment) @comment +(block_comment) @comment ; Keywords @@ -104,15 +114,19 @@ "module" "native" "new" + "non-sealed" "open" "opens" "package" + "permits" "private" "protected" "provides" "public" "requires" + "record" "return" + "sealed" "static" "strictfp" "switch" @@ -127,4 +141,5 @@ "volatile" "while" "with" + "yield" ] @keyword diff --git a/runtime/queries/java/injections.scm b/runtime/queries/java/injections.scm index 321c90add371..e4509a5fd317 100644 --- a/runtime/queries/java/injections.scm +++ b/runtime/queries/java/injections.scm @@ -1,2 +1,2 @@ -((comment) @injection.content +([(line_comment) (block_comment)] @injection.content (#set! injection.language "comment")) diff --git a/runtime/queries/java/textobjects.scm b/runtime/queries/java/textobjects.scm new file mode 100644 index 000000000000..a932c7934553 --- /dev/null +++ b/runtime/queries/java/textobjects.scm @@ -0,0 +1,35 @@ +(method_declaration + body: (_) @function.inside) @function.around + +(interface_declaration + body: (_) @class.inside) @class.around + +(class_declaration + body: (_) @class.inside) @class.around + +(record_declaration + body: (_) @class.inside) @class.around + +(enum_declaration + body: (_) @class.inside) @class.around + +(formal_parameters + ((_) @parameter.inside . ","? @parameter.around) @parameter.around) + +(type_parameters + ((_) @parameter.inside . ","? @parameter.around) @parameter.around) + +(type_arguments + ((_) @parameter.inside . ","? @parameter.around) @parameter.around) + +(argument_list + ((_) @parameter.inside . ","? @parameter.around) @parameter.around) + +[ + (line_comment) + (block_comment) +] @comment.inside + +(line_comment)+ @comment.around + +(block_comment) @comment.around