236 lines
7 KiB
Lua
236 lines
7 KiB
Lua
local lspconfig = require('lspconfig')
|
|
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
|
require("yaml-companion").open_ui_select()
|
|
|
|
lspconfig.bashls.setup {
|
|
capabilities = capabilities,
|
|
}
|
|
|
|
lspconfig.clangd.setup {
|
|
capabilities = capabilities,
|
|
}
|
|
|
|
lspconfig.eslint.setup{
|
|
capabilities = capabilities,
|
|
}
|
|
|
|
-- 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,
|
|
single_file_support = true,
|
|
settings = {
|
|
Lua = {
|
|
diagnostics = {
|
|
globals = {'vim'} -- Add any globals you want to ignore as undefined
|
|
},
|
|
workspace = {
|
|
library = {
|
|
[vim.fn.expand('$VIMRUNTIME/lua')] = true
|
|
}
|
|
},
|
|
telemetry = {
|
|
enable = false -- Disable telemetry
|
|
}
|
|
}
|
|
},
|
|
flags = {
|
|
debounce_text_changes = 150,
|
|
}
|
|
}
|
|
|
|
lspconfig.marksman.setup{
|
|
capabilities = capabilities,
|
|
}
|
|
|
|
lspconfig.nil_ls.setup {
|
|
capabilities = capabilities,
|
|
}
|
|
|
|
lspconfig.pylsp.setup {
|
|
capabilities = capabilities,
|
|
settings = {
|
|
pylsp = {
|
|
plugins = {
|
|
pylint = {
|
|
enabled = true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
lspconfig.terraformls.setup{
|
|
capabilities = capabilities,
|
|
}
|
|
|
|
lspconfig.tflint.setup{
|
|
capabilities = capabilities,
|
|
}
|
|
|
|
-- 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 = {
|
|
[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',
|
|
callback = function(ev)
|
|
local bufmap = function(mode, lhs, rhs)
|
|
local opts = {buffer = true}
|
|
vim.keymap.set(mode, lhs, rhs, opts)
|
|
end
|
|
|
|
-- Displays hover information about the symbol under the cursor
|
|
bufmap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>')
|
|
|
|
-- Jump to the definition
|
|
bufmap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>')
|
|
|
|
-- Jump to declaration
|
|
bufmap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>')
|
|
|
|
-- Lists all the implementations for the symbol under the cursor
|
|
bufmap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<cr>')
|
|
|
|
-- Jumps to the definition of the type symbol
|
|
bufmap('n', 'go', '<cmd>lua vim.lsp.buf.type_definition()<cr>')
|
|
|
|
-- Lists all the references
|
|
bufmap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<cr>')
|
|
|
|
-- Displays a function's signature information
|
|
bufmap('n', 'gs', '<cmd>lua vim.lsp.buf.signature_help()<cr>')
|
|
|
|
-- Renames all references to the symbol under the cursor
|
|
bufmap('n', '<F2>', '<cmd>lua vim.lsp.buf.rename()<cr>')
|
|
|
|
-- Selects a code action available at the current cursor position
|
|
bufmap('n', '<F4>', '<cmd>lua vim.lsp.buf.code_action()<cr>')
|
|
bufmap('x', '<F4>', '<cmd>lua vim.lsp.buf.range_code_action()<cr>')
|
|
|
|
-- Show diagnostics in a floating window
|
|
bufmap('n', 'gl', '<cmd>lua vim.diagnostic.open_float()<cr>')
|
|
|
|
-- Move to the previous diagnostic
|
|
bufmap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<cr>')
|
|
|
|
-- Move to the next diagnostic
|
|
bufmap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<cr>')
|
|
local client = vim.lsp.get_client_by_id(ev.data.client_id)
|
|
if client and (client.name == "yamlls" or client.name == "helm_ls") then
|
|
bufmap ('n', '<F3>', '<cmd>lua require("yaml-companion").open_ui_select()<cr>')
|
|
end
|
|
end
|
|
})
|