aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Hoffmann <mhoffm@posteo.de>2022-12-02 23:47:19 +0100
committerStephan Seitz <stephan.seitz@fau.de>2022-12-29 22:18:41 +0100
commitee3e9f4dc0e5ee9e2bfb1ee47638375840b8fe0f (patch)
treef638bb4493056146317796d894464801b805118b
parentUpdate parsers: astro, ocaml, ocaml_interface (diff)
downloadnvim-treesitter-ee3e9f4dc0e5ee9e2bfb1ee47638375840b8fe0f.tar
nvim-treesitter-ee3e9f4dc0e5ee9e2bfb1ee47638375840b8fe0f.tar.gz
nvim-treesitter-ee3e9f4dc0e5ee9e2bfb1ee47638375840b8fe0f.tar.bz2
nvim-treesitter-ee3e9f4dc0e5ee9e2bfb1ee47638375840b8fe0f.tar.lz
nvim-treesitter-ee3e9f4dc0e5ee9e2bfb1ee47638375840b8fe0f.tar.xz
nvim-treesitter-ee3e9f4dc0e5ee9e2bfb1ee47638375840b8fe0f.tar.zst
nvim-treesitter-ee3e9f4dc0e5ee9e2bfb1ee47638375840b8fe0f.zip
feat(hcl,terraform): split terraform from hcl, add specialized queries for tf
This enables us to have different queries for terraform and general hcl. It solve the situation where other dialects of hcl (nomad, packer, etc) might use a terraform keyword and get highlighted out of place.
-rw-r--r--README.md1
-rw-r--r--lockfile.json3
-rw-r--r--lua/nvim-treesitter/parsers.lua12
-rw-r--r--queries/hcl/highlights.scm15
-rw-r--r--queries/terraform/folds.scm1
-rw-r--r--queries/terraform/highlights.scm21
-rw-r--r--queries/terraform/indents.scm1
-rw-r--r--queries/terraform/injections.scm1
-rw-r--r--tests/indent/terraform/function_call.tf (renamed from tests/indent/hcl/function_call.tf)0
-rw-r--r--tests/indent/terraform/indent-in-multiline-objects.tf (renamed from tests/indent/hcl/indent-in-multiline-objects.tf)0
-rw-r--r--tests/indent/terraform/indent-in-multiline-tuples.tf (renamed from tests/indent/hcl/indent-in-multiline-tuples.tf)0
-rw-r--r--tests/indent/terraform/multiline-comments.tf (renamed from tests/indent/hcl/multiline-comments.tf)0
-rw-r--r--tests/indent/terraform/multiple-attributes.tf (renamed from tests/indent/hcl/multiple-attributes.tf)0
-rw-r--r--tests/indent/terraform/multiple-blocks.tf (renamed from tests/indent/hcl/multiple-blocks.tf)0
-rw-r--r--tests/indent/terraform/nested_blocks.tf (renamed from tests/indent/hcl/nested_blocks.tf)0
-rw-r--r--tests/indent/terraform/no-indent-after-brace.tf (renamed from tests/indent/hcl/no-indent-after-brace.tf)0
-rw-r--r--tests/indent/terraform_spec.lua (renamed from tests/indent/hcl_spec.lua)4
17 files changed, 47 insertions, 12 deletions
diff --git a/README.md b/README.md
index 40aa11d6a..2f210f718 100644
--- a/README.md
+++ b/README.md
@@ -296,6 +296,7 @@ We are looking for maintainers to add more parsers and to write query files for
- [x] [swift](https://github.com/alex-pinkus/tree-sitter-swift) (maintained by @alex-pinkus)
- [x] [sxhkdrc](https://github.com/RaafatTurki/tree-sitter-sxhkdrc) (maintained by @RaafatTurki)
- [x] [teal](https://github.com/euclidianAce/tree-sitter-teal) (maintained by @euclidianAce)
+- [x] [terraform](https://github.com/MichaHoffmann/tree-sitter-hcl) (maintained by @MichaHoffmann)
- [x] [tiger](https://github.com/ambroisie/tree-sitter-tiger) (maintained by @ambroisie)
- [x] [tlaplus](https://github.com/tlaplus-community/tree-sitter-tlaplus) (maintained by @ahelwer, @susliko)
- [x] [todotxt](https://github.com/arnarg/tree-sitter-todotxt.git) (experimental, maintained by @arnarg)
diff --git a/lockfile.json b/lockfile.json
index bb4e18ade..97aad4ec5 100644
--- a/lockfile.json
+++ b/lockfile.json
@@ -374,6 +374,9 @@
"teal": {
"revision": "1ae8c68e90523b26b93af56feb7868fe4214e2b2"
},
+ "terraform": {
+ "revision": "0ff887f2a60a147452d52db060de6b42f42f1441"
+ },
"tiger": {
"revision": "a233ebe360a73a92c50978e5c4e9e471bc59ff42"
},
diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua
index f4e13974b..6bd94f93b 100644
--- a/lua/nvim-treesitter/parsers.lua
+++ b/lua/nvim-treesitter/parsers.lua
@@ -8,7 +8,6 @@ local filetype_to_parsername = {
PKGBUILD = "bash",
html_tags = "html",
["typescript.tsx"] = "tsx",
- terraform = "hcl",
["html.handlebars"] = "glimmer",
systemverilog = "verilog",
cls = "latex",
@@ -618,6 +617,17 @@ list.hcl = {
filetype = "hcl",
}
+list.terraform = {
+ install_info = {
+ url = "https://github.com/MichaHoffmann/tree-sitter-hcl",
+ files = { "src/parser.c", "src/scanner.cc" },
+ branch = "main",
+ location = "dialects/terraform",
+ },
+ maintainers = { "@MichaHoffmann" },
+ filetype = "terraform",
+}
+
list.markdown = {
install_info = {
url = "https://github.com/MDeiml/tree-sitter-markdown",
diff --git a/queries/hcl/highlights.scm b/queries/hcl/highlights.scm
index 658369292..4f2eb2300 100644
--- a/queries/hcl/highlights.scm
+++ b/queries/hcl/highlights.scm
@@ -81,7 +81,8 @@
(comment) @comment @spell
(identifier) @variable
-(block (identifier) @type)
+(body (block (identifier) @keyword))
+(body (block (body (block (identifier) @type))))
(function_call (identifier) @function)
(attribute (identifier) @field)
@@ -90,13 +91,9 @@
; highlight identifier keys as though they were block attributes
(object_elem key: (expression (variable_expr (identifier) @field)))
-((identifier) @keyword (#any-of? @keyword "module" "root" "cwd" "resource" "variable" "data" "locals" "terraform" "provider" "output"))
-((identifier) @type.builtin (#any-of? @type.builtin "bool" "string" "number" "object" "tuple" "list" "map" "set" "any"))
-(variable_expr (identifier) @variable.builtin (#any-of? @variable.builtin "var" "local" "path"))
-(get_attr (identifier) @variable.builtin (#any-of? @variable.builtin "root" "cwd" "module"))
-
-(object_elem val: (expression
- (variable_expr
- (identifier) @type.builtin (#any-of? @type.builtin "bool" "string" "number" "object" "tuple" "list" "map" "set" "any"))))
+; var.foo, data.bar
+;
+; first element in get_attr is a keyword or a reference to a keyword
+(expression (variable_expr (identifier) @keyword) (get_attr (identifier) @field))
(ERROR) @error
diff --git a/queries/terraform/folds.scm b/queries/terraform/folds.scm
new file mode 100644
index 000000000..0e5ffc2db
--- /dev/null
+++ b/queries/terraform/folds.scm
@@ -0,0 +1 @@
+; inherits: hcl
diff --git a/queries/terraform/highlights.scm b/queries/terraform/highlights.scm
new file mode 100644
index 000000000..d31b83c82
--- /dev/null
+++ b/queries/terraform/highlights.scm
@@ -0,0 +1,21 @@
+; inherits: hcl
+
+; Terraform specific references
+;
+;
+; local/module/data/var/output
+(expression (variable_expr (identifier) @type.builtin (#any-of? @type.builtin "data" "var" "local" "module" "output")) (get_attr (identifier) @field))
+
+; path.root/cwd/module
+(expression (variable_expr (identifier) @type.builtin (#eq? @type.builtin "path")) (get_attr (identifier) @variable.builtin (#any-of? @variable.builtin "root" "cwd" "module")))
+
+; terraform.workspace
+(expression (variable_expr (identifier) @type.builtin (#eq? @type.builtin "terraform")) (get_attr (identifier) @variable.builtin (#any-of? @variable.builtin "workspace")))
+
+; Terraform specific keywords
+
+; FIXME: ideally only for identifiers under a `variable` block to minimize false positives
+((identifier) @type.builtin (#any-of? @type.builtin "bool" "string" "number" "object" "tuple" "list" "map" "set" "any"))
+(object_elem val: (expression
+ (variable_expr
+ (identifier) @type.builtin (#any-of? @type.builtin "bool" "string" "number" "object" "tuple" "list" "map" "set" "any"))))
diff --git a/queries/terraform/indents.scm b/queries/terraform/indents.scm
new file mode 100644
index 000000000..0e5ffc2db
--- /dev/null
+++ b/queries/terraform/indents.scm
@@ -0,0 +1 @@
+; inherits: hcl
diff --git a/queries/terraform/injections.scm b/queries/terraform/injections.scm
new file mode 100644
index 000000000..0e5ffc2db
--- /dev/null
+++ b/queries/terraform/injections.scm
@@ -0,0 +1 @@
+; inherits: hcl
diff --git a/tests/indent/hcl/function_call.tf b/tests/indent/terraform/function_call.tf
index 44c477e48..44c477e48 100644
--- a/tests/indent/hcl/function_call.tf
+++ b/tests/indent/terraform/function_call.tf
diff --git a/tests/indent/hcl/indent-in-multiline-objects.tf b/tests/indent/terraform/indent-in-multiline-objects.tf
index 00ee9c958..00ee9c958 100644
--- a/tests/indent/hcl/indent-in-multiline-objects.tf
+++ b/tests/indent/terraform/indent-in-multiline-objects.tf
diff --git a/tests/indent/hcl/indent-in-multiline-tuples.tf b/tests/indent/terraform/indent-in-multiline-tuples.tf
index 402487890..402487890 100644
--- a/tests/indent/hcl/indent-in-multiline-tuples.tf
+++ b/tests/indent/terraform/indent-in-multiline-tuples.tf
diff --git a/tests/indent/hcl/multiline-comments.tf b/tests/indent/terraform/multiline-comments.tf
index 494aaba9c..494aaba9c 100644
--- a/tests/indent/hcl/multiline-comments.tf
+++ b/tests/indent/terraform/multiline-comments.tf
diff --git a/tests/indent/hcl/multiple-attributes.tf b/tests/indent/terraform/multiple-attributes.tf
index da6a85fb0..da6a85fb0 100644
--- a/tests/indent/hcl/multiple-attributes.tf
+++ b/tests/indent/terraform/multiple-attributes.tf
diff --git a/tests/indent/hcl/multiple-blocks.tf b/tests/indent/terraform/multiple-blocks.tf
index b9826c889..b9826c889 100644
--- a/tests/indent/hcl/multiple-blocks.tf
+++ b/tests/indent/terraform/multiple-blocks.tf
diff --git a/tests/indent/hcl/nested_blocks.tf b/tests/indent/terraform/nested_blocks.tf
index 7be6492cc..7be6492cc 100644
--- a/tests/indent/hcl/nested_blocks.tf
+++ b/tests/indent/terraform/nested_blocks.tf
diff --git a/tests/indent/hcl/no-indent-after-brace.tf b/tests/indent/terraform/no-indent-after-brace.tf
index e670ad8d7..e670ad8d7 100644
--- a/tests/indent/hcl/no-indent-after-brace.tf
+++ b/tests/indent/terraform/no-indent-after-brace.tf
diff --git a/tests/indent/hcl_spec.lua b/tests/indent/terraform_spec.lua
index ee53d89fc..49fa22c20 100644
--- a/tests/indent/hcl_spec.lua
+++ b/tests/indent/terraform_spec.lua
@@ -1,13 +1,13 @@
local Runner = require("tests.indent.common").Runner
--local XFAIL = require("tests.indent.common").XFAIL
-local run = Runner:new(it, "tests/indent/hcl", {
+local run = Runner:new(it, "tests/indent/terraform", {
tabstop = 2,
shiftwidth = 2,
expandtab = true,
})
-describe("indent HCL:", function()
+describe("indent Terraform:", function()
describe("whole file:", function()
run:whole_file(".", {
expected_failures = {},