zed
zed copied to clipboard
Terraform support
Check for existing issues
- [X] Completed
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
Tree sitter: https://github.com/MichaHoffmann/tree-sitter-hcl
No pressure, but having this would allow me to jump into some hardcore mob programming with my current team. 😬
Hey @fdionisi, no promises, but we're currently expecting to add HCL in the rather-near future.
Any news about this? :) I'd love to use Zed for all my Terraform repositories! 😊
Any news, @JosephTLyons?
@JosephTLyons Bumping this up as well, this would be a welcomed feature for all of us DevOps/SRE folks 👍
Would love to see this as well!
Terraform is nearly the only reason I am jumping back to vscode occasionally
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. 🙃
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", "-"]
}
}
}
}
}
Still waiting ...
Still waiting ...
@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?
If no one else is working on it, I'll be happy to try implementing it next week.
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 ?
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
Feel free to coordinate and work on it if you like, we'll pull terraform in directly if a PR emerges :)
Any news about HCL syntaxe support ? Zed is really fantastic !
-- Update --
Looks like @caius is working on this one! https://github.com/zed-industries/zed/pull/6882
Thanks @caius!
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
Syntax highlighting landed in preview today: v0.121.1-pre.
This worked for me after Syntax highlighting for Terraform was added:
settings.json
"languages": {
"Terraform": {
"formatter": {
"external": {
"command": "terraform",
"arguments": [
"fmt",
"-"
]
}
}
}
}
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.
- Installed terraform pluging
- My settings.json looks like this
As mentioned by here https://github.com/zed-industries/zed/blob/main/docs/src/languages/terraform.md
@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.
What kind of HCL do you write?
Terragrunt and its use of HCL is quite common when working with Terraform.
@avtar terragrunt hclfmt
- https://terragrunt.gruntwork.io/docs/getting-started/configuration/#formatting-hcl-files
@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
orvault 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.
but every time when I save my hcl, it clears the file.
Current solution what I have done
- Clone this https://github.com/hashicorp/hcl/tree/main/cmd/hclfmt
- Go into cmd/hclfmt and then run
go build
- Shift the hclfmt to /usr/local/bin/ and then chmod +x it
and then this is what I have used for settings.json
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.
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"
]
}
}
How can I rename variables affecting all occurrences throughout the code?