Skip to content

Support for .tpf (Helm chart Yaml-based template files) #220

Open

Description

@mickaelistria

It seems like Helm Chart files are basically Kubernetes yaml files with templating capability in {{...}} blocks.
It would be nice if Yaml Language Server could provide support for those files (by pre-setting schema, allowing validation/completion in {{...}} and so on.

Activity

  1. nklmilojevic commented on May 31, 2021

    @nklmilojevic

    What is needed for this to be added - how we can help? There is https://github.com/Azure/vscode-kubernetes-tools/blob/master/syntaxes/helm.tmLanguage.json which VSCode uses to correctly highlight Helm template syntax.

  2. valorl commented on Jul 27, 2021

    @valorl

    There seems to be a tree-sitter grammar for go templates. It might be useful here.

    With tree-sitter and this grammar, the template blocks can be fully parsed into an AST that could be used for functionality beyond highlighting, such as diagnostics, autocomplete, etc.

    https://github.com/ngalaiko/tree-sitter-go-template

  3. luisdavim commented on Aug 11, 2022

    @luisdavim

    It would be nice to make this work with templates in general and not just helm templates, {{...}} is the default delimiter set but it can be customised, and we also have Jinja and ERB....

  4. kekscode commented on Jul 28, 2023

    @kekscode

    Just revisiting after nearly a year. Any new solutions or workarounds? @luisdavim any thoughts?

  5. Kerwood commented on Jul 28, 2023

    @Kerwood

    Would be nice to see this feature.

  6. luisdavim commented on May 18, 2024

    @luisdavim
  7. luisdavim commented on May 18, 2024

    @luisdavim

    This is the setup I landed on, install these 2 plugins:

    Then configure the language server to run helm-ls for helm files, in my case, I use https://github.com/neoclide/coc.nvim so I have:

    "languageserver": {
      "helm": {
        "command": "helm_ls",
        "args": ["serve"],
        "filetypes": ["helm", "helmfile"],
        "rootPatterns": ["Chart.yaml"]
      }
    }

    This solves the problems with all the diagnostics errors from yaml ls but still uses it under the covers if installed.
    There's a TreeSitter gramar for helm so that also works out nicely.

  8. UgaTheDev commented on Aug 13, 2026

    @UgaTheDev

    This issue is six years old, so before proposing anything, here is what has already been tried and why it went nowhere:

    So the recorded objection is specific: this server should not learn Helm semantics, and it should not swap out its YAML parser. I agree with both. What I want to propose is narrower and does neither.

    Proposal: opt-in masking of {{ ... }} spans before parsing, same length, no semantics.

    Behind a new setting (yaml.template: "none" | "helm", default "none", plumbed exactly like yaml.keyOrdering through settingsHandlers.ts and LanguageSettings), replace each Go-template span with inert text of identical length before the text reaches the YAML parser:

    • A line whose content is only a template expression ({{- if .Values.x }}, {{- end }}) becomes a comment of the same length (# plus filler). These lines drop out of the document structure, which is what you want for control flow.
    • An inline expression (foo: {{ .Values.name }}) becomes an unquoted filler scalar of the same length. The value parses as a plain string.
    • Expressions already inside quotes are valid YAML today and masking them is a harmless no-op.

    Because every replacement is length-preserving, all offsets survive. Diagnostics, hover, completion, and symbol ranges map back to the real document with no position translation layer.

    Where it hooks in. All features go through one choke point: YamlDocuments.ensureCache in src/languageservice/parser/yaml-documents.ts, which does let text = document.getText() (line 304) and then calls parse() from yamlParser07.ts. Masking is one function applied to text at that point, plus adding the setting to the cache-invalidation check a few lines above (it currently compares only document version and customTags). Validation, completion, hover, folding, symbols, code lens, and definition all read from that cache, so they all benefit from one edit site. The formatter is the only feature that bypasses the cache (yamlFormatter.ts runs prettier on the raw text); when masking is active for a document, format should return no edits, since prettier would mangle the template syntax anyway.

    What this fixes, concretely. I checked how the current parser (yaml 2.x, strict: false) handles these inputs:

    • {{- if .Values.enabled }} at block level produces a cascade of BLOCK_IN_FLOW, MISSING_CHAR, and UNEXPECTED_TOKEN errors, one per following line. This is the wall of red everyone in this thread is describing.
    • foo: {{ .Values.name }} composes without syntax errors, but as a nested flow map, so schema validation then reports a type error (object where a string was expected).

    Masking removes both failure modes. What remains fully working on the rest of the file: schema validation (including Kubernetes schemas), duplicate key detection, completion and hover on non-template keys, document symbols, folding.

    Honest limits, stated up front:

    • No completion, hover, or validation inside {{ }}. That is helm-ls territory and stays there. This proposal only stops the template syntax from poisoning everything around it.
    • A fully templated value validates as a string. If the schema expects a number or boolean there, you get a type error. This can be handled by suppressing type diagnostics whose range overlaps a masked span, which is a small filter in YAMLValidation.doValidation, but I would leave that for a second iteration.
    • {{ include "x" . | nindent 4 }} producing block content, and if/else branches that both define the same key, can still yield false positives (missing property, duplicate key). Masking cannot know what the template expands to.
    • Multi-line template expressions get masked line by line; positions stay correct but the result is uglier than the single-line case.

    Scope of the change. One masking function plus tests, one setting, one line in ensureCache, one guard in the formatter. No new dependencies, no parser changes, no Helm awareness beyond the {{ }} delimiters. Off by default, so zero behavior change for anyone who does not opt in. Auto-detection for files under charts/*/templates/ could come later as a separate opt-in, but I would start with the explicit setting only.

    If a maintainer agrees with this shape, or wants it adjusted (different setting name, comment-masking vs whitespace, detection story), I will put up a PR implementing it behind the setting.

  9. UgaTheDev commented on Aug 13, 2026

    @UgaTheDev

    Opened PR #1321 implementing the proposal above.

    It came out close to the shape I described: one masking function, one setting (yaml.template, default none), one line in ensureCache, and a guard in the formatter. No new dependencies, no parser changes, no Helm awareness beyond the {{ }} delimiters.

    On the chart in the PR description, the parser goes from 10 errors to 0. Both directions are asserted in the tests, so it cannot regress into a no-op without failing.

    The limits I listed above still stand, and they are repeated in the PR rather than left implicit: nothing works inside {{ }}, a fully templated value validates as a string, and expressions that expand to block content can still produce false positives.

    One decision I would like a maintainer's opinion on. The template mode is stored on YamlDocuments instead of being added to ParserOptions, because most callers of getYamlDocument pass no options at all, so keying it off the options would make masking depend on which feature filled the cache first. It is easy to move if you would rather it live elsewhere.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions