zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
48.6k stars 2.9k forks source link

Terraform support #5098

Closed HarryET closed 7 months ago

HarryET commented 1 year ago

Check for existing issues

Is your feature request related to a problem?

Missing support for Terraform/HCL

Describe the solution you'd like

Add support for terraform-ls so that we can have syntax highlighting and auto-complete for terraform configurations

If applicable, add mockups / screenshots to help present your vision of the feature

N/a

mikayla-maki commented 1 year ago

Tree sitter: https://github.com/MichaHoffmann/tree-sitter-hcl

fdionisi commented 1 year ago

No pressure, but having this would allow me to jump into some hardcore mob programming with my current team. 😬

JosephTLyons commented 1 year ago

Hey @fdionisi, no promises, but we're currently expecting to add HCL in the rather-near future.

maxdec commented 1 year ago

Any news about this? :) I'd love to use Zed for all my Terraform repositories! 😊

nikolay commented 1 year ago

Any news, @JosephTLyons?

bxker commented 10 months ago

@JosephTLyons Bumping this up as well, this would be a welcomed feature for all of us DevOps/SRE folks 👍

cjfinnell commented 10 months ago

Would love to see this as well!

ivan-kiselev commented 10 months ago

Terraform is nearly the only reason I am jumping back to vscode occasionally

caius commented 10 months ago

Not wanting this to just be a +1 comment, so can I add HCL covers more than just Terraform too. Packer & Nomad also use HCL in their configuration. GitHub Copilot is mostly good enough in Zed for completion purposes writing HCL, but the lack of highlighting/indentation support is slightly annoying.

Edit: and GitHub's State of Open Source 2023 edition shows HCL sits just below Go in popularity on their platform. 🙃

caius commented 9 months ago

I've worked around this temporarily by selecting Scheme as my syntax when editing Terraform / HCL files, and as I don't edit Scheme files normally then overridden my settings to get formatting-on-save working as I'd expect with this in my Zed settings:

{
  "language_overrides": {
    "Scheme": {
      "formatter": {
        "external": {
          "command": "terraform",
          "arguments": ["fmt", "-"]
        }
      }
    }
  }
}
francisceril commented 9 months ago

Still waiting ...

AMaliutsin commented 8 months ago

Still waiting ...

caius commented 8 months ago

@AMaliutsin @francisceril not sure if you’ve seen but the repo is open source now, makes it easier to open a Pull Request to push this forward rather than waiting?

dbanck commented 8 months ago

If no one else is working on it, I'll be happy to try implementing it next week.

wadhah101 commented 8 months ago

I love how fast and clean zed is, the only reason i go back to vscode is terraform. Does anyone know a way how to make tf files open as Scheme by default ?

caius commented 8 months ago

If no one else is working on it, I'll be happy to try implementing it next week.

I started spiking it out last night, got some highlighting working but haven't gotten the LSP wired up correctly yet. Errors when invoked with a oneshot cancelled error. Couldn't find any scheme files in the tree-sitter-hcl repo so copied them from https://github.com/nvim-treesitter/nvim-treesitter/tree/master/queries/terraform for now.

https://github.com/zed-industries/zed/compare/main...caius:zed:cd/lang-terraform

JosephTLyons commented 8 months ago

Feel free to coordinate and work on it if you like, we'll pull terraform in directly if a PR emerges :)

Abdelwaheb-Hnaien commented 8 months ago

Any news about HCL syntaxe support ? Zed is really fantastic !

bxker commented 8 months ago

-- Update --

Looks like @caius is working on this one! https://github.com/zed-industries/zed/pull/6882

Thanks @caius!

romans-ovo commented 8 months ago

Syntax is due to be deployed in 122.

Still missing Language Server support: https://github.com/zed-industries/zed/blob/main/crates/zed/src/languages.rs#L325

JosephTLyons commented 8 months ago

Syntax highlighting landed in preview today: v0.121.1-pre.

0xDones commented 7 months ago

This worked for me after Syntax highlighting for Terraform was added:

settings.json

  "languages": {
    "Terraform": {
      "formatter": {
        "external": {
          "command": "terraform",
          "arguments": [
            "fmt",
            "-"
          ]
        }
      }
    }
  }
chinyongcy commented 5 months ago

any idea when will the formatting works with .hcl files? Have just tried, it works with .tf file as mentioned above.

Day 0 of trying to use Zed.

  1. Installed terraform pluging image
  2. My settings.json looks like this image

As mentioned by here https://github.com/zed-industries/zed/blob/main/docs/src/languages/terraform.md

dbanck commented 5 months ago

@chinyongcy What kind of HCL do you write? Packer files for example?

Unlike some other formats like JSON and YAML, HCL was designed as a toolkit for building languages rather than as a language in itself, so there's a lot more application-level interpretation involved than you might be used to with other grammars. That's why formatting is usually done by specific applications rather than by a product-agnostic formatter.

The Terraform plugin/language server is only equipped to format Terraform files and won't format generic HCL. Many tools provide application-specific formatters, such as packer fmt or vault policy fmt. Depending on the type of HCL you're writing, I hope you can find something similar.

avtar commented 5 months ago

What kind of HCL do you write?

Terragrunt and its use of HCL is quite common when working with Terraform.

stv-io commented 5 months ago

@avtar terragrunt hclfmt - https://terragrunt.gruntwork.io/docs/getting-started/configuration/#formatting-hcl-files

chinyongcy commented 5 months ago

@chinyongcy What kind of HCL do you write? Packer files for example?

Unlike some other formats like JSON and YAML, HCL was designed as a toolkit for building languages rather than as a language in itself, so there's a lot more application-level interpretation involved than you might be used to with other grammars. That's why formatting is usually done by specific applications rather than by a product-agnostic formatter.

The Terraform plugin/language server is only equipped to format Terraform files and won't format generic HCL. Many tools provide application-specific formatters, such as packer fmt or vault policy fmt. Depending on the type of HCL you're writing, I hope you can find something similar.

terragrunt hcl, new to zed, i tried doing this based on some of the reply above for terraform, and try doing it for terragrunt.

image

but every time when I save my hcl, it clears the file.

Current solution what I have done

  1. Clone this https://github.com/hashicorp/hcl/tree/main/cmd/hclfmt
  2. Go into cmd/hclfmt and then run go build
  3. Shift the hclfmt to /usr/local/bin/ and then chmod +x it

and then this is what I have used for settings.json

image

one caveat it is only able to do formatting after I save the file without formatting. However, once i make some changes and edit, and i click save straight away, whatever changes that was there will be lost.

pretty sure that is still something wrong in my setting.json. It is almost perfect now.

begemotik commented 4 months ago

The tricky part to make the formatter work is to make sure the terragrunt hclfmt command outputs the file to stdout. Following the recommendation here adjusted inline formatter as following and should admit that it works as a charm:

"HCL": {
      // Workarond to be able to format_on_save terragrunt files
      // https://github.com/gruntwork-io/terragrunt/issues/1037#issuecomment-2143442454
      "format_on_save": {
        "external": {
          "command": "sh",
          "arguments": [
            "-c",
            "TMPFILE=$(mktemp) && cat - > $TMPFILE && terragrunt hclfmt --terragrunt-hclfmt-file $TMPFILE && cat $TMPFILE && rm $TMPFILE"
          ]
        }
      }
ChzenChzen commented 3 months ago

How can I rename variables affecting all occurrences throughout the code?