You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support for .tpf (Helm chart Yaml-based template files) #220
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.
Reacted by Daniel Ciaglia, Jan Steinke, Alex Hokanson, Subrato, Maksim Kavaleu, Salomon Popp, Nikola Milojević, Valér Orlovský, Christian Agerbeck, T. Miller and 76 more
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.
Reacted by Hans, Narthana Epa, Matthew Critchlow, Trevor Hartman, dapc11, Aleksander Sumowski, Mikael Elkiaer, Robin Bürgi, Ben Rexin, Ilmurat Kerimov and 1 more
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....
Reacted by Robin Bürgi, Matthew Critchlow, Marek Maksimczyk, Jun, Ben Rexin, Jens Schneider, Matthew Kennedy, VladB, Nick Maltsev, Peter Cardenas and 5 more
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.
In this thread the workarounds that stuck are external: helm-ls, tree-sitter-go-template, vim-helm. They work, but only for editors where you can reroute the filetype, and helm-ls still shells back into yaml-language-server for the YAML half.
Issue [feature] Plugin system #1314 (plugin system) touched on this. The concern raised there was that Helm and Jinja would need the parser itself to be swappable, which is a big change nobody wants to make.
I searched merged and closed PRs for helm, template, and jinja. No PR has ever attempted any of this, in any form.
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.
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.
Activity
nklmilojevic commentedon May 31, 2021
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.
valorl commentedon Jul 27, 2021
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
luisdavim commentedon Aug 11, 2022
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....kekscode commentedon Jul 28, 2023
Just revisiting after nearly a year. Any new solutions or workarounds? @luisdavim any thoughts?
Kerwood commentedon Jul 28, 2023
Would be nice to see this feature.
luisdavim commentedon May 18, 2024
There is there now: https://github.com/mrjosh/helm-ls
luisdavim commentedon May 18, 2024
This is the setup I landed on, install these 2 plugins:
helm(this is the important part)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:
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.
UgaTheDev commentedon Aug 13, 2026
This issue is six years old, so before proposing anything, here is what has already been tried and why it went nowhere:
{{- if }}/{{- range }}lines) is still open and is really a duplicate of the parsing half of this issue.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 likeyaml.keyOrderingthroughsettingsHandlers.tsandLanguageSettings), replace each Go-template span with inert text of identical length before the text reaches the YAML parser:{{- 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.foo: {{ .Values.name }}) becomes an unquoted filler scalar of the same length. The value parses as a plain string.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.ensureCacheinsrc/languageservice/parser/yaml-documents.ts, which doeslet text = document.getText()(line 304) and then callsparse()fromyamlParser07.ts. Masking is one function applied totextat that point, plus adding the setting to the cache-invalidation check a few lines above (it currently compares only document version andcustomTags). 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.tsruns 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 ofBLOCK_IN_FLOW,MISSING_CHAR, andUNEXPECTED_TOKENerrors, 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:
{{ }}. That is helm-ls territory and stays there. This proposal only stops the template syntax from poisoning everything around it.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.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 undercharts/*/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.
UgaTheDev commentedon Aug 13, 2026
Opened PR #1321 implementing the proposal above.
It came out close to the shape I described: one masking function, one setting (
yaml.template, defaultnone), one line inensureCache, 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
YamlDocumentsinstead of being added toParserOptions, because most callers ofgetYamlDocumentpass 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.