diff --git a/README.md b/README.md index 1d1acb4..174f02a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/extension.toml b/extension.toml index 0313ecb..7f0e809 100644 --- a/extension.toml +++ b/extension.toml @@ -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" diff --git a/languages/helm/injections.scm b/languages/helm/injections.scm index 50b4fbd..6deab87 100644 --- a/languages/helm/injections.scm +++ b/languages/helm/injections.scm @@ -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")) diff --git a/scripts/check-grammar.sh b/scripts/check-grammar.sh index 35f21d0..e5d0d01 100755 --- a/scripts/check-grammar.sh +++ b/scripts/check-grammar.sh @@ -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 } @@ -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. diff --git a/scripts/check-zed-queries.sh b/scripts/check-zed-queries.sh index 06abd2d..1623e32 100755 --- a/scripts/check-zed-queries.sh +++ b/scripts/check-zed-queries.sh @@ -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 diff --git a/scripts/lib/zed-queries.sh b/scripts/lib/zed-queries.sh index c251013..c4efa9a 100644 --- a/scripts/lib/zed-queries.sh +++ b/scripts/lib/zed-queries.sh @@ -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. @@ -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 } diff --git a/tests/fixtures/networkpolicy.yaml b/tests/fixtures/networkpolicy.yaml new file mode 100644 index 0000000..23e659f --- /dev/null +++ b/tests/fixtures/networkpolicy.yaml @@ -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