Add packer language for HCL2 Packer templates - #16203
Open
sanga wants to merge 1 commit into
Open
Conversation
Packer templates (`*.pkr.hcl`) and variable files (`*.pkrvars.hcl`) are HCL2 but are *not* Terraform. Previously they were caught by the `hcl` language's `"hcl"` extension and had `terraform-ls` attached, which produces spurious diagnostics since packer's schema differs from terraform's. Add a dedicated `packer` language, modeled on the sibling `tfvars` entry: it reuses the existing `hcl` grammar (no new `[[grammar]]`) and its queries are `; inherits: hcl`. - Uses `file-types` globs rather than plain extensions because `.pkr.hcl` / `.pkrvars.hcl` are compound suffixes; plain extension matching only sees `.hcl`. The glob matcher is consulted before the extension fallback and prefers the longest matching glob, so these files resolve to `packer` while bare `*.hcl` still resolves to `hcl`. - No default language server: there is no widely-available packer LSP, and attaching `terraform-ls` is exactly the bug being fixed. - Formats with `packer fmt -` (reads stdin, writes stdout), covering both `.pkr.hcl` and `.pkrvars.hcl`. Query files provide full parity with the `hcl` grammar (highlights, injections, indents, textobjects, folds, rainbows). Note `tfvars` ships only four of these; the extra two are pure inherits with no downside. `book/src/generated/lang-support.md` regenerated with `cargo xtask docgen`. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Would solve #16115. Ping @kpbaks per request. Note that this is vibecoded. I glanced through it and it looked reasonable to me but I’m not very familiar with this code. Empirically seems to work fine locally.