Skip to content

Add packer language for HCL2 Packer templates - #16203

Open
sanga wants to merge 1 commit into
helix-editor:masterfrom
sanga:packer-language-support
Open

Add packer language for HCL2 Packer templates#16203
sanga wants to merge 1 commit into
helix-editor:masterfrom
sanga:packer-language-support

Conversation

@sanga

@sanga sanga commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

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.

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>
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.

1 participant