-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Terraform support #5098
Comments
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. |
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 |
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 ! |
Terraform and HCL are almost the same language, but not quite so proposing them as separate languages within Zed. (Terraform is an extension of HCL, with a different formatter.) This is just adding the language definition, parsing and highlighting functionality, not any LSP or formatting beyond that for either language. I've taken a bunch of inspiration from Neovim for having the separate languages, and also lifted some of their `scm` files (with attribution comments in this codebase) as the tree-sitter repo doesn't contain them. (Neovim's code is Apache-2.0 licensed, so should be fine here with attribution from reading Zed's licenses files.) I've then amended to make sure the capture groups are named for things Zed understands. I'd love someone from Zed to confirm that's okay, or if I should clean-room implement the `scm` files. Highlighting in Terraform & HCL with a moderate amount of syntax in a file (Terraform on left, HCL on right.) <img width="1392" alt="Screenshot 2024-01-31 at 18 07 45" src="https://github.com/zed-industries/zed/assets/696/1d3c9a08-588e-4b8f-ad92-98ce1e419659"> Release Notes: - (|Improved) ... ([#5098](#5098)).
Syntax is due to be deployed in 122. Still missing Language Server support: |
Syntax highlighting landed in preview today: v0.121.1-pre. |
With #6882 basic syntax highlighting support for Terraform has arrived in Zed. To fully support all features of the language server (when it lands), it's necessary to handle `*.tfvars` slightly differently. TL;DR: [terraform-ls](https://github.com/hashicorp/terraform-ls) expects `terraform` as language id for `*.tf` files and `terraform-vars` as language id for `*.tfvars` files because the allowed configuration inside the files is different. Duplicating the Terraform language configuration was the only way I could see to achieve this. --- In the [LSP](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentItem), text documents have a language identifier to identify a document on the server side to avoid reinterpreting the file extension. The Terraform language server currently uses two different language identifiers: * `terraform` - for `*.tf` files * `terraform-vars` - for `*.tfvars` files Both file types contain HCL and can be highlighted using the same grammar and tree-sitter configuration files. The difference in the file content is that `*.tfvars` files only allow top-level attributes and no blocks. [_So you could argue that `*.tfvars` can use a stripped down version of the grammar_]. To set the right context (which affects completion, hover, validation...) for each file, we need to send a different language id. The only way I could see to achieve this with the current architecture was to copy the Terraform language configuration with a different `name` and different `path_suffixes`. Everything else is the same. A Terraform LSP adapter implementation would then map the language configurations to their specific language ids: ```rust fn language_ids(&self) -> HashMap<String, String> { HashMap::from_iter([ ("Terraform".into(), "terraform".into()), ("Terraform Vars".into(), "terraform-vars".into()), ]) } ``` I think it might be helpful in the future to have another way to map file extensions to specific language ids without having to create a new language configuration. ### UX Before ![CleanShot 2024-02-07 at 23 00 56@2x](https://github.com/zed-industries/zed/assets/45985/2c40f477-99a2-4dc1-86de-221acccfcedb) ### UX After ![CleanShot 2024-02-07 at 22 58 40@2x](https://github.com/zed-industries/zed/assets/45985/704c9cca-ae14-413a-be1f-d2439ae1ae22) Release Notes: - N/A --- * Part of #5098
This worked for me after Syntax highlighting for Terraform was added: settings.json "languages": {
"Terraform": {
"formatter": {
"external": {
"command": "terraform",
"arguments": [
"fmt",
"-"
]
}
}
}
} |
* Depends on: #7449 * Closes: #5098 --- This PR adds support for downloading and running the Terraform language server for `*.tf` and `*.tfvars` files. I've verified that the code works for `aarch64` and `x86_64` macOS. Downloading new language server versions on release also works as expected. Furthermore this PR adds: - A short docs page for Terraform - An icon for `*.tf` and `*.tfvars` files ## UX ### File Icons ![CleanShot 2024-02-10 at 23 10 13@2x](https://github.com/zed-industries/zed/assets/45985/6f7cd4f0-e94c-4cfb-b3e9-64b0e33c8a43) ### Completion ![CleanShot 2024-02-13 at 20 54 15@2x](https://github.com/zed-industries/zed/assets/45985/18fafa3b-cb50-4f51-b071-ca9eee3521a6) ### Hover ![CleanShot 2024-02-13 at 20 53 40@2x](https://github.com/zed-industries/zed/assets/45985/4d215315-e019-4d3d-b23c-2691db1803e3) ### Go to definition ![2024-02-13 20 56 28](https://github.com/zed-industries/zed/assets/45985/c21d562f-eb0b-4df9-9175-c53b9923344e) ### Formatting ![2024-02-13 20 59 06](https://github.com/zed-industries/zed/assets/45985/0cdf4ec5-e231-4c8a-a257-cae30a8edc8b) and more! ## Known issue(s) @fdionisi discovered that sometimes completion results are inserted with the wrong indentation. Or rather, if you look closely, they are inserted with the correct indentation and then something shifts the closing `}`. I don't think this is related to LSP support and can be addressed in a separate PR. ![2024-02-13 20 58 16](https://github.com/zed-industries/zed/assets/45985/94a118dd-95f5-4e38-8f83-75fec7a0dddf) Release Notes: - Add language server support for Terraform ([#5098](#5098)). --------- Co-authored-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
any idea when will the formatting works with .hcl files? Day 0 of trying to use Zed.
As mentioned by here |
@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 |
Terragrunt and its use of HCL is quite common when working with Terraform. |
terragrunt hcl, new to zed, i tried doing this based on some of the reply above for terraform, and try doing it for terragrunt. Current solution what I have done
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. pretty sure that is still something wrong in my setting.json. It is almost perfect now. |
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
The text was updated successfully, but these errors were encountered: