Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
paultyng opened this issue Jun 18, 2020 · 1 comment
Open

Comments

@paultyng
Copy link
Contributor

paultyng commented Jun 18, 2020

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 hashicorp/terraform-ls#633 for more

microsoft/language-server-protocol#1252 has possibly most context, including links to some workarounds.

Syntax Highlighting

See #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 paultyng changed the title Add back the ability to inject Terraform syntax to markdown code blocks Add ability to inject Terraform syntax to markdown code blocks Jun 18, 2020
@paultyng paultyng added enhancement New feature or request syntax labels Jun 18, 2020
@danieldreier
Copy link

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

@radeksimko radeksimko changed the title Add ability to inject Terraform syntax to markdown code blocks Support files with embedded Terraform syntax (e.g. Markdown or ERB) Apr 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants