Add inline schema references for Kubernetes resources and CRDs using snippets
Source of video: https://asciinema.org/a/730906
The differences from other plugins is that it doesn't patch, interfere the language server's settings, auto match base on file content. It just provide a fast way to add inline schema.
Note
Support L3MON4D3/LuaSnip only
Important
You will need to use yaml-language-server to have suggestions and documentations like in the video.
-- lazy.nvim
{
"KevinNitroG/kubernetes-schema-snippets.nvim",
ft = "yaml",
config = true,
dependencies = "L3MON4D3/LuaSnip",
}
---@module 'kubernetes-json-schema'
---@type KubernetesJsonSchema.Opts
{
filetypes = {
"yaml",
},
integrations = {
kubernetes = true,
kustomize = true,
crds_catalog = true,
argocd = true,
flux2 = true,
},
}
- Snippets:
schema-kube
schema-kustomize
,kus
schema-crds-catalog
schema-argocd
,argocd-app
,argocd-appset
schema-flux2
- Choose version, type, resources by iterating versions either using:
- Next:
<Plug>luasnip-next-choice
- Prev:
<Plug>luasnip-prev-choice
- Open choices with
vim.ui.select
using:require("luasnip.extras.select_choice")()
- Enter yourself by going to the last choice and type string
- Next:
Warning
The resources of Kubernetes, argocd are from the master version. Choosing older versions might not have the resources of the latest one.
Below is an example of my personal keymaps configuration for LuaSnip. You may use it as a reference for your setup.
---@module 'lazy'
---@type LazySpec
return {
"L3MON4D3/LuaSnip",
keys = {
{
"<C-n>",
"<Plug>luasnip-next-choice",
silent = true,
mode = { "i", "s" },
},
{
"<C-p>",
"<Plug>luasnip-prev-choice",
silent = true,
mode = { "i", "s" },
},
{
"<M-e>",
function()
if require("luasnip").expand_or_jumpable() then
require("luasnip").expand_or_jump()
end
end,
silent = true,
mode = { "i", "s" },
noremap = true,
},
{
"<M-c>",
function()
if require("luasnip").choice_active() then
require("luasnip.extras.select_choice")()
end
end,
silent = true,
mode = { "i", "s" },
},
},
}
- https://github.com/yannh/kubernetes-json-schema
- https://github.com/datreeio/CRDs-catalog
- https://github.com/KevinNitroG/argocd-json-schema
- https://github.com/fluxcd-community/flux2-schemas