vscode-terraform icon indicating copy to clipboard operation
vscode-terraform copied to clipboard

Support files with embedded Terraform syntax (e.g. Markdown or ERB)

Open paultyng opened this issue 4 years ago • 1 comments

Background

Both LSP and VS Code mostly make the assumption that each file has a single language and based on that language it decides whether to

  • highlight the file using a particular grammar
  • send the file to the language server, to provide IntelliSense (e.g. completion or hover) for it

There are files which may embed Terraform syntax in some ways, e.g.

  • Markdown via code blocks such as ```terraform
  • ERB - e.g. Terraspace templating Terraform configs

There also reverse examples, where syntax of other languages is embedded within Terraform, e.g. YAML or JSON

  content=<<-YAML
    apiVersion: policy/v1
    kind: PodDisruptionBudget
    metadata:
      name: ${var.name}
    spec:
      minAvailable: 2
      selector:
        matchLabels:
          app: ${var.app}
  YAML
policy = <<JSON
{"valid_policy": "json"}
JSON

LSP

See https://github.com/hashicorp/terraform-ls/issues/633 for more

https://github.com/microsoft/language-server-protocol/issues/1252 has possibly most context, including links to some workarounds.

Syntax Highlighting

See https://github.com/hashicorp/vscode-terraform/issues/328 for more

Related to #225, the implementation could be something like:

{
  "scopeName": "text.markdown.terraform.codeblock-terraform",
  "path": "./syntaxes/terraform.tmGrammar.json",
  "injectTo": [
    "text.html.markdown"
  ]
}

Proposal

TODO

paultyng avatar Jun 18 '20 14:06 paultyng

To clarify, the desired behavior here is that markdown files that contain Terraform code should receive syntax highlighting. They key challenges are (a) how to avoid claiming markdown and breaking other markdown highlighting, and (b) how to pass these files and have them processed correctly by the language server. There's an open question about whether the language server needs to be involved here.

It's also possible this could be handled in VSCode's existing markdown embedded syntax highlighting - this is a research question

danieldreier avatar May 24 '21 16:05 danieldreier