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. There are a few snippets that I did not know how to port across and are commented out.
  • Loading branch information
mdaffin committed Feb 24, 2022
1 parent f83843c commit ab65bc7
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,6 @@
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
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) @field)))

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

(identifier) @variable
(comment) @comment
(null) @constant.builtin
(numeric_literal) @constant.number

[
(true)
(false)
] @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

[
"if"
(conditional)
] @conditional

[
"for"
"in"
] @repeat

[
":"
"="
] @none

[
"?"
"=>"
] @punctuation.special

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

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

[
"!"
"\*"
"/"
"%"
"\+"
"-"
">"
">="
"<"
"<="
"=="
"!="
"&&"
"||"
] @operator

[
(string_literal)
(quoted_template)
] @string

(escape_sequence) @punctuation.special
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 ab65bc7

Please sign in to comment.