|
| 1 | +HCL syntax highlighting: TS report |
| 2 | +==================================== |
| 3 | + |
| 4 | +Sample file: `hcl.hcl` |
| 5 | +TS query: `misc/syntax-ts/queries-override/hcl-highlights.scm` |
| 6 | +TS colors: `misc/syntax-ts/colors.ini` `[hcl]` |
| 7 | +Grammar: `hcl` (language: `hcl`) |
| 8 | +Legacy reference: none (legacy produces no highlighting for `.hcl` |
| 9 | +files) |
| 10 | + |
| 11 | +Note: There is no legacy syntax highlighting for generic HCL files |
| 12 | +in MC. This report documents the TS highlighting choices only. |
| 13 | + |
| 14 | +Color assignments |
| 15 | +----------------- |
| 16 | + |
| 17 | +- Top-level block names (`service`, `job`, `locals`, `output`, |
| 18 | + `variable`, etc.): `brightmagenta` (keyword.directive) — any |
| 19 | + identifier that starts a top-level block gets this color. HCL is |
| 20 | + a generic language with no reserved block names. |
| 21 | +- Nested block names (`group`, `task`, `config`, `resources`, etc.): |
| 22 | + DEFAULT — inner blocks are not colored to avoid visual noise. |
| 23 | +- Control flow keywords (`if`, `else`, `endif`, `for`, `endfor`, |
| 24 | + `in`): `yellow`. |
| 25 | +- Comments (`#`, `//`, `/* */`): `brown`. |
| 26 | +- Strings (quoted, heredocs): `green`. |
| 27 | +- Numbers: `lightgray`. |
| 28 | +- Booleans (`true`, `false`): `lightgray` (constant). |
| 29 | +- Null (`null`): `lightgray` (constant). |
| 30 | +- Type references (`string`, `number`, `bool`, `object`, `tuple`, |
| 31 | + `list`, `map`, `set`, `any`): `yellow` (type). |
| 32 | +- Operators (`=`, `+`, `-`, `*`, `/`, `%`, `!`, `==`, `!=`, `<`, |
| 33 | + `>`, `<=`, `>=`, `&&`, `||`, `?`, `=>`, `:`): `brightcyan`. |
| 34 | +- Delimiters (`{`, `}`, `[`, `]`, `(`, `)`, `,`, `.`, `.*`, |
| 35 | + `[*]`): `brightcyan`. |
| 36 | +- Template interpolation (`${`, `}`): `brightcyan` (operator). |
| 37 | +- Heredoc identifiers: `green`. |
| 38 | +- Splat expressions (`[*]`, `.*`): `brightcyan` (delimiter). |
| 39 | + |
| 40 | +Design decisions |
| 41 | +---------------- |
| 42 | + |
| 43 | +- HCL is a generic configuration language with no reserved block |
| 44 | + names. All top-level block identifiers are colored uniformly as |
| 45 | + `brightmagenta` regardless of their name. This distinguishes |
| 46 | + structural blocks from attribute keys without hardcoding any |
| 47 | + specific keyword list. |
| 48 | +- Nested block names are left as DEFAULT to avoid confusion with |
| 49 | + variable references and attribute keys, which also appear as |
| 50 | + plain identifiers. |
| 51 | +- No variable reference prefixes are colored (unlike Terraform's |
| 52 | + `var.`, `local.`, etc.) since HCL itself has no such convention. |
| 53 | + Applications that embed HCL may define their own prefixes. |
| 54 | + |
| 55 | +Known shortcomings |
| 56 | +------------------ |
| 57 | + |
| 58 | +- Legacy MC has no highlighting for `.hcl` files at all, so there |
| 59 | + is nothing to compare against. |
| 60 | +- Function calls in expressions (e.g. `join()`, `upper()`) are not |
| 61 | + colored. The HCL grammar parses them as `function_call` nodes but |
| 62 | + the query does not capture them to keep the highlighting minimal |
| 63 | + for a generic language. |
0 commit comments