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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Full helm-ls options: [helm-ls configuration](https://github.com/mrjosh/helm-ls/

## Empty mappings (`emptyDir: {}`)

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)).
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 combined across all `(text)` nodes so fragments between `{{ }}` keep their indentation context (#35). Zed can still drop combined ranges next to an edit ([zed#57341](https://github.com/zed-industries/zed/issues/57341), fix in [zed#63280](https://github.com/zed-industries/zed/pull/63280)).

## Testing

Expand Down
2 changes: 1 addition & 1 deletion extension.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ 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).
# injected combined across (text) nodes (#35); see zed#57341.
[grammars.helm]
repository = "https://github.com/cabrinha/helm.zed"
commit = "d4a62d114ffc784cf7df8ec294d8323d590de46d"
Expand Down
18 changes: 11 additions & 7 deletions languages/helm/injections.scm
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
; YAML highlighting for each (text) node. Use only @content: Zed errors
; YAML highlighting for template text. 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).
; Combined so all (text) fragments around {{ }} form one YAML document.
; Per-node injection parses each fragment on its own; a fragment that
; starts deep in a mapping and then dedents is invalid YAML and loses
; highlighting on load (#35).
;
; 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.
; Zed can drop combined ranges that only touch an edit
; (zed-industries/zed#57341, fix in zed-industries/zed#63280). The helm
; lexer keeps `{}`, the rest of that line, and the trailing newline in one
; text node to make that less likely next to emptyDir: {}.
((text) @content
(#set! "language" "yaml"))
(#set! "language" "yaml")
(#set! "combined"))
36 changes: 14 additions & 22 deletions scripts/check-grammar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -153,27 +153,21 @@ injection_has_capture() {

zed_injection_query_ok() {
local file="$1"
if injection_has_capture "$file" content \
&& injection_has_capture "$file" injection.content; then
if injection_has_capture "$file" content &&
injection_has_capture "$file" injection.content; then
echo "both content and injection.content captures are present" >&2
return 1
fi
if injection_has_capture "$file" language \
&& injection_has_capture "$file" injection.language; then
if injection_has_capture "$file" language &&
injection_has_capture "$file" injection.language; then
echo "both language and injection.language captures are present" >&2
return 1
fi
if ! injection_has_capture "$file" content \
&& ! injection_has_capture "$file" injection.content; then
if ! injection_has_capture "$file" content &&
! injection_has_capture "$file" injection.content; then
echo "missing required capture: content or injection.content" >&2
return 1
fi
# Combined YAML injection is zed#57341 / helm.zed#22: typing next to
# emptyDir: {} drops every YAML key. Inject each (text) node separately.
if grep -vE '^\s*;' "$file" | grep -Eq '(^|[^A-Za-z0-9_.])(injection\.)?combined($|[^A-Za-z0-9_.])'; then
echo "combined injection drops YAML on incremental parse in Zed (zed#57341)" >&2
return 1
fi
return 0
}

Expand Down Expand Up @@ -206,17 +200,15 @@ else
echo "ok detector rejects dual captures: $(tr '\n' ' ' <"$WORK/dual.err")"
fi

# Combined injection is the #22 incremental drop in Zed. Must not ship.
cat >"$WORK/combined-injections.scm" <<'EOF'
((text) @content
(#set! "language" "yaml")
(#set! "combined"))
EOF
if zed_injection_query_ok "$WORK/combined-injections.scm" 2>"$WORK/comb.err"; then
echo "QUERY CHECK MISSED combined injection"
fail=1
# Per-node YAML injection parses each (text) fragment between {{ }} as its
# own document. A fragment that starts deep in a mapping and then dedents
# (networkpolicy.yaml) is invalid YAML on its own and loses highlighting
# on load (#35). Keep combined so YAML sees the whole indentation context.
if grep -vE '^\s*;' "$injections" | grep -Eq '(^|[^A-Za-z0-9_.])(injection\.)?combined($|[^A-Za-z0-9_.])'; then
echo "ok injections.scm uses combined YAML injection"
else
echo "ok detector rejects combined injection: $(tr '\n' ' ' <"$WORK/comb.err")"
echo "QUERY FAILED injections.scm: must set combined (per-node YAML injection breaks #35)"
fail=1
fi

# Builtin captures for include/tpl/sha512sum, which the old regex list missed.
Expand Down
15 changes: 5 additions & 10 deletions scripts/check-zed-queries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,12 @@ else
echo "ok detector rejects dual captures: $(tr '\n' ' ' <"$WORK/dual.err")"
fi

# Combined injection is the #22 incremental drop in Zed. Must not ship.
cat >"$WORK/combined-injections.scm" <<'EOF'
((text) @content
(#set! "language" "yaml")
(#set! "combined"))
EOF
if zed_injection_query_ok "$WORK/combined-injections.scm" 2>"$WORK/comb.err"; then
echo "QUERY CHECK MISSED combined injection"
fail=1
# Per-node injection breaks YAML for fragments that dedent after {{ }} (#35).
if injection_is_combined "$ROOT/languages/helm/injections.scm"; then
echo "ok injections.scm uses combined YAML injection"
else
echo "ok detector rejects combined injection: $(tr '\n' ' ' <"$WORK/comb.err")"
echo "QUERY FAILED injections.scm: must set combined (per-node YAML injection breaks #35)"
fail=1
fi

# Invalid node type that made Helm vanish: backtick is not a token, raw
Expand Down
57 changes: 30 additions & 27 deletions scripts/lib/zed-queries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,33 @@ query_has_capture() {
# ("Error loading injection query: both content and injection.content captures are present").
zed_injection_query_ok() {
local file="$1"
if query_has_capture "$file" content \
&& query_has_capture "$file" injection.content; then
if query_has_capture "$file" content &&
query_has_capture "$file" injection.content; then
echo "both content and injection.content captures are present" >&2
return 1
fi
if query_has_capture "$file" language \
&& query_has_capture "$file" injection.language; then
if query_has_capture "$file" language &&
query_has_capture "$file" injection.language; then
echo "both language and injection.language captures are present" >&2
return 1
fi
if ! query_has_capture "$file" content \
&& ! query_has_capture "$file" injection.content; then
if ! query_has_capture "$file" content &&
! query_has_capture "$file" injection.content; then
echo "missing required capture: content or injection.content" >&2
return 1
fi
# Combined YAML injection is zed#57341 / helm.zed#22: typing next to
# emptyDir: {} drops every YAML key. Inject each (text) node separately.
if grep -vE '^\s*;' "$file" | grep -Eq '(^|[^A-Za-z0-9_.])(injection\.)?combined($|[^A-Za-z0-9_.])'; then
echo "combined injection drops YAML on incremental parse in Zed (zed#57341)" >&2
return 1
fi
return 0
}

# Per-node YAML injection parses each (text) fragment between {{ }} as its
# own document. A fragment that starts deep in a mapping and then dedents
# is invalid YAML on its own, so highlighting breaks on load (helm.zed#35).
# Zed's incremental splice of combined layers is zed-industries/zed#57341.
injection_is_combined() {
local file="$1"
grep -vE '^\s*;' "$file" | grep -Eq '(^|[^A-Za-z0-9_.])(injection\.)?combined($|[^A-Za-z0-9_.])'
}

# Required captures Zed looks up after Query::new succeeds.
# Missing ones log an error and skip that feature; we still fail CI so
# registration does not silently drop brackets/indents/outline.
Expand All @@ -49,20 +52,20 @@ zed_required_captures_ok() {
local name
name="$(basename "$file")"
case "$name" in
brackets.scm)
query_has_capture "$file" open && query_has_capture "$file" close
;;
indents.scm)
query_has_capture "$file" indent
;;
outline.scm)
query_has_capture "$file" item && query_has_capture "$file" name
;;
injections.scm)
zed_injection_query_ok "$file"
;;
*)
return 0
;;
brackets.scm)
query_has_capture "$file" open && query_has_capture "$file" close
;;
indents.scm)
query_has_capture "$file" indent
;;
outline.scm)
query_has_capture "$file" item && query_has_capture "$file" name
;;
injections.scm)
zed_injection_query_ok "$file"
;;
*)
return 0
;;
esac
}
44 changes: 44 additions & 0 deletions tests/fixtures/networkpolicy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
name: {{ include "valkey.name" . }}
namespace: {{ .Release.Namespace }}
labels: {{- include "valkey.labels" . | nindent 4 }}
spec:
podSelector:
matchLabels: {{- include "valkey.selectorLabels" . | nindent 6 }}
policyTypes:
- Ingress
- Egress
ingress:
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: {{ .Release.Namespace }}
podSelector:
matchLabels:
networkpolicy.valkey.net/valkey-access: "true"
ports:
- protocol: TCP
port: 6379 # Default Valkey database port
- protocol: TCP
port: 26379 # Sentinel port
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: alloy
podSelector:
matchLabels:
app.kubernetes.io/instance: alloy
app.kubernetes.io/name: alloy
ports:
- protocol: TCP
port: 9121 # Valkey/Redis Exporter port
- from:
- podSelector:
matchLabels: {{- include "valkey.selectorLabels" . | nindent 14 }}
ports:
- protocol: TCP
port: 6379 # Default Valkey database port
- protocol: TCP
port: 26379 # Sentinel port
Loading