Skip to content

Commit

Permalink
Add support for HCL language
Browse files Browse the repository at this point in the history
Queries based on the neovims ones: https://github.com/nvim-treesitter/nvim-treesitter/tree/master/queries/hcl and modified for helix support.
  • Loading branch information
mdaffin committed Feb 24, 2022
1 parent f83843c commit 43f7c32
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,7 @@
path = helix-syntax/languages/tree-sitter-kotlin
url = https://github.com/fwcd/tree-sitter-kotlin.git
shallow = true
[submodule "helix-syntax/languages/tree-sitter-hcl"]
path = helix-syntax/languages/tree-sitter-hcl
url = https://github.com/MichaHoffmann/tree-sitter-hcl.git
shallow = true
1 change: 1 addition & 0 deletions book/src/generated/lang-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
| go |||| `gopls` |
| graphql || | | |
| haskell || | | `haskell-language-server-wrapper` |
| hcl || || |
| html || | | |
| iex || | | |
| java || | | |
Expand Down
1 change: 1 addition & 0 deletions helix-syntax/languages/tree-sitter-hcl
Submodule tree-sitter-hcl added at 3cb7fc
9 changes: 9 additions & 0 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -750,3 +750,12 @@ roots = ["settings.gradle", "settings.gradle.kts"]
comment-token = "//"
indent = { tab-width = 4, unit = " " }
language-server = { command = "kotlin-language-server" }

[[language]]
name = "hcl"
scope = "source.hcl"
injection-regex = "(hcl|tf)"
file-types = ["hcl", "tf"]
roots = []
comment-token = "#"
indent = { tab-width = 2, unit = " " }
6 changes: 6 additions & 0 deletions runtime/queries/hcl/folds.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
(comment)
(block)
(heredoc_template)
(object)
] @fold
100 changes: 100 additions & 0 deletions runtime/queries/hcl/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
(ERROR) @error

; { key: val }

(object_elem val: (expression
(variable_expr
(identifier) @type.builtin (#match? @type.builtin "^(bool|string|number|object|tuple|list|map|set|any)$"))))

(get_attr (identifier) @variable.builtin (#match? @variable.builtin "^(root|cwd|module)$"))
(variable_expr (identifier) @variable.builtin (#match? @variable.builtin "^(var|local|path)$"))
((identifier) @type.builtin (#match? @type.builtin "^(bool|string|number|object|tuple|list|map|set|any)$"))
((identifier) @keyword (#match? @keyword "^(module|root|cwd|resource|variable|data|locals|terraform|provider|output)$"))

; highlight identifier keys as though they were block attributes
(object_elem key: (expression (variable_expr (identifier) @variable.other.member)))

(attribute (identifier) @variable.other.member)
(function_call (identifier) @function.method)
(block (identifier) @type.builtin)

(identifier) @variable
(comment) @comment
(null_lit) @constant.builtin
(numeric_lit) @constant.number
(bool_lit) @constant.builtin.boolean

[
(template_interpolation_start) ; ${
(template_interpolation_end) ; }
(template_directive_start) ; %{
(template_directive_end) ; }
(strip_marker) ; ~
] @punctuation.special

[
(heredoc_identifier) ; <<END
(heredoc_start) ; END
] @punctuation.delimiter

[
(quoted_template_start) ; "
(quoted_template_end); "
(template_literal) ; non-interpolation/directive content
] @string

[
"if"
"else"
"endif"
] @keyword.control.conditional

[
"for"
"endfor"
"in"
] @keyword.control.repeat

[
":"
"="
] @none

[
(ellipsis)
"\?"
"=>"
] @punctuation.special

[
"."
".*"
","
"[*]"
] @punctuation.delimiter

[
"{"
"}"
"["
"]"
"("
")"
] @punctuation.bracket

[
"!"
"\*"
"/"
"%"
"\+"
"-"
">"
">="
"<"
"<="
"=="
"!="
"&&"
"||"
] @operator
13 changes: 13 additions & 0 deletions runtime/queries/hcl/indents.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
indent = [
"object",
"block",
"tuple",
"for_tuple_expr",
"for_object_expr"
]

outdent = [
"object_end",
"block_end",
"tuple_end"
]
2 changes: 2 additions & 0 deletions runtime/queries/hcl/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
((comment) @injection.content
(#set! injection.language "comment"))

0 comments on commit 43f7c32

Please sign in to comment.