on master help sign in
Add support for HCL language (#1705)

Queries based on the neovims ones: https://github.com/nvim-treesitter/nvim-treesitter/tree/master/queries/hcl and modified for helix support.

commit93ec42d06e6c7b8c157fd17a1ed40dda3ee91bf3 authorMichael Daffin <michael@daffin.io> dateFri 25 Feb 2022, 08:48 (5 years ago) parenta494f47
8 files changed+136
.gitmodules+4 book/src/generated/lang-support.md+1 helix-syntax/languages/tree-sitter-hcl+1 languages.toml+9 runtime/queries/hcl/folds.scm+6 runtime/queries/hcl/highlights.scm+100 runtime/queries/hcl/indents.toml+13 runtime/queries/hcl/injections.scm+2
.gitmodules+4
@@ -234,3 +234,7 @@
234234 path = helix-syntax/languages/tree-sitter-kotlin
235235 url = https://github.com/fwcd/tree-sitter-kotlin.git
236236 shallow = true
237+[submodule "helix-syntax/languages/tree-sitter-hcl"]
238+ path = helix-syntax/languages/tree-sitter-hcl
239+ url = https://github.com/MichaHoffmann/tree-sitter-hcl.git
240+ shallow = true
book/src/generated/lang-support.md+1
@@ -21,6 +21,7 @@
2121| go | ✓ | ✓ | ✓ | `gopls` |
2222| graphql | ✓ | | | |
2323| haskell | ✓ | | | `haskell-language-server-wrapper` |
24+| hcl | ✓ | | ✓ | |
2425| html | ✓ | | | |
2526| iex | ✓ | | | |
2627| java | ✓ | | | |
helix-syntax/languages/tree-sitter-hclnew file+1

Submodule changed.

languages.toml+9
@@ -757,3 +757,12 @@ roots = ["settings.gradle", "settings.gradle.kts"]
757757comment-token = "//"
758758indent = { tab-width = 4, unit = " " }
759759language-server = { command = "kotlin-language-server" }
760+
761+[[language]]
762+name = "hcl"
763+scope = "source.hcl"
764+injection-regex = "(hcl|tf)"
765+file-types = ["hcl", "tf"]
766+roots = []
767+comment-token = "#"
768+indent = { tab-width = 2, unit = " " }
runtime/queries/hcl/folds.scmnew file+6
@@ -0,0 +1,6 @@
1+[
2+ (comment)
3+ (block)
4+ (heredoc_template)
5+ (object)
6+] @fold
runtime/queries/hcl/highlights.scmnew file+100
@@ -0,0 +1,100 @@
1+(ERROR) @error
2+
3+; { key: val }
4+
5+(object_elem val: (expression
6+ (variable_expr
7+ (identifier) @type.builtin (#match? @type.builtin "^(bool|string|number|object|tuple|list|map|set|any)$"))))
8+
9+(get_attr (identifier) @variable.builtin (#match? @variable.builtin "^(root|cwd|module)$"))
10+(variable_expr (identifier) @variable.builtin (#match? @variable.builtin "^(var|local|path)$"))
11+((identifier) @type.builtin (#match? @type.builtin "^(bool|string|number|object|tuple|list|map|set|any)$"))
12+((identifier) @keyword (#match? @keyword "^(module|root|cwd|resource|variable|data|locals|terraform|provider|output)$"))
13+
14+; highlight identifier keys as though they were block attributes
15+(object_elem key: (expression (variable_expr (identifier) @variable.other.member)))
16+
17+(attribute (identifier) @variable.other.member)
18+(function_call (identifier) @function.method)
19+(block (identifier) @type.builtin)
20+
21+(identifier) @variable
22+(comment) @comment
23+(null_lit) @constant.builtin
24+(numeric_lit) @constant.number
25+(bool_lit) @constant.builtin.boolean
26+
27+[
28+ (template_interpolation_start) ; ${
29+ (template_interpolation_end) ; }
30+ (template_directive_start) ; %{
31+ (template_directive_end) ; }
32+ (strip_marker) ; ~
33+] @punctuation.special
34+
35+[
36+ (heredoc_identifier) ; <<END
37+ (heredoc_start) ; END
38+] @punctuation.delimiter
39+
40+[
41+ (quoted_template_start) ; "
42+ (quoted_template_end); "
43+ (template_literal) ; non-interpolation/directive content
44+] @string
45+
46+[
47+ "if"
48+ "else"
49+ "endif"
50+] @keyword.control.conditional
51+
52+[
53+ "for"
54+ "endfor"
55+ "in"
56+] @keyword.control.repeat
57+
58+[
59+ ":"
60+ "="
61+] @none
62+
63+[
64+ (ellipsis)
65+ "\?"
66+ "=>"
67+] @punctuation.special
68+
69+[
70+ "."
71+ ".*"
72+ ","
73+ "[*]"
74+] @punctuation.delimiter
75+
76+[
77+ "{"
78+ "}"
79+ "["
80+ "]"
81+ "("
82+ ")"
83+] @punctuation.bracket
84+
85+[
86+ "!"
87+ "\*"
88+ "/"
89+ "%"
90+ "\+"
91+ "-"
92+ ">"
93+ ">="
94+ "<"
95+ "<="
96+ "=="
97+ "!="
98+ "&&"
99+ "||"
100+] @operator
runtime/queries/hcl/indents.tomlnew file+13
@@ -0,0 +1,13 @@
1+indent = [
2+ "object",
3+ "block",
4+ "tuple",
5+ "for_tuple_expr",
6+ "for_object_expr"
7+]
8+
9+outdent = [
10+ "object_end",
11+ "block_end",
12+ "tuple_end"
13+]
runtime/queries/hcl/injections.scmnew file+2
@@ -0,0 +1,2 @@
1+((comment) @injection.content
2+ (#set! injection.language "comment"))