Closed rafi closed 1 year ago
I am trying to figure out the same thing currently, I have the autocomplete working for the Kubernetes yaml file but the helm charts blow up the LSP diagnostics. Is neovim able to tell a helm file from a regular yaml file? If so what do I need for that part? This reddit post here has the same direction but I dont know how you get a helm filetype. helm charts neovim
I also found kubelinter Thank you.
My hacky solution to detach the yamlls
from helm
templates.
local function detach_yamlls()
local clients = vim.lsp.get_active_clients()
for client_id, client in pairs(clients) do
if client.name == "yamlls" then
vim.lsp.buf_detach_client(0, client_id)
end
end
end
local gotmpl_group = vim.api.nvim_create_augroup("_gotmpl", { clear = true })
vim.api.nvim_create_autocmd("FileType", {
group = gotmpl_group,
pattern = "yaml",
callback = function()
vim.schedule(function()
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
for _, line in ipairs(lines) do
if string.match(line, "{{.+}}") then
vim.defer_fn(detach_yamlls, 500)
return
end
end
end)
end,
})
The main idea here is to do a quick pattern check on the yaml file, {{.+}}
. If the pattern match is true then we wait an arbitrary amount of time (500 ms seems to work well for me) and detach the yamlls
from the buffer.
There was this suggestion on reddit from u/jemag
if vim.bo[bufnr].buftype ~= "" or vim.bo[bufnr].filetype == "helm" then
vim.diagnostic.disable(bufnr)
vim.defer_fn(function()
vim.diagnostic.reset(nil, bufnr)
end, 1000)
end
My hacky solution to detach the
yamlls
fromhelm
templates.local function detach_yamlls() local clients = vim.lsp.get_active_clients() for client_id, client in pairs(clients) do if client.name == "yamlls" then vim.lsp.buf_detach_client(0, client_id) end end end local gotmpl_group = vim.api.nvim_create_augroup("_gotmpl", { clear = true }) vim.api.nvim_create_autocmd("FileType", { group = gotmpl_group, pattern = "yaml", callback = function() vim.schedule(function() local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false) for _, line in ipairs(lines) do if string.match(line, "{{.+}}") then vim.defer_fn(detach_yamlls, 500) return end end end) end, })
The main idea here is to do a quick pattern check on the yaml file,
{{.+}}
. If the pattern match is true then we wait an arbitrary amount of time (500 ms seems to work well for me) and detach theyamlls
from the buffer.
This actually worked the best for me. Thank you for sharing.
My hacky solution to detach the
yamlls
fromhelm
templates.local function detach_yamlls() local clients = vim.lsp.get_active_clients() for client_id, client in pairs(clients) do if client.name == "yamlls" then vim.lsp.buf_detach_client(0, client_id) end end end local gotmpl_group = vim.api.nvim_create_augroup("_gotmpl", { clear = true }) vim.api.nvim_create_autocmd("FileType", { group = gotmpl_group, pattern = "yaml", callback = function() vim.schedule(function() local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false) for _, line in ipairs(lines) do if string.match(line, "{{.+}}") then vim.defer_fn(detach_yamlls, 500) return end end end) end, })
The main idea here is to do a quick pattern check on the yaml file,
{{.+}}
. If the pattern match is true then we wait an arbitrary amount of time (500 ms seems to work well for me) and detach theyamlls
from the buffer.
In case syntax is not working for you, I had to do the following:
if client.name == "yamlls" then
vim.lsp.buf_detach_client(0, client_id)
vim.cmd "set syntax=helm"
end
In case anyone is using nvim-lua/kickstart I was able to solve this issue by setting the ft
property in the plugin declaration:
require('lazy').setup({
...
{
'towolf/vim-helm',
ft = 'helm',
},
...
}, {})
I'm not sure why this works, can someone explain it?
Helm files are handled as YAML and produces much LSP errors. I've got this in my on_attach function:
It's not perfect (defer_fn), the statusline still reports error summary sometimes, but it's the best I came up with. Anybody has better workarounds?