aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPham Huy Hoang <hoangtun0810@gmail.com>2023-06-04 13:28:41 +0900
committerGitHub <noreply@github.com>2023-06-04 13:28:41 +0900
commit1281601cb40b71a47c5b30866bd4968fd0d20fb3 (patch)
tree68b98f43e1d403b5035a769231ceae785c6f7f2d
parentfeat(prisma): highlight views (diff)
downloadnvim-treesitter-1281601cb40b71a47c5b30866bd4968fd0d20fb3.tar
nvim-treesitter-1281601cb40b71a47c5b30866bd4968fd0d20fb3.tar.gz
nvim-treesitter-1281601cb40b71a47c5b30866bd4968fd0d20fb3.tar.bz2
nvim-treesitter-1281601cb40b71a47c5b30866bd4968fd0d20fb3.tar.lz
nvim-treesitter-1281601cb40b71a47c5b30866bd4968fd0d20fb3.tar.xz
nvim-treesitter-1281601cb40b71a47c5b30866bd4968fd0d20fb3.tar.zst
nvim-treesitter-1281601cb40b71a47c5b30866bd4968fd0d20fb3.zip
feat: add indents for annotation defs (#4828)
- Add indent for `@interface` and `@Annotation(...)` - Add notes for indent queries
-rw-r--r--queries/java/indents.scm23
-rw-r--r--tests/indent/java/annotation.java3
-rw-r--r--tests/indent/java/annotation_2.java8
-rw-r--r--tests/indent/java_spec.lua2
4 files changed, 27 insertions, 9 deletions
diff --git a/queries/java/indents.scm b/queries/java/indents.scm
index 017646e5b..73fb386e3 100644
--- a/queries/java/indents.scm
+++ b/queries/java/indents.scm
@@ -1,13 +1,17 @@
[
- (class_body)
- (enum_body)
- (interface_body)
- (constructor_body)
- (block)
- (switch_block)
- (array_initializer)
- (argument_list)
- (formal_parameters)
+ ; ... refers to the portion that this indent query will have effects on
+ (class_body) ; { ... } of `class X`
+ (enum_body) ; { ... } of `enum X`
+ (interface_body) ; { ... } of `interface X`
+ (constructor_body) ; { `modifier` X() {...} } inside `class X`
+ (annotation_type_body) ; { ... } of `@interface X`
+ (block) ; { ... } that's not mentioned in this scope
+ (switch_block) ; { ... } in `switch X`
+ (array_initializer) ; [1, 2]
+ (argument_list) ; foo(...)
+ (formal_parameters) ; method foo(...)
+ (annotation_argument_list) ; @Annotation(...)
+ (element_value_array_initializer) ; { a, b } inside @Annotation()
] @indent.begin
(expression_statement (method_invocation) @indent.begin)
@@ -21,6 +25,7 @@
"]"
] @indent.branch
+(annotation_argument_list ")" @indent.end) ; This should be a special cased as `()` here doesn't have ending `;`
"}" @indent.end
(line_comment) @indent.ignore
diff --git a/tests/indent/java/annotation.java b/tests/indent/java/annotation.java
new file mode 100644
index 000000000..bd37d09a7
--- /dev/null
+++ b/tests/indent/java/annotation.java
@@ -0,0 +1,3 @@
+abstract public @interface Foo {
+ abstract public String Bar();
+}
diff --git a/tests/indent/java/annotation_2.java b/tests/indent/java/annotation_2.java
new file mode 100644
index 000000000..aa5f45994
--- /dev/null
+++ b/tests/indent/java/annotation_2.java
@@ -0,0 +1,8 @@
+@ContextConfiguration(
+ classes = {
+ WireMockConfig.class,
+ }
+)
+public class Foo {
+
+}
diff --git a/tests/indent/java_spec.lua b/tests/indent/java_spec.lua
index 33003fd40..1d10046bb 100644
--- a/tests/indent/java_spec.lua
+++ b/tests/indent/java_spec.lua
@@ -33,5 +33,7 @@ describe("indent Java:", function()
run:new_line("method_chaining.java", { on_line = 4, text = '.append("b");', indent = 6 })
run:new_line("constructor_with_arguments_on_multiple_lines.java", { on_line = 4, text = "}", indent = 2 })
run:new_line("method_with_arguments_on_multiple_lines.java", { on_line = 4, text = "}", indent = 2 })
+ run:new_line("annotation.java", { on_line = 1, text = "abstract public Foo(){}", indent = 2 })
+ run:new_line("annotation_2.java", { on_line = 2, text = "Bar.class", indent = 4 })
end)
end)