Skip to content

fix: broken syntax highlighting - #36

Merged
cabrinha merged 2 commits into
cabrinha:mainfrom
tzabbi:fix/broken-syntax-highlighting
Oct 11, 2026
Merged

cabrinha merged 2 commits into
cabrinha:mainfrom
tzabbi:fix/broken-syntax-highlighting

Conversation

@tzabbi

@tzabbi tzabbi commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #35. Restores (#set! "combined") in languages/helm/injections.scm so all (text) fragments are injected as one YAML document again, like in v0.0.6.

With this fix:
grafik

Without this fix:
grafik

Root cause

Since v0.0.7 (commit 5095657, "Inject YAML per text node instead of combined", shipped with #32), YAML is injected into each (text) node separately. The helm grammar splits the file at every {{ … }} action, so each fragment between two actions was parsed as its own standalone YAML document, with no knowledge of the indentation context around it.

That breaks as soon as a {{ … }} sits inside a deeply nested block and the YAML after it dedents. From tests/fixtures/networkpolicy.yaml:

              kubernetes.io/metadata.name: {{ .Release.Namespace }}
          podSelector:            # <- new fragment starts here, root indent = 10
            matchLabels:
              networkpolicy.valkey.net/valkey-access: "true"
      ports:                      # <- indent 6 < root indent 10 => invalid YAML
        - protocol: TCP
    - from:                       # <- indent 4
      ...
            matchLabels: {{- include "valkey.selectorLabels" . | nindent 14 }}

As a standalone document this fragment is invalid YAML. tree-sitter-yaml produces an ERROR node for podSelector … "true" and drops the rest of the fragment, so roughly lines 21–38 (both ports: blocks and the second and third - from: entries) lose YAML highlighting entirely. Highlighting comes back after the next {{ … }}, because that fragment happens to start at a valid indentation again.

Reproduced outside of Zed by parsing the fixture with the vendored helm grammar and tree-sitter-yaml:

Mode Result
helm grammar 7 (text) nodes, no ERROR
per-node YAML injection (v0.0.7 / v0.0.8) fragment starting at line 17 → ERROR
whole document with {{ … }} blanked (≈ combined) no ERROR

This is common in real charts: any {{ … }} value in a nested mapping followed by a dedent triggers it.

Why combined was removed, and the trade-off

combined was dropped as a workaround for #22 / zed-industries/zed#57341. Zed's splice_included_ranges discards combined-injection ranges that only touch an edit, so typing next to emptyDir: {} could wipe YAML highlighting for the rest of the file. The commit right before the removal (a2d11d5) already noted that removing combined "would stop YAML from stitching across {{ }} on load". That is exactly what #35 is.

Bringing combined back means:

A YAML layer that is valid on load and occasionally dropped while editing seemed better to us than one that is wrong on load for a large share of real-world templates.

Testing

@tzabbi
tzabbi force-pushed the fix/broken-syntax-highlighting branch from 0f582a1 to 45be107 Compare October 10, 2026 16:17
@cabrinha
cabrinha merged commit 1dde2e8 into cabrinha:main Oct 11, 2026
7 checks passed
@tzabbi
tzabbi deleted the fix/broken-syntax-highlighting branch October 11, 2026 13:42
@Hoid

Hoid commented Oct 12, 2026

Copy link
Copy Markdown

So glad this was fixed! Looking forward to the next release :)

@anthony-t-johnson

anthony-t-johnson commented Oct 15, 2026 •

Copy link
Copy Markdown

Just updated Zed to 1.24.2 and it's working flawlessly 😍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Syntax highlighting is broken

4 participants