aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Hoffmann <mhoffm@posteo.de>2022-04-23 11:17:10 +0200
committerStephan Seitz <stephan.seitz@fau.de>2022-04-24 18:57:30 +0200
commitb1e8b61a94955d747ba8ad02cd3c0dddb1bf883f (patch)
treeddebbbb900d55a78f0242325b9b0c812275dee9e
parentUpdate lockfile.json (diff)
downloadnvim-treesitter-b1e8b61a94955d747ba8ad02cd3c0dddb1bf883f.tar
nvim-treesitter-b1e8b61a94955d747ba8ad02cd3c0dddb1bf883f.tar.gz
nvim-treesitter-b1e8b61a94955d747ba8ad02cd3c0dddb1bf883f.tar.bz2
nvim-treesitter-b1e8b61a94955d747ba8ad02cd3c0dddb1bf883f.tar.lz
nvim-treesitter-b1e8b61a94955d747ba8ad02cd3c0dddb1bf883f.tar.xz
nvim-treesitter-b1e8b61a94955d747ba8ad02cd3c0dddb1bf883f.tar.zst
nvim-treesitter-b1e8b61a94955d747ba8ad02cd3c0dddb1bf883f.zip
indents(hcl): fix indentation queries
This commit adds tests for hcl indentation and fixes various bugs
-rw-r--r--queries/hcl/indents.scm17
-rw-r--r--tests/indent/hcl/indent-in-multiline-objects.tf6
-rw-r--r--tests/indent/hcl/indent-in-multiline-tuples.tf6
-rw-r--r--tests/indent/hcl/multiline-comments.tf7
-rw-r--r--tests/indent/hcl/multiple-attributes.tf4
-rw-r--r--tests/indent/hcl/multiple-blocks.tf6
-rw-r--r--tests/indent/hcl/nested_blocks.tf5
-rw-r--r--tests/indent/hcl/no-indent-after-brace.tf4
-rw-r--r--tests/indent/hcl_spec.lua33
9 files changed, 84 insertions, 4 deletions
diff --git a/queries/hcl/indents.scm b/queries/hcl/indents.scm
index b0f0bc9bb..c316628ba 100644
--- a/queries/hcl/indents.scm
+++ b/queries/hcl/indents.scm
@@ -1,13 +1,22 @@
[
- (object)
(block)
+ (object)
(tuple)
- (for_tuple_expr)
- (for_object_expr)
] @indent
[
- (object_end)
(block_end)
+ (object_end)
(tuple_end)
] @branch
+
+
+[
+ "]"
+ ")"
+ "}"
+] @indent_end
+
+
+(comment) @auto
+(ERROR) @auto
diff --git a/tests/indent/hcl/indent-in-multiline-objects.tf b/tests/indent/hcl/indent-in-multiline-objects.tf
new file mode 100644
index 000000000..00ee9c958
--- /dev/null
+++ b/tests/indent/hcl/indent-in-multiline-objects.tf
@@ -0,0 +1,6 @@
+test {
+ x = {
+ 1: "foo",
+ 2: "bar",
+ }
+}
diff --git a/tests/indent/hcl/indent-in-multiline-tuples.tf b/tests/indent/hcl/indent-in-multiline-tuples.tf
new file mode 100644
index 000000000..402487890
--- /dev/null
+++ b/tests/indent/hcl/indent-in-multiline-tuples.tf
@@ -0,0 +1,6 @@
+test {
+ x = [
+ 1,
+ 2,
+ ]
+}
diff --git a/tests/indent/hcl/multiline-comments.tf b/tests/indent/hcl/multiline-comments.tf
new file mode 100644
index 000000000..494aaba9c
--- /dev/null
+++ b/tests/indent/hcl/multiline-comments.tf
@@ -0,0 +1,7 @@
+test {
+ /*
+ foo
+ bar
+ baz
+ */
+}
diff --git a/tests/indent/hcl/multiple-attributes.tf b/tests/indent/hcl/multiple-attributes.tf
new file mode 100644
index 000000000..da6a85fb0
--- /dev/null
+++ b/tests/indent/hcl/multiple-attributes.tf
@@ -0,0 +1,4 @@
+test {
+ x = ["foo", "bar"]
+ y = {"fizz": "buzz"}
+}
diff --git a/tests/indent/hcl/multiple-blocks.tf b/tests/indent/hcl/multiple-blocks.tf
new file mode 100644
index 000000000..b9826c889
--- /dev/null
+++ b/tests/indent/hcl/multiple-blocks.tf
@@ -0,0 +1,6 @@
+test {
+ x = "foo"
+}
+test {
+ y = "bar"
+}
diff --git a/tests/indent/hcl/nested_blocks.tf b/tests/indent/hcl/nested_blocks.tf
new file mode 100644
index 000000000..7be6492cc
--- /dev/null
+++ b/tests/indent/hcl/nested_blocks.tf
@@ -0,0 +1,5 @@
+test {
+ nest {
+ x = "bar"
+ }
+}
diff --git a/tests/indent/hcl/no-indent-after-brace.tf b/tests/indent/hcl/no-indent-after-brace.tf
new file mode 100644
index 000000000..e670ad8d7
--- /dev/null
+++ b/tests/indent/hcl/no-indent-after-brace.tf
@@ -0,0 +1,4 @@
+# Issue #2590
+locals {
+ titles = ["test0", "test1"]
+}
diff --git a/tests/indent/hcl_spec.lua b/tests/indent/hcl_spec.lua
new file mode 100644
index 000000000..b97af2786
--- /dev/null
+++ b/tests/indent/hcl_spec.lua
@@ -0,0 +1,33 @@
+local Runner = require("tests.indent.common").Runner
+--local XFAIL = require("tests.indent.common").XFAIL
+
+local run = Runner:new(it, "tests/indent/hcl", {
+ tabstop = 2,
+ shiftwidth = 2,
+ expandtab = true,
+})
+
+describe("indent HCL:", function()
+ describe("whole file:", function()
+ run:whole_file(".", {
+ expected_failures = {},
+ })
+ end)
+
+ describe("new line:", function()
+ run:new_line("no-indent-after-brace.tf", { on_line = 4, text = "# Wow, no indent here please", indent = 0 })
+ run:new_line("indent-in-multiline-tuples.tf", { on_line = 4, text = "3,", indent = 4 })
+ run:new_line("indent-in-multiline-tuples.tf", { on_line = 3, text = "# as elements", indent = 4 })
+ run:new_line("indent-in-multiline-tuples.tf", { on_line = 5, text = "# as outer block", indent = 2 })
+ run:new_line("indent-in-multiline-tuples.tf", { on_line = 1, text = "# as outer block", indent = 2 })
+ run:new_line("indent-in-multiline-objects.tf", { on_line = 4, text = '3: "baz",', indent = 4 })
+ run:new_line("indent-in-multiline-objects.tf", { on_line = 3, text = "# as elements", indent = 4 })
+ run:new_line("indent-in-multiline-objects.tf", { on_line = 5, text = "# as outer block", indent = 2 })
+ run:new_line("indent-in-multiline-objects.tf", { on_line = 1, text = "# as outer block", indent = 2 })
+ run:new_line("multiple-attributes.tf", { on_line = 2, text = "a = 1", indent = 2 })
+ run:new_line("multiple-attributes.tf", { on_line = 3, text = "a = 1", indent = 2 })
+ run:new_line("multiple-attributes.tf", { on_line = 4, text = "a = 1", indent = 0 })
+ run:new_line("nested_blocks.tf", { on_line = 3, text = "a = 1", indent = 4 })
+ run:new_line("nested_blocks.tf", { on_line = 4, text = "a = 1", indent = 2 })
+ end)
+end)