Repository navigation
Support HCL objects natively - #107
Conversation
`=` between an object key and value is now `punctuation.separator.key-value.terraform`, matching `:` and the `=>` of object `for` expressions. Block attribute `=` keeps `keyword.operator.assignment.terraform`. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The scope was misspelled as `punctuation.section.baces.begin/end`,
so the basic brace folding rule never matched and object constructor
`{ ... }` expressions did not fold through it.
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Object constructors only recognised `identifier =`, `"string" =` and `(expr) =` elements and handed everything else to the JSON syntax's `object-body`, so valid HCL such as `aws.secrets-manager = ...`, `foo: 1` or `"a": var.x` was highlighted as `invalid.illegal.*.json`. Parse elements following the HCL grammar instead: the key is an identifier or any expression (`object-key`, `object-key-expression`), followed by `=` or `:` (`object-key-separator`) and a full Terraform expression. `:` is scoped `punctuation.separator.key-value.terraform`. A `for` expression is only recognised as the first token of an object (`object-begin`), as in hclsyntax `parseObjectCons`. Fixes #95 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`JSON (Terraform)` gained Terraform string interpolation and line
comments to serve as the fallback for objects in
`Terraform.sublime-syntax`, which no longer uses it.
State files hold resolved values and no comments, so a literal `${...}`
in a value is not interpolation.
Keep the ACL and IP address highlighting of string values, and add a
syntax test for `.tfstate` files.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
deathaxe
left a comment
There was a problem hiding this comment.
Separating HCL from JSON is a reasonable step forward. Changes look good in general. Some comments and suggestions, following.
| pop: 1 | ||
| - match: (?=\S) | ||
| push: | ||
| - object-value |
There was a problem hiding this comment.
Object-value is not scoped meta.mapping.value nor is the separator scoped meta.mapping.terraform.
With keys being scoped meta.mapping.key and separators punctuation.separator.key-value, it is probably worth adding full meta.mapping.[key|value] support in addition to or replacing more general meta.braces.
There was a problem hiding this comment.
Good point, but I'd prefer to do this in a follow-up.
There was a problem hiding this comment.
The change wasn't that involved and it is still related to object matching, so I added it here after all.
There was a problem hiding this comment.
With braces of blocks being scoped punctuation.section.block, does it make sense to change braces of objects to punctuation.section.mapping?
It would likely - in a follow up - also advice to move tuples to "sequence" scope.
Commas between object elements are now scoped `punctuation.separator.sequence.terraform`, matching what the previous JSON fallback produced for JSON-style objects. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
655b059 to
5311d3b
Compare
Use `meta.mapping.terraform` for object bodies in place of `meta.braces.terraform`, following the scope naming conventions and the built-in JSON syntax. Existing `- meta.mapping` exclusions on separators and values become `- meta.mapping.key`, which is what they are about; the exclusions outside objects keep the full `- meta.mapping`. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Follow the built-in JSON syntax: keys and values clear the object's `meta.mapping.terraform` with `clear_scopes: 1` and are scoped `meta.mapping.key.terraform` and the new `meta.mapping.value.terraform`, so they are siblings of the mapping instead of nested in it. The value scope ends before trailing whitespace, a trailing line comment and a trailing single-line block comment. Separators, commas, and whitespace and comments between elements keep `meta.mapping.terraform`. Object `for` expressions are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Commas in tuples, function arguments and for-expression headers now use `punctuation.separator.sequence.terraform`, matching the commas between object elements (PR #107 review). Color schemes targeting `punctuation.separator` still match. The `/` and `:` in IP addresses keep `punctuation.separator.terraform`. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The previous object implementation (#71) was naïve and only supported the JSON notation but HCL objects are much more … terrible than that. Notably, they support arbitrary expressions in the key position and only when an identifier fails to be looked up it is treated as an unquoted string. We cannot resolve this from our syntax definition, of course, so we treat any single identifier as an unquoted string key, while treating the rest as a key expression (with the appropriate
meta.mapping.keyscope).Additionally,
=and:are equivalent separator characters and we are scoping both aspunctuation.separator.key-value.terraform.Closes #95.
PS: Turns out this wasn't so hard as I initially anticipated but Claude did all the work anyway.