zed
zed copied to clipboard
Add Terraform & HCL syntax highlighting
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.)
Release Notes:
- (|Improved) ... (#5098).
We require contributors to sign our Contributor License Agreement, and we don't have @caius on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.
@cla-bot check
The cla-bot has been summoned, and re-checked this pull request!
@caius I have an initial implementation for the lsp on a branch - if you'd like we could pair one of these days and finish it off.
This looks close to be done, so it would be great to add a new docs entry to the https://github.com/zed-industries/zed/tree/main/docs/src/languages list before merging.
@fdionisi sounds good to me, my rust isn't that strong. Shall we take this to email to coordinate? [email protected].
Sent you an email already 😃
Unless you've already started on the work on this branch, I think we could merge in the tree sitter portion of this and let the language server portion be a new PR.
Unless you've already started on the work on this branch, I think we could merge in the tree sitter portion of this and let the language server portion be a new PR.
Good point @JosephTLyons, have marked this as ready for review to get the syntax highlighting shipped.
(I spy @fdionisi has :+1:'d you. We can open a second PR for shipping the LSP ✌🏻)
This branch uses default indent of 4, while terraform typically uses 2 as ident. Not sure if this is a relevant comment (my first one here).
also - cmd+/ commenting does not work.
@romans-ovo well spotted, looks like e9edad1d51 changed from line_comment to line_comments in the language's Config.toml. Updated in 355fcc9 so it works again.
I hadn't noticed the indentation because my Zed is configured to have all languages at two spaces 😬 Changed that in the default settings.json now too.
Thanks for the comment!
Nice work! This will ship in Zed 0.122.