Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for HCL language #1705

Merged
merged 1 commit into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"))