diff --git a/lua/astrocommunity/pack/helm/README.md b/lua/astrocommunity/pack/helm/README.md new file mode 100644 index 000000000..e797eb8f4 --- /dev/null +++ b/lua/astrocommunity/pack/helm/README.md @@ -0,0 +1,7 @@ +# Helm Language Pack + +This plugin pack does the following: + +- Adds `go-template` Treesitter parsers +- Adds `helm-ls` language server +- Adds [vim-helm](https://github.com/towolf/vim-helm) for language specific tools diff --git a/lua/astrocommunity/pack/helm/init.lua b/lua/astrocommunity/pack/helm/init.lua new file mode 100644 index 000000000..b50e58f35 --- /dev/null +++ b/lua/astrocommunity/pack/helm/init.lua @@ -0,0 +1,67 @@ +local utils = require "astronvim.utils" +return { + -- Helm support + { + "nvim-treesitter/nvim-treesitter", + optional = true, + dependencies = { + { + "ngalaiko/tree-sitter-go-template", + config = function() + require("nvim-treesitter.parsers").get_parser_configs().gotmpl = { + install_info = { + url = vim.fn.stdpath "data" .. "/lazy/tree-sitter-go-template", + files = "src/parser.c", + }, + filetype = "helm", + } + end, + }, + }, + }, + { + "williamboman/mason-lspconfig.nvim", + opts = function(_, opts) + opts.ensure_installed = utils.list_insert_unique(opts.ensure_installed, "helm_ls") + + local configs = require "lspconfig.configs" + local lspconfig = require "lspconfig" + local util = require "lspconfig.util" + + if not configs.helm_ls then + configs.helm_ls = { + default_config = { + cmd = { "helm_ls", "serve" }, + filetypes = { "helm" }, + root_dir = function(fname) return util.root_pattern "Chart.yaml"(fname) end, + }, + } + end + + lspconfig.helm_ls.setup { + filetypes = { "helm" }, + cmd = { "helm_ls", "serve" }, + } + end, + }, + { + "towolf/vim-helm", + init = function() + local function helm_ft(path, _) + -- check if file is in templates folder or is helmfile + local path_regex = vim.regex "/templates/*\\.(tpl|yaml)$|*.gotmpl|helmfile*.yaml" + if path_regex and path_regex:match_str(path) then return "helm" end + + -- return yaml if nothing else + return "yaml" + end + + vim.filetype.add { + extension = { + yaml = helm_ft, + }, + } + end, + ft = "helm", + }, +}