Skip to content

Commit

Permalink
feat(nvim): enable helm files editing
Browse files Browse the repository at this point in the history
Disable yaml diagnostic for 'helm' files based on this Reddit thread
https://www.reddit.com/r/neovim/comments/sqr6r5/helm_charts_for_kubernetes_in_nvim_bad_experience/

And detect helm files according to
https://www.reddit.com/r/neovim/comments/12ub997/how_to_prevent_yaml_ls_from_attaching_to_helm/

Also add vim-helm (https://github.com/towolf/vim-helm) plugin for
syntax highlighting.
  • Loading branch information
beiertu-mms committed Oct 5, 2023
1 parent 38c7b9d commit 6a9a316
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .config/nvim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,24 @@ require('lazy').setup('plugins', lazy_config)
require('core.options')
require('core.keymaps')
require('core.autocmds')

--[[
-- Change file types to helm if a 'Chart.yaml' file is found
--]]
local isHelmfile = function(path)
local check = vim.fs.find('Chart.yaml', { path = vim.fs.dirname(path), upward = true })
return not vim.tbl_isempty(check)
end

vim.filetype.add({
extension = {
yaml = isHelmfile and 'helm' or 'yaml',
yml = isHelmfile and 'helm' or 'yaml',
tmpl = isHelmfile and 'helm' or 'tmpl',
tpl = isHelmfile and 'helm' or 'tpl',
},
filename = {
['Chart.yaml'] = 'yaml',
['Chart.lock'] = 'yaml',
},
})
8 changes: 8 additions & 0 deletions .config/nvim/lua/plugins/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ return {

nmap('K', vim.lsp.buf.hover, 'Hover Documentation') -- See `:help K` for why this keymap
nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation')

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

-- https://github.com/williamboman/mason-lspconfig.nvim#available-lsp-servers
Expand All @@ -52,6 +59,7 @@ return {
'diagnosticls',
'dockerls',
'gopls',
'helm-ls',
'html',
'jsonls',
'lua_ls',
Expand Down
4 changes: 4 additions & 0 deletions .config/nvim/lua/plugins/vimhelm.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
return {
'towolf/vim-helm', -- https://github.com/towolf/vim-helm
lazy = false,
}

0 comments on commit 6a9a316

Please sign in to comment.