mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17:02 -04:00
indents(hcl): fix indentation queries
This commit adds tests for hcl indentation and fixes various bugs
This commit is contained in:
parent
91f912f2d1
commit
b1e8b61a94
9 changed files with 84 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
6
tests/indent/hcl/indent-in-multiline-objects.tf
Normal file
6
tests/indent/hcl/indent-in-multiline-objects.tf
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
test {
|
||||
x = {
|
||||
1: "foo",
|
||||
2: "bar",
|
||||
}
|
||||
}
|
||||
6
tests/indent/hcl/indent-in-multiline-tuples.tf
Normal file
6
tests/indent/hcl/indent-in-multiline-tuples.tf
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
test {
|
||||
x = [
|
||||
1,
|
||||
2,
|
||||
]
|
||||
}
|
||||
7
tests/indent/hcl/multiline-comments.tf
Normal file
7
tests/indent/hcl/multiline-comments.tf
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
test {
|
||||
/*
|
||||
foo
|
||||
bar
|
||||
baz
|
||||
*/
|
||||
}
|
||||
4
tests/indent/hcl/multiple-attributes.tf
Normal file
4
tests/indent/hcl/multiple-attributes.tf
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
test {
|
||||
x = ["foo", "bar"]
|
||||
y = {"fizz": "buzz"}
|
||||
}
|
||||
6
tests/indent/hcl/multiple-blocks.tf
Normal file
6
tests/indent/hcl/multiple-blocks.tf
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
test {
|
||||
x = "foo"
|
||||
}
|
||||
test {
|
||||
y = "bar"
|
||||
}
|
||||
5
tests/indent/hcl/nested_blocks.tf
Normal file
5
tests/indent/hcl/nested_blocks.tf
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
test {
|
||||
nest {
|
||||
x = "bar"
|
||||
}
|
||||
}
|
||||
4
tests/indent/hcl/no-indent-after-brace.tf
Normal file
4
tests/indent/hcl/no-indent-after-brace.tf
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
# Issue #2590
|
||||
locals {
|
||||
titles = ["test0", "test1"]
|
||||
}
|
||||
33
tests/indent/hcl_spec.lua
Normal file
33
tests/indent/hcl_spec.lua
Normal file
|
|
@ -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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue