syntax icon indicating copy to clipboard operation
syntax copied to clipboard

Document use of grammars in template/expression context

Open radeksimko opened this issue 2 years ago • 0 comments

History

The main context in which we expect HCL/Terraform grammars to be used is to highlight whole HCL "bodies". For example

attr = "foobar"
block "label" {
  another = 42
}
ref = data.aws_instance.foo.tags["noot"]

The "expression" on the RHS after the = is part of the existing grammars and we happen to treat standalone expressions, such as

42
"foobar"
data.aws_instance.foo.tags["noot"]

The decision to treat standalone expressions as valid was mostly pragmatic, where it was easier to do it than not to, due to the way TextMate grammars and nesting inside works.

To date however, this was a rather "hidden feature".

Potential

There are context in which this can be genuinely useful. For example:

  • rendering full object structures in highlighted hover data (markdown), e.g. { foo = string, bar = set(number) }
  • template files, which are effectively the inner part of a template expression, i.e. the ... in attr = "${...}" - see https://github.com/hashicorp/vscode-terraform/issues/496 / https://github.com/hashicorp/vscode-terraform/issues/636

Proposal

  • [ ] Ensure we have this use case covered by tests
  • [ ] Document this use case clearly in the Readme

radeksimko avatar Mar 23 '23 09:03 radeksimko