extensions icon indicating copy to clipboard operation
extensions copied to clipboard

Add Helm extension

Open cabrinha opened this issue 1 year ago • 13 comments

Support for https://helm.sh

cabrinha avatar Apr 04 '24 15:04 cabrinha

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)

maxdeviant avatar Apr 08 '24 14:04 maxdeviant

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

maxbrunsfeld avatar Apr 08 '24 19:04 maxbrunsfeld

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.

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.

cabrinha avatar Apr 09 '24 04:04 cabrinha

That would only be needed if there is a Helm language server.

maxbrunsfeld avatar Apr 09 '24 06:04 maxbrunsfeld

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

cabrinha avatar Apr 09 '24 15:04 cabrinha

Thanks for the help so far, let me know if there are any other changes I need to make to get this working.

cabrinha avatar Apr 09 '24 15:04 cabrinha

The Cargo.toml is only needed if you're providing Rust code to configure a language server.

maxbrunsfeld avatar Apr 09 '24 15:04 maxbrunsfeld

The Cargo.toml is only needed if you're providing Rust code to configure a language server.

Ok, it has been removed.

cabrinha avatar Apr 09 '24 16:04 cabrinha

Updated the submodule and confirmed it uses underscores now.

CI keeps failing, weird.

cabrinha avatar Apr 09 '24 16:04 cabrinha

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

maxbrunsfeld avatar Apr 15 '24 17:04 maxbrunsfeld

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

Looks like it's now failing on: https://github.com/cabrinha/helm.zed/blob/master/languages/gotmpl/injections.scm#L1

cabrinha avatar Apr 16 '24 02:04 cabrinha

Yeah, apparently yaml_command is not a node in the grammar. Where did that injection query come from?

maxbrunsfeld avatar Apr 17 '24 01:04 maxbrunsfeld

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.

cabrinha avatar Apr 17 '24 01:04 cabrinha

Yeah, apparently yaml_command is 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

cabrinha avatar May 15 '24 17:05 cabrinha

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?

cabrinha avatar May 16 '24 20:05 cabrinha

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

mikayla-maki avatar May 16 '24 21:05 mikayla-maki

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

qvalentin avatar May 17 '24 17:05 qvalentin