From b84e46bda1d9671b7b0589e42c522a6a5cd02397 Mon Sep 17 00:00:00 2001 From: Tomas Mirchev Date: Sat, 31 Jan 2026 05:30:42 +0200 Subject: [PATCH] add helm lsp --- init.lua | 6 +++ lsp/helm_ls.lua | 25 +++++++++++ lsp/yamlls.lua | 80 ++++++++++++++++++++++++++++++++++ lua/modules/language-specs.lua | 19 ++++++++ 4 files changed, 130 insertions(+) create mode 100644 lsp/helm_ls.lua create mode 100644 lsp/yamlls.lua diff --git a/init.lua b/init.lua index 6ca8ece..b12d6e1 100644 --- a/init.lua +++ b/init.lua @@ -5,6 +5,12 @@ end vim.env.PATH = vim.fn.stdpath('data') .. '/mason/bin:' .. vim.env.PATH +vim.filetype.add({ + pattern = { + ['.*/templates/.*%.ya?ml'] = 'yaml.helm-values', + }, +}) + require('core.options') require('core.keymaps') require('core.events') diff --git a/lsp/helm_ls.lua b/lsp/helm_ls.lua new file mode 100644 index 0000000..a2deb89 --- /dev/null +++ b/lsp/helm_ls.lua @@ -0,0 +1,25 @@ +---@brief +--- +--- https://github.com/mrjosh/helm-ls +--- +--- Helm Language server. (This LSP is in early development) +--- +--- `helm Language server` can be installed by following the instructions [here](https://github.com/mrjosh/helm-ls). +--- +--- The default `cmd` assumes that the `helm_ls` binary can be found in `$PATH`. +--- +--- If need Helm file highlight use [vim-helm](https://github.com/towolf/vim-helm) plugin. + +---@type vim.lsp.Config +return { + cmd = { 'helm_ls', 'serve' }, + filetypes = { 'helm', 'yaml.helm-values' }, + root_markers = { 'Chart.yaml' }, + capabilities = { + workspace = { + didChangeWatchedFiles = { + dynamicRegistration = true, + }, + }, + }, +} diff --git a/lsp/yamlls.lua b/lsp/yamlls.lua new file mode 100644 index 0000000..9a3b8c4 --- /dev/null +++ b/lsp/yamlls.lua @@ -0,0 +1,80 @@ +---@brief +--- +--- https://github.com/redhat-developer/yaml-language-server +--- +--- `yaml-language-server` can be installed via `yarn`: +--- ```sh +--- yarn global add yaml-language-server +--- ``` +--- +--- To use a schema for validation, there are two options: +--- +--- 1. Add a modeline to the file. A modeline is a comment of the form: +--- +--- ``` +--- # yaml-language-server: $schema= +--- ``` +--- +--- where the relative filepath is the path relative to the open yaml file, and the absolute filepath +--- is the filepath relative to the filesystem root ('/' on unix systems) +--- +--- 2. Associated a schema url, relative , or absolute (to root of project, not to filesystem root) path to +--- the a glob pattern relative to the detected project root. Check `:checkhealth vim.lsp` to determine the resolved project +--- root. +--- +--- ```lua +--- vim.lsp.config('yamlls', { +--- ... +--- settings = { +--- yaml = { +--- ... -- other settings. note this overrides the lspconfig defaults. +--- schemas = { +--- ["https://json.schemastore.org/github-workflow.json"] = "/.github/workflows/*", +--- ["../path/relative/to/file.yml"] = "/.github/workflows/*", +--- ["/path/from/root/of/project"] = "/.github/workflows/*", +--- }, +--- }, +--- } +--- }) +--- ``` +--- +--- Currently, kubernetes is special-cased in yammls, see the following upstream issues: +--- * [#211](https://github.com/redhat-developer/yaml-language-server/issues/211). +--- * [#307](https://github.com/redhat-developer/yaml-language-server/issues/307). +--- +--- To override a schema to use a specific k8s schema version (for example, to use 1.18): +--- +--- ```lua +--- vim.lsp.config('yamlls', { +--- ... +--- settings = { +--- yaml = { +--- ... -- other settings. note this overrides the lspconfig defaults. +--- schemas = { +--- ["https://raw.githubusercontent.com/yannh/kubernetes-json-schema/refs/heads/master/v1.32.1-standalone-strict/all.json"] = "/*.k8s.yaml", +--- ... -- other schemas +--- }, +--- }, +--- } +--- }) +--- ``` + +---@type vim.lsp.Config +return { + cmd = { 'yaml-language-server', '--stdio' }, + filetypes = { 'helm', 'yaml', 'yaml.docker-compose', 'yaml.gitlab', 'yaml.helm-values' }, + root_markers = { '.git' }, + settings = { + -- https://github.com/redhat-developer/vscode-redhat-telemetry#how-to-disable-telemetry-reporting + redhat = { telemetry = { enabled = false } }, + -- formatting disabled by default in yaml-language-server; enable it + yaml = { format = { enable = true } }, + }, + on_init = function(client) + --- https://github.com/neovim/nvim-lspconfig/pull/4016 + --- Since formatting is disabled by default if you check `client:supports_method('textDocument/formatting')` + --- during `LspAttach` it will return `false`. This hack sets the capability to `true` to facilitate + --- autocmd's which check this capability + client.server_capabilities.documentFormattingProvider = true + end, +} diff --git a/lua/modules/language-specs.lua b/lua/modules/language-specs.lua index 54d2f14..1f312a1 100644 --- a/lua/modules/language-specs.lua +++ b/lua/modules/language-specs.lua @@ -1,7 +1,26 @@ local M = {} +-- vim.filetype.add({ +-- pattern = { +-- ['.*/templates/.*%.ya?ml'] = 'yaml.helm-values', +-- ['.*/templates/.*%.tpl'] = 'yaml.helm-values', +-- }, +-- }) + +-- vim.api.nvim_create_autocmd({ 'BufNewFile', 'BufRead' }, { +-- pattern = '**/templates/**/*.y?ml', +-- callback = function() +-- vim.bo.filetype = 'yaml.helm-values' +-- end, +-- }) +-- function M.get() return { + { + ft = 'yaml.helm-values', + ts = 'helm', + lsp = 'helm-ls', + }, { ft = 'yaml', ts = 'yaml',