chore(neovim): improve YAML LSP related configuration

This commit is contained in:
Yorick Barbanneau 2025-01-02 10:38:16 +01:00
parent c2dc77e360
commit b70ac37321

View file

@ -1,5 +1,6 @@
local lspconfig = require('lspconfig')
local capabilities = require("cmp_nvim_lsp").default_capabilities()
require("yaml-companion").open_ui_select()
lspconfig.bashls.setup {
capabilities = capabilities,
@ -13,19 +14,65 @@ lspconfig.eslint.setup{
capabilities = capabilities,
}
lspconfig.helm_ls.setup{
capabilities = capabilities,
settings = {
['helm-ls'] = {
logLevel = "info",
valuesFiles = {
mainValuesFile = "values.yaml",
lintOverlayValuesFile = "values.lint.yaml",
additionalValuesFilesGlobPattern = "values*.yaml"
}
},
}
-- YAML variables and Helm LS (quite big!)
local schemas = {}
local kubernetes = "https://raw.githubusercontent.com/yannh/kubernetes-json-schema/refs/heads/master/v1.29.6-standalone-strict/all.json"
local flux2 = "https://raw.githubusercontent.com/fluxcd-community/flux2-schemas/refs/heads/main/all.json"
local gitlab = "https://gitlab.com/gitlab-org/gitlab/-/raw/master/app/assets/javascripts/editor/schema/ci.json"
local taskfile = "https://taskfile.dev/schema.json"
local podmonitor = "https://raw.githubusercontent.com/datreeio/CRDs-catalog/refs/heads/main/monitoring.coreos.com/podmonitor_v1.json"
local servicemonitor = "https://raw.githubusercontent.com/datreeio/CRDs-catalog/refs/heads/main/monitoring.coreos.com/servicemonitor_v1.json"
local prometheus = "https://raw.githubusercontent.com/datreeio/CRDs-catalog/refs/heads/main/monitoring.coreos.com/prometheus_v1.json"
local ingress = "https://raw.githubusercontent.com/yannh/kubernetes-json-schema/refs/heads/master/v1.30.1/ingress-networking-v1.json"
local lefthook = "https://json.schemastore.org/lefthook.json"
local github = "https://json.schemastore.org/github-workflow.json"
schemas[kubernetes] = {
"templates/*deployment.yaml",
"templates/*service.yaml",
"templates/*secret.yaml",
"templates/*configmap.yaml",
"templates/*daemonset.yaml",
"templates/*replicaset.yaml",
"templates/*persistentvolume.yaml",
"templates/*persistentvolumeclaim.yaml",
"templates/*serviceaccount.yaml",
"templates/*role.yaml",
"templates/*rolebinding.yaml",
"templates/*clusterrole.yaml",
"templates/*clusterrolebinding.yaml",
"templates/*job*.yaml",
}
schemas[podmonitor] = "templates/*podmonitor*"
schemas[servicemonitor] = "templates/*servicemonitor*"
schemas[ingress] = "templates/*ingress*"
lspconfig.helm_ls.setup {
capabilities = capabilities,
settings = {
['helm-ls'] = {
yamlls = {
enabled = true,
enabledForFilesGlob = "*.{yaml,yml}",
diagnosticsLimit = 50,
showDiagnosticsDirectly = false,
path = "yaml-language-server",
config = {
schemas = schemas,
completion = true,
hover = true,
}
}
}
}
}
-- restart LSP server avoir problems with Helm-ls
vim.api.nvim_create_autocmd("FileType", {
pattern = "helm",
command = "LspRestart",
})
lspconfig.lua_ls.setup {
capabilities = capabilities,
@ -64,18 +111,63 @@ lspconfig.tflint.setup{
capabilities = capabilities,
}
lspconfig.yamlls.setup{
-- YAML configuration (quite big!)
local cfg = require("yaml-companion").setup({
schemas = {
{ name = "Flux2", uri = flux2 },
{ name = "Gitlab", uri = gitlab },
{ name = "Taskfile", uri = taskfile },
{ name = "PodMonitor", uri = podmonitor },
{ name = "ServiceMonitor", uri = servicemonitor },
{ name = "Prometheus", uri = prometheus },
{ name = "Kubernetes", uri = kubernetes },
{ name = "Lefthook", uri = lefthook },
},
lspconfig = {
capabilities = capabilities,
settings = {
yaml = {
schemas = {
["https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.30.0/all.json"] = {"k8s/**/*.yaml", "cluster/**/*.yaml",},
["https://taskfile.dev/schema.json"] = {"**/Taskfile.*", "**/taskfile.*",},
["https://json.schemastore.org/lefthook.json"] = {"**/lefthook.*",},
},
},
},
}
settings = {
yaml = {
schemas = {
[flux2] = {
"*.{alert,provider,receiver,helmrelease,helmrepository,gitrepository}.yaml",
"gotk-sync.yaml",
"gotk-*.yaml",
},
[gitlab] = {
"ci/*.{yaml,yml}",
".gitlab/**/*.{yaml,yml}",
".gitlab-ci.{yaml,yml}",
},
[taskfile] = {
"**/Taskfile*.{yaml,yml}",
"taskfiles/**/*.{yaml,yml}",
},
[podmonitor] = {
"*podmonitor*.{yaml,yml}"
},
[servicemonitor] = {
"*servicemonitor*.{yaml,yml}"
},
[prometheus] = {
"*prometheus*.{yaml,yml}"
},
[ingress] = {
"*ingress*.{yaml,yml}"
},
[lefthook] = {
"**/lefthook.*"
},
[github] = {
".github/workflow/**/*.{yaml,yml}"
}
},
},
},
},
})
lspconfig.yamlls.setup{cfg}
vim.api.nvim_create_autocmd('LspAttach', {
desc = 'LSP actions',