Add Helm extension
Support for https://helm.sh
It looks like there are still some problems when trying to compile the go-template grammar to Wasm:
[2024-04-07T12:09:22Z INFO extension::extension_builder] compiling go-template parser
Error: failed to compile extension
Caused by:
0: failed to compile grammar 'go-template'
1: failed to compile go-template parser with clang: wasm-ld: warning: creating shared libraries, with -shared, is not yet stable
wasm-ld: error: symbol exported via --export not found: tree_sitter_go-template
clang: error: linker command failed with exit code 1 (use -v to see invocation)
wasm-ld: error: symbol exported via --export not found: tree_sitter_go-template
The function is probably called go_template (with an underscore, not a dash), so that needs to the name of the grammar. @cabrinha I think that means we need to change the directory name from grammars/go-template to grammars/go_template.
Also, since this is a new extension, it'd be good to be using the latest extension schema and API. Could you copy the structure of the extensions in here? https://github.com/zed-industries/zed/tree/main/extensions
wasm-ld: error: symbol exported via --export not found: tree_sitter_go-templateThe function is probably called
go_template(with an underscore, not a dash), so that needs to the name of the grammar. @cabrinha I think that means we need to change the directory name fromgrammars/go-templatetogrammars/go_template.
Alright, I think I can do that by forking the other repo...
Also, since this is a new extension, it'd be good to be using the latest extension schema and API. Could you copy the structure of the extensions in here? https://github.com/zed-industries/zed/tree/main/extensions
Do I need to create a helm.rs file inside of a src directory in my own helm.zed repo? I'm not sure what to populate helm.rs file with.
That would only be needed if there is a Helm language server.
That would only be needed if there is a Helm language server.
Ok, here are the changes I've made to the extension: https://github.com/hjoshi123/helm.zed/pull/1/files
Thanks for the help so far, let me know if there are any other changes I need to make to get this working.
The Cargo.toml is only needed if you're providing Rust code to configure a language server.
The
Cargo.tomlis only needed if you're providing Rust code to configure a language server.
Ok, it has been removed.
Updated the submodule and confirmed it uses underscores now.
CI keeps failing, weird.
It looks like the grammar actually is called gotmpl (not go_template): https://github.com/ngalaiko/tree-sitter-go-template/blob/master/grammar.js#L3
It looks like the grammar actually is called
gotmpl(notgo_template): https://github.com/ngalaiko/tree-sitter-go-template/blob/master/grammar.js#L3
Looks like it's now failing on: https://github.com/cabrinha/helm.zed/blob/master/languages/gotmpl/injections.scm#L1
Yeah, apparently yaml_command is not a node in the grammar. Where did that injection query come from?
Not sure, but here is the line: https://github.com/cabrinha/helm.zed/blob/master/languages/gotmpl/injections.scm#L1
Basically, Helm syntax is a combination of yaml and go-template, there is a tree sitter for both, but I don't know the proper way to combine them. I forked this repo: https://github.com/hjoshi123/helm.zed
If there is anything I can do to fix this issue, just let me know.
Yeah, apparently
yaml_commandis not a node in the grammar. Where did that injection query come from?
Interesting note in the README from the go-template tree-sitter: Note that yaml is listed under used_by. I've set this to highlight helm templates as Go Templates instead of yaml. To ensure that yaml highlighting is still working, you should set up language injection for gotmpl filetypes.: https://github.com/ngalaiko/tree-sitter-go-template/blob/master/README.md
Does this mean I should change yaml_command to yaml?
I've changed yaml_command to text, so I hope thats the right thing here: https://github.com/ngalaiko/tree-sitter-go-template/blob/master/dialects/helm/src/grammar.json#L24
Now, I'm wondering if this approach is correct to use the gotmpl grammar, since tree-sitter-go-template has it's own dialect and grammar for helm here: https://github.com/ngalaiko/tree-sitter-go-template/blob/master/dialects/helm/src/grammar.json
@maxbrunsfeld do you think we're still on the right track here?
Discussed in discord, author has decided to discontinue this effort, that said extension is very close, just needs to improve the association between heml and yaml. If someone else is interested in picking it up and finishing this, we'd be happy to have it :)
That would only be necessary if there was a Helm language server.
Well, there is https://github.com/mrjosh/helm-ls 😄
Perhaps I can provide some information on how helm is currently handled in Neovim:
- There is a specific file type that is set for files that match the pattern
*/templates/*.{yaml,yml},*/templates/*.tpl,*.gotmpl,helmfile*.{yaml,yml}. - The helm dialogue in the https://github.com/ngalaiko/tree-sitter-go-template repo is only used to be able to include both gotmpl and helm in https://github.com/nvim-treesitter/nvim-treesitter (currently it would not matter which grammar zed would include).
- Injections should use combined injections if possible (as discussed in https://github.com/ngalaiko/tree-sitter-go-template/pull/11), I think you were on the right track here @cabrinha