aboutsummaryrefslogtreecommitdiffstats
path: root/neovim/.config/nvim
diff options
context:
space:
mode:
authorGravatar Tom van der Lee <t0m.vd.l33@gmail.com>2026-09-29 12:05:18 +0200
committerGravatar Tom van der Lee <t0m.vd.l33@gmail.com>2026-09-29 12:05:18 +0200
commit2f874f8749800265142a12050c8a7e2a836dd43c (patch)
tree7dfc103b1edb5c87163794e246bdafe6825dbc41 /neovim/.config/nvim
parentb1690381850f011abad0bb3e94c03e99a9101e98 (diff)
downloaddotfiles-2f874f8749800265142a12050c8a7e2a836dd43c.tar.gz
dotfiles-2f874f8749800265142a12050c8a7e2a836dd43c.tar.bz2
dotfiles-2f874f8749800265142a12050c8a7e2a836dd43c.zip
Added k8s template functionalityHEADmaster
Diffstat (limited to 'neovim/.config/nvim')
-rw-r--r--neovim/.config/nvim/lua/plugins/lsp.lua53
1 files changed, 53 insertions, 0 deletions
diff --git a/neovim/.config/nvim/lua/plugins/lsp.lua b/neovim/.config/nvim/lua/plugins/lsp.lua
index 3106fcd..6f365a0 100644
--- a/neovim/.config/nvim/lua/plugins/lsp.lua
+++ b/neovim/.config/nvim/lua/plugins/lsp.lua
@@ -41,6 +41,59 @@ return {
41 capabilities = require("blink.cmp").get_lsp_capabilities(), 41 capabilities = require("blink.cmp").get_lsp_capabilities(),
42 }) 42 })
43 43
44 -- yamlls only completes/validates when a schema is associated with the
45 -- file, and plain k8s manifests don't match anything by filename. So we
46 -- detect manifests by content (top-level apiVersion + kind) and add each
47 -- one to yamlls's built-in "kubernetes" schema. CRDs (ArgoCD, Traefik,
48 -- cert-manager, ...) are then resolved from apiVersion/kind by yamlls's
49 -- CRD store, which is enabled by default.
50 vim.lsp.config("yamlls", {
51 settings = { yaml = { schemas = { kubernetes = {} } } },
52 })
53
54 local function is_k8s_manifest(bufnr)
55 local has_api, has_kind = false, false
56 for _, line in ipairs(vim.api.nvim_buf_get_lines(bufnr, 0, 50, false)) do
57 has_api = has_api or line:match("^apiVersion:") ~= nil
58 has_kind = has_kind or line:match("^kind:") ~= nil
59 end
60 return has_api and has_kind
61 end
62
63 local function attach_k8s_schema(client, bufnr)
64 local path = vim.api.nvim_buf_get_name(bufnr)
65 if path == "" or not is_k8s_manifest(bufnr) then
66 return
67 end
68 local k8s = client.settings.yaml.schemas.kubernetes
69 if vim.tbl_contains(k8s, path) then
70 return
71 end
72 table.insert(k8s, path)
73 client:notify("workspace/didChangeConfiguration", { settings = client.settings })
74 end
75
76 local group = vim.api.nvim_create_augroup("yamlls_kubernetes", { clear = true })
77 vim.api.nvim_create_autocmd("LspAttach", {
78 group = group,
79 callback = function(args)
80 local client = vim.lsp.get_client_by_id(args.data.client_id)
81 if client and client.name == "yamlls" then
82 attach_k8s_schema(client, args.buf)
83 end
84 end,
85 })
86 -- Also re-check on save, so a new file picks up the schema once
87 -- apiVersion/kind have been written.
88 vim.api.nvim_create_autocmd("BufWritePost", {
89 group = group,
90 callback = function(args)
91 for _, client in ipairs(vim.lsp.get_clients({ bufnr = args.buf, name = "yamlls" })) do
92 attach_k8s_schema(client, args.buf)
93 end
94 end,
95 })
96
44 require("mason-lspconfig").setup(opts) 97 require("mason-lspconfig").setup(opts)
45 98
46 -- clangd ships with Xcode Command Line Tools already, so it's not 99 -- clangd ships with Xcode Command Line Tools already, so it's not