Skip to content
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
19 changes: 19 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Test

on:
pull_request:
push:
branches: [main]

jobs:
grammar:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "22"
- name: Install tree-sitter CLI
run: npm install -g tree-sitter-cli@0.25.10
- name: Parse Helm fixtures
run: bash scripts/check-grammar.sh
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zed_helm"
version = "0.0.6"
version = "0.0.7"
edition = "2024"
publish = false
license = "Apache-2.0"
Expand Down
110 changes: 73 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,68 +1,104 @@
# helm.zed

Syntax highlighting for Helm templates using tree-sitter and integration of [helm-ls](https://github.com/mrjosh/helm-ls).
Syntax highlighting for Helm templates using tree-sitter, plus [helm-ls](https://github.com/mrjosh/helm-ls).

## Installation

Before the extension is working properly, you have to install the [helm-ls](https://github.com/mrjosh/helm-ls#installation-with-a-package-manager)
and [yaml-languages-server](https://github.com/redhat-developer/yaml-language-server) with your preferred package manager.
Install from the [Zed extension store](https://zed.dev/extensions/helm).

Install this extension via the [Zed extension store](https://zed.dev/extensions/helm).
The extension looks for `helm_ls`, then `helm-ls`, on PATH. If neither is there it downloads a helm-ls release. [yaml-language-server](https://github.com/redhat-developer/yaml-language-server) is optional; helm-ls uses it for Kubernetes schema diagnostics when it is installed.

The extension relies on the PATH environment variable and first looks for 'helm_ls', then 'helm-ls'.
If neither is available, an error is shown.
You can also pin a binary:

## Configuration
```json
{
"lsp": {
"helm_ls": {
"binary": {
"path": "/usr/local/bin/helm_ls",
"arguments": ["serve"]
}
}
}
}
```

## File detection

`.tpl`, `.gotmpl`, `helmfile.yaml`, and `helmfile.yml` are Helm out of the box. Chart templates still share `.yaml` with ordinary YAML, so map those in `settings.json`:

```json
{
"file_types": {
"Helm": [
"**/templates/**/*.tpl",
"**/templates/**/*.yaml",
"**/templates/**/*.yml",
"**/templates/**/*.gotmpl",
"**/helmfile.d/**/*.yaml",
"**/helmfile.d/**/*.yml",
"helmfile.yaml",
"helmfile.yml",
"**/values*.yaml",
"**/values*.yml"
]
}
}
```

Leave `Chart.yaml` as YAML. It is chart metadata, not a template.

This is an example of providing configuration for the language server via Zed's `settings.json`.
For full reference of possible values, refer to [helm-ls configuration section](https://github.com/mrjosh/helm-ls/?tab=readme-ov-file#configuration-options).
If a `.yaml` file still opens as YAML, pick Helm in the language selector once, or add the glob above. helm-ls will not start on files that stay tagged as YAML, and yaml-language-server will flag `{{ }}` as errors.

## Language server settings

helm-ls reads the `helm-ls` section of workspace configuration. Put that nested object under `lsp.helm_ls.settings` (`lsp.helm` and `lsp.helm-ls` also work). These two shapes are equivalent:

```json
{
"lsp": {
"helm_ls": {
"settings": {
"yamlls": {
"enabled": false
}
}
}
}
}
```

```json
{
...
"lsp": {
"helm_ls": {
"settings": {
"helm-ls": {
"logLevel": "info",
"yamlls": {
"enabled": true
"enabled": true,
"enabledForFilesGlob": "*.{yaml,yml}"
}
}
}
}
},
"file_types": {
"Helm": [
"helmfile.yaml",
"helmfile.yml",
"Chart.yaml",
"Chart.yml",
"Chart.lock",
"requirements.yaml",
"requirements.yml",
"**/templates/**/*.tpl",
"**/templates/**/*.yaml",
"**/templates/**/*.yml",
"**/helmfile.d/**/*.yaml",
"**/helmfile.d/**/*.yml",
],
},
}
}
```

## Credits
`yamlls.enabled` only controls the yaml-language-server process that helm-ls starts. It does not disable Zed's own YAML language server. If CRDs are still underlined, the buffer is probably still language YAML. Use the `file_types` globs above.

Full helm-ls options: [helm-ls configuration](https://github.com/mrjosh/helm-ls/?tab=readme-ov-file#configuration-options).

[https://github.com/ngalaiko/tree-sitter-go-template]
## Empty mappings (`emptyDir: {}`)

## Release Process
The vendored helm grammar keeps `{}`, the rest of that line, and the trailing newline as one text token so typing at EOL after `emptyDir: {}` does not sit on the next node's start. YAML is injected per `(text)` node, not combined ([zed#57341](https://github.com/zed-industries/zed/issues/57341)).

Every time the extension is released:
## Credits

1. **Bump the Version:**
Update the version number in Cargo.toml and extension.toml.
Highlighting uses [tree-sitter-go-template](https://github.com/ngalaiko/tree-sitter-go-template), including the empty-mapping lexer fix from [tree-sitter-go-template#53](https://github.com/ngalaiko/tree-sitter-go-template/pull/53).

2. **Update Extension Index:**
After releasing, update the extension entry in [zed-industries/extensions](http://github.com/zed-industries/extensions/) to reflect the new version.
## Release process

This ensures users always have access to the newest version.
1. Bump the version in `Cargo.toml` and `extension.toml`.
2. After release, update the entry in [zed-industries/extensions](https://github.com/zed-industries/extensions/).
16 changes: 12 additions & 4 deletions extension.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
id = "helm"
name = "Helm"
version = "0.0.6"
version = "0.0.7"
schema_version = 1
authors = [
"cabrinha <yuppie@hey.com>",
Expand All @@ -14,7 +14,15 @@ repository = "https://github.com/cabrinha/helm.zed"
name = "helm_ls"
language = "Helm"

# helm-ls only treats languageId "helm" (lowercase) as a template document.
[language_servers.helm.language_ids]
Helm = "helm"

# Vendored helm dialect in this repo. `{}` plus rest of line plus the
# trailing newline is one text token, so an EOL insert after emptyDir: {}
# stays in that node and YAML for keys below is not dropped. YAML is
# injected per (text) node, not combined (zed#57341).
[grammars.helm]
repository = "https://github.com/ngalaiko/tree-sitter-go-template"
commit = "aa71f63de226c5592dfbfc1f29949522d7c95fac"
path = "dialects/helm"
repository = "https://github.com/cabrinha/helm.zed"
commit = "d4a62d114ffc784cf7df8ec294d8323d590de46d"
path = "vendor/tree-sitter-helm"
4 changes: 4 additions & 0 deletions languages/helm/brackets.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
("{{" @open "}}" @close)
("{{-" @open "-}}" @close)
("(" @open ")" @close)
("\"" @open "\"" @close)
17 changes: 16 additions & 1 deletion languages/helm/config.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
name = "Helm"
grammar = "helm"
line_comments = ["# "]
path_suffixes = [".helmignore"]
path_suffixes = [
"tpl",
"gotmpl",
"helm",
"yaml.gotmpl",
"yml.gotmpl",
"helmfile.yaml",
"helmfile.yml",
".helmignore",
]
# Templates that open with an action, including helmfile and _helpers.tpl.
# Path globs such as charts/*/templates/*.yaml still need file_types in settings.
first_line_pattern = "^\\s*\\{\\{[-]?\\s*(if|range|with|define|block|template|include|/\\*)"
tab_size = 2
word_characters = ["-"]
block_comment = ["{{/* ", " */}}"]
autoclose_before = ";:.,=}])>"
brackets = [
{ start = "{{", end = "}}", close = true, newline = false },
{ start = "{{-", end = "-}}", close = true, newline = false },
{ start = "(", end = ")", close = true, newline = false },
{ start = "\"", end = "\"", close = true, newline = false },
{ start = "`", end = "`", close = true, newline = false },
]
104 changes: 80 additions & 24 deletions languages/helm/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
; Identifiers

[
(field)
(field_identifier)
(field)
(field_identifier)
] @property

(variable) @variable

(dot) @variable.special

; Function calls

(function_call
Expand All @@ -18,36 +20,91 @@

; Operators

"|" @operator
":=" @operator

; Builtin functions

((identifier) @function.builtin
(#match? @function.builtin "^(abbrev|abbrevboth|add|add1|add1f|addf|adler32sum|ago|and|append|atoi|b32dec|b32enc|b64dec|b64enc|base|buildCustomCert|camelcase|call|cat|ceil|chunk|clean|coalesce|compact|concat|contains|date|dateInZone|dateModify|decryptAES|deepCopy|deepEqual|default|derivePassword|dict|dig|dir|div|divf|duration|durationRound|empty|encryptAES|eq|ext|fail|first|float64|floor|fromJson|fromJsonArray|fromYaml|fromYamlArray|ge|genCA|genPrivateKey|genSelfSignedCert|genSignedCert|get|getHostByName|gt|has|hasKey|hasPrefix|hasSuffix|html|htmlDate|htmlDateInZone|htpasswd|index|indent|initials|int|int64|isAbs|js|kebabcase|keys|kindIs|kindOf|last|le|len|list|lookup|lower|lt|max|maxf|merge|mergeOverwrite|min|minf|mod|mul|mulf|mustAppend|mustCompact|mustDateModify|mustDeepCopy|mustFirst|mustHas|mustInitial|mustLast|mustMerge|mustMergeOverwrite|mustPrepend|mustRegexFind|mustRegexFindAll|mustRegexMatch|mustRegexReplaceAll|mustRegexReplaceAllLiteral|mustRegexSplit|mustRest|mustReverse|mustSlice|mustToDate|mustToJson|mustToPrettyJson|mustToRawJson|mustToToml|mustUniq|mustWithout|ne|nindent|nospace|not|now|omit|or|pick|pluck|plural|prepend|print|printf|println|quote|randAlpha|randAlphaNum|randAscii|randBytes|randNumeric|regexFind|regexFindAll|regexMatch|regexReplaceAll|regexReplaceAllLiteral|regexSplit|repeat|replace|required|rest|reverse|round|semver|semverCompare|seq|set|sha1sum|sha256sum|shuffle|slice|snakecase|squote|sub|subf|substr|swapcase|ternary|title|toDate|toDecimal|toJson|toPrettyJson|toRawJson|toString|toStrings|toToml|toYaml|toYamlPretty|trim|trimAll|trimPrefix|trimSuffix|trunc|typeIs|typeIsLike|typeOf|uniq|unixEpoch|unset|until|untilStep|untitle|upper|urlJoin|urlParse|urlquery|uuidv4|values|without|wrap|wrapWith)$"))
[
"|"
":="
"="
] @operator

; Helm / Sprig / Go template builtins. Scoped to the function name so field
; identifiers such as .Values.index are not highlighted as functions, and so
; the matcher is a hash lookup (#any-of?) instead of a giant regex on every
; identifier.
(function_call
function: (identifier) @function.builtin
(#any-of? @function.builtin
"abbrev" "abbrevboth" "add" "add1" "add1f" "addf" "adler32sum" "ago" "all"
"and" "any" "append" "atoi" "b32dec" "b32enc" "b64dec" "b64enc" "base"
"buildCustomCert" "camelcase" "call" "cat" "ceil" "chunk" "clean" "coalesce"
"compact" "concat" "contains" "date" "dateInZone" "dateModify" "decryptAES"
"deepCopy" "deepEqual" "default" "derivePassword" "dict" "dig" "dir" "div"
"divf" "duration" "durationRound" "empty" "encryptAES" "eq" "ext" "fail"
"first" "float64" "floor" "fromJson" "fromJsonArray" "fromYaml"
"fromYamlArray" "ge" "genCA" "genPrivateKey" "genSelfSignedCert"
"genSignedCert" "get" "getHostByName" "gt" "has" "hasKey" "hasPrefix"
"hasSuffix" "html" "htmlDate" "htmlDateInZone" "htpasswd" "include" "index"
"indent" "initial" "initials" "int" "int64" "isAbs" "js" "kebabcase" "keys"
"kindIs" "kindOf" "last" "le" "len" "list" "lookup" "lower" "lt" "max"
"maxf" "merge" "mergeOverwrite" "min" "minf" "mod" "mul" "mulf"
"mustAppend" "mustCompact" "mustDateModify" "mustDeepCopy" "mustFirst"
"mustHas" "mustInitial" "mustLast" "mustMerge" "mustMergeOverwrite"
"mustPrepend" "mustRegexFind" "mustRegexFindAll" "mustRegexMatch"
"mustRegexReplaceAll" "mustRegexReplaceAllLiteral" "mustRegexSplit"
"mustRest" "mustReverse" "mustSlice" "mustToDate" "mustToJson"
"mustToPrettyJson" "mustToRawJson" "mustToToml" "mustUniq" "mustWithout"
"ne" "nindent" "nospace" "not" "now" "omit" "or" "pick" "pluck" "plural"
"prepend" "print" "printf" "println" "quote" "randAlpha" "randAlphaNum"
"randAscii" "randBytes" "randNumeric" "regexFind" "regexFindAll"
"regexMatch" "regexReplaceAll" "regexReplaceAllLiteral" "regexSplit"
"repeat" "replace" "required" "rest" "reverse" "round" "semver"
"semverCompare" "seq" "set" "sha1sum" "sha256sum" "sha512sum" "shuffle"
"slice" "snakecase" "squote" "sub" "subf" "substr" "swapcase" "ternary"
"title" "toDate" "toDecimal" "toJson" "toPrettyJson" "toRawJson" "toString"
"toStrings" "toToml" "toYaml" "toYamlPretty" "tpl" "trim" "trimAll"
"trimPrefix" "trimSuffix" "trunc" "typeIs" "typeIsLike" "typeOf" "uniq"
"unixEpoch" "unset" "until" "untilStep" "untitle" "upper" "urlJoin"
"urlParse" "urlquery" "uuidv4" "values" "without" "wrap" "wrapWith"))

; Built-in chart objects: {{ .Values.foo }} and {{ $.Release.Name }}
(field
name: (identifier) @constant.builtin
(#any-of? @constant.builtin
"Values" "Chart" "Release" "Capabilities" "Files" "Subcharts" "Template"))

(selector_expression
operand: (variable)
field: (field_identifier) @constant.builtin
(#any-of? @constant.builtin
"Values" "Chart" "Release" "Capabilities" "Files" "Subcharts" "Template"))

; Delimiters

"." @punctuation.delimiter
"," @punctuation.delimiter

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

; Keywords

"else" @keyword
"if" @keyword
"range" @keyword
"with" @keyword
"end" @keyword
"template" @keyword
"define" @keyword
"block" @keyword
[
"else"
"if"
"range"
"with"
"end"
"template"
"define"
"block"
"break"
"continue"
] @keyword

; Literals

Expand All @@ -72,4 +129,3 @@
] @constant.builtin

(comment) @comment
(ERROR) @error
13 changes: 11 additions & 2 deletions languages/helm/injections.scm
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
; YAML highlighting for each (text) node. Use only @content: Zed errors
; if @content and @injection.content are both set on the same pattern.
;
; Do not set combined. Zed drops a combined YAML layer on incremental
; edits (zed-industries/zed#57341).
;
; The helm lexer keeps `{}`, the rest of that line, and the trailing
; newline in one text node. An EOL insert after emptyDir: {} stays
; inside that node, so YAML for keys on later lines is not dropped.
((text) @content
(#set! "language" "yaml")
(#set! "combined"))
(#set! "language" "yaml"))

Loading
Loading