tree-sitter-grammars / tree-sitter-hcl

HCL grammar for tree-sitter
https://tree-sitter-grammars.github.io/tree-sitter-hcl/
Apache License 2.0
92 stars 20 forks source link

Detect .nomad files as filetypes to parse #25

Closed tommyalatalo closed 1 year ago

tommyalatalo commented 2 years ago

Hashicorp's Nomad orchestrator commonly uses the filetype .nomad for its files. While the file extension is named differently, these files are in fact HCL files, and it would be great if this plugin detected and parsed .nomad files as well, which it doesn't seem to do now. I think this has already been done for .tf terraform files in this plugin, I get syntax highlighting for those. .tf files are in the exact same position as .nomad files - not named .hcl, but the contents are always HCL.

MichaHoffmann commented 2 years ago

Hey, this (detection and configuration) is usually handled by the editor. Are you using neovim by chance?

tommyalatalo commented 2 years ago

Yes, neovim is what I'm running

MichaHoffmann commented 2 years ago

Ok then we could probably create a PR to neovim-treesitter to add nomad to https://github.com/nvim-treesitter/nvim-treesitter/blob/d642de92f700c74613977fe6697fb42b299177c9/lua/nvim-treesitter/parsers.lua#L4. That should suffice i think! If not then we would need to set the filetype for .nomad files too. I can try to create a PR over the weekend! One problem could be that the queries are geared to terraform currently but that may be acceptable for now.

MichaHoffmann commented 1 year ago

You can solve this by following this https://neovim.io/doc/user/filetype.html#new-filetype and adding

au BufRead,BufNewFile *.nomad                set filetype=hcl

to your ~/.config/nvim/ftdetect file