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
106 changes: 106 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: CI

on:
pull_request:
push:
branches: [main]

env:
ZED_EXTENSION_CLI_SHA: 9ee3c503a4bbbc6b4a0f8a789acca4871d773223

jobs:
rust:
name: Rust tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-wasip1
- name: Unit tests
run: cargo test
- name: WASM build
run: cargo build --target wasm32-wasip1 --release

grammar-pin:
name: Grammar pin
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: Check pin lock and generated files
run: bash scripts/check-grammar-pin.sh

zed-query-load:
name: Zed query load
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: Reject queries Zed cannot register
run: bash scripts/check-zed-queries.sh

queries:
name: Chart fixtures and queries
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 fixtures and check queries
run: bash scripts/check-queries.sh

package:
name: Package extension
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-wasip1, wasm32-wasip2
- id: cache-zed-extension-cli
name: Cache zed-extension CLI
uses: actions/cache@v4
with:
path: zed-extension
key: zed-extension-${{ env.ZED_EXTENSION_CLI_SHA }}
- name: Download zed-extension CLI
if: steps.cache-zed-extension-cli.outputs.cache-hit != 'true'
run: |
wget --quiet "https://zed-extension-cli.nyc3.digitaloceanspaces.com/${ZED_EXTENSION_CLI_SHA}/x86_64-unknown-linux-gnu/zed-extension" -O "$GITHUB_WORKSPACE/zed-extension"
chmod +x "$GITHUB_WORKSPACE/zed-extension"
- name: Package with zed-extension
run: |
chmod +x "$GITHUB_WORKSPACE/zed-extension"
mkdir -p /tmp/ext-scratch /tmp/ext-output
"$GITHUB_WORKSPACE/zed-extension" --source-dir . --scratch-dir /tmp/ext-scratch --output-dir /tmp/ext-output

query-format:
name: Query format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download ts_query_ls
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh release download v3.15.1 --repo ribru17/ts_query_ls --pattern ts_query_ls-x86_64-unknown-linux-gnu.tar.gz --dir "$GITHUB_WORKSPACE"
- name: ts_query_ls format --check languages
run: |
tar -xf "$GITHUB_WORKSPACE/ts_query_ls-x86_64-unknown-linux-gnu.tar.gz" -C "$GITHUB_WORKSPACE"
"$GITHUB_WORKSPACE/ts_query_ls" format --check languages || {
echo "Found unformatted queries, please format them with ts_query_ls."
echo "For easy use, install the Tree-sitter query extension:"
echo "zed://extension/tree-sitter-query"
false
}
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Syntax highlighting for Helm templates using tree-sitter, plus [helm-ls](https:/

Install from 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.
You do not need to install helm-ls first. The extension looks for `helm_ls`, then `helm-ls`, on PATH. If neither is there, it downloads a pinned helm-ls release and reuses that binary on later Zed starts.

[yaml-language-server](https://github.com/redhat-developer/yaml-language-server) is still required for full LSP. helm-ls shells out to it for Kubernetes schema validation. Without it you get Helm template intelligence only.

You can also pin a binary:

Expand All @@ -25,7 +27,7 @@ You can also pin a binary:

## 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`:
This matches the [official Zed Helm docs](https://zed.dev/docs/languages/helm). `.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
{
Expand All @@ -46,10 +48,12 @@ You can also pin a binary:
}
```

Leave `Chart.yaml` as YAML. It is chart metadata, not a template.
Leave `Chart.yaml` as YAML. It is chart metadata, not a template. Path globs such as `charts/*/templates/*.yaml` are not valid in `languages/helm/config.toml` `path_suffixes`; those stay in `file_types`.

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.

`**/values*.yaml` is included because helm-ls understands values files.

## 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:
Expand Down Expand Up @@ -94,6 +98,18 @@ Full helm-ls options: [helm-ls configuration](https://github.com/mrjosh/helm-ls/

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)).

## Testing

```sh
cargo test
./scripts/check-queries.sh
./scripts/check-grammar.sh
./scripts/check-grammar-pin.sh
./scripts/check-zed-queries.sh
```

CI also packages with the `zed-extension` CLI and runs `ts_query_ls format --check languages`.

## Credits

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).
Expand Down
15 changes: 11 additions & 4 deletions languages/helm/brackets.scm
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
("{{" @open "}}" @close)
("{{-" @open "-}}" @close)
("(" @open ")" @close)
("\"" @open "\"" @close)
("{{" @open
"}}" @close)

("{{-" @open
"-}}" @close)

("(" @open
")" @close)

("\"" @open
"\"" @close)
4 changes: 4 additions & 0 deletions languages/helm/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ brackets = [
{ start = "\"", end = "\"", close = true, newline = false },
{ start = "`", end = "`", close = true, newline = false },
]
decrease_indent_patterns = [
{ pattern = "^\\s*\\{\\{-?\\s*else(\\s+if)?\\b", valid_after = ["if", "range", "with"] },
{ pattern = "^\\s*\\{\\{-?\\s*end\\b" },
]
62 changes: 25 additions & 37 deletions languages/helm/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
; Identifiers

[
(field)
(field_identifier)
Expand All @@ -10,7 +9,6 @@
(dot) @variable.special

; Function calls

(function_call
function: (identifier) @function)

Expand All @@ -19,7 +17,6 @@
field: (field_identifier) @function))

; Operators

[
"|"
":="
Expand All @@ -33,37 +30,30 @@
(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"))
"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
Expand All @@ -78,8 +68,8 @@
"Values" "Chart" "Release" "Capabilities" "Files" "Subcharts" "Template"))

; Delimiters

"." @punctuation.delimiter

"," @punctuation.delimiter

[
Expand All @@ -92,7 +82,6 @@
] @punctuation.bracket

; Keywords

[
"else"
"if"
Expand All @@ -107,7 +96,6 @@
] @keyword

; Literals

[
(interpreted_string_literal)
(raw_string_literal)
Expand Down
15 changes: 15 additions & 0 deletions languages/helm/indents.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; Indent bodies of template control actions. `end` / `else` outdent so they
; line up with the opening action, matching everyday Helm editing.
(if_action) @indent @start.if

(range_action) @indent @start.range

(with_action) @indent @start.with

(define_action) @indent

(block_action) @indent

"else" @outdent

"end" @outdent
3 changes: 1 addition & 2 deletions languages/helm/injections.scm
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@
; 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! "language" "yaml"))
6 changes: 6 additions & 0 deletions languages/helm/textobjects.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
; Named templates are the function-like unit in Helm.
(define_action) @function.around

(block_action) @function.around

(comment)+ @comment.around
47 changes: 47 additions & 0 deletions scripts/check-grammar-pin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
# Grammar pin / generated-files gate.
#
# 1. extension.toml [grammars.helm] commit must match tests/grammar-pin.sha
# so the revision Zed downloads is the one queries are compiled against.
# 2. Prefer vendor/tree-sitter-helm in this checkout (the newline-after-{}
# lexer). Clone the pin only if vendor/ is missing.
# 3. Like ngalaiko/tree-sitter-go-template CI: regenerate the helm dialect
# and fail if committed parser artifacts drift (aside from the CLI
# version banner in parser.c).
set -euo pipefail

# shellcheck source=lib/grammar-pin.sh
source "$(cd "$(dirname "$0")" && pwd)/lib/grammar-pin.sh"

load_grammar_pin
assert_grammar_pin_lock

WORK="$(mktemp -d)"
trap 'rm -rf "$WORK"' EXIT
ensure_tree_sitter "$WORK"

echo "Pin $GRAMMAR_REPO @$GRAMMAR_COMMIT ($GRAMMAR_PATH)"
echo "tree-sitter $(tree-sitter --version)"

stage_helm_grammar "$WORK/dialect"
echo "ok grammar pin lock matches extension.toml and tests/grammar-pin.sha"

cd "$DIALECT"
git init -q
git add -A
git -c user.name=ci -c user.email=ci@helm.zed commit -qm pin
tree-sitter generate

# Ignore the "Automatically @generated by tree-sitter vX.Y.Z" banner so a
# patch CLI bump does not fail this gate. Real parser/node-types drift still
# fails, same as `git diff --exit-code` in the upstream grammar CI.
if ! git diff --exit-code \
-I 'Automatically @generated by tree-sitter' \
-- src; then
echo "generated helm grammar artifacts drifted from git at $GRAMMAR_COMMIT" >&2
echo "Bump the pin only to a commit whose $GRAMMAR_PATH/src is generated." >&2
exit 1
fi

echo "ok generated $GRAMMAR_PATH/src matches git (ignoring CLI version banner)"
echo "Grammar pin is consistent."
Loading
Loading