zed icon indicating copy to clipboard operation
zed copied to clipboard

Add Terraform & HCL syntax highlighting

Open caius opened this issue 1 year ago • 11 comments

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.)

Screenshot 2024-01-31 at 18 07 45

Release Notes:

  • (|Improved) ... (#5098).

caius avatar Jan 27 '24 17:01 caius

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[bot] avatar Jan 27 '24 17:01 cla-bot[bot]

@cla-bot check

caius avatar Jan 27 '24 17:01 caius

The cla-bot has been summoned, and re-checked this pull request!

cla-bot[bot] avatar Jan 27 '24 17:01 cla-bot[bot]

@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.

fdionisi avatar Jan 27 '24 20:01 fdionisi

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.

SomeoneToIgnore avatar Jan 29 '24 11:01 SomeoneToIgnore

@fdionisi sounds good to me, my rust isn't that strong. Shall we take this to email to coordinate? [email protected].

caius avatar Jan 29 '24 11:01 caius

Sent you an email already 😃

fdionisi avatar Jan 29 '24 12:01 fdionisi

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.

JosephTLyons avatar Jan 30 '24 02:01 JosephTLyons

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 ✌🏻)

caius avatar Jan 30 '24 16:01 caius

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 avatar Jan 31 '24 10:01 romans-ovo

@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!

caius avatar Jan 31 '24 12:01 caius

Nice work! This will ship in Zed 0.122.

maxbrunsfeld avatar Feb 05 '24 19:02 maxbrunsfeld