nvim: Update schema-companion and kubernetes matcher
This commit is contained in:
@@ -32,7 +32,7 @@
|
|||||||
"peek.nvim": { "branch": "master", "commit": "5820d937d5414baea5f586dc2a3d912a74636e5b" },
|
"peek.nvim": { "branch": "master", "commit": "5820d937d5414baea5f586dc2a3d912a74636e5b" },
|
||||||
"plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" },
|
"plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" },
|
||||||
"ros-nvim": { "branch": "main", "commit": "1ad64cd3a1e144dfea67890845f9da2e82d96900" },
|
"ros-nvim": { "branch": "main", "commit": "1ad64cd3a1e144dfea67890845f9da2e82d96900" },
|
||||||
"schema-companion.nvim": { "branch": "main", "commit": "b22243d3ca71be08d06a4b9bf200c1d677c41d45" },
|
"schema-companion.nvim": { "branch": "main", "commit": "e94f5f8439705d772363817c9d2c6c9fc7562bd0" },
|
||||||
"schemastore.nvim": { "branch": "main", "commit": "2ae6d27897c60265d4ad3f33e286528d519098fd" },
|
"schemastore.nvim": { "branch": "main", "commit": "2ae6d27897c60265d4ad3f33e286528d519098fd" },
|
||||||
"scrollEOF.nvim": { "branch": "master", "commit": "aeedfad14e4a0cfa31b44b531c1ad8fd4696b551" },
|
"scrollEOF.nvim": { "branch": "master", "commit": "aeedfad14e4a0cfa31b44b531c1ad8fd4696b551" },
|
||||||
"smart-open.nvim": { "branch": "0.3.x", "commit": "e7f27218bd43de5262d3e8e3e84a135737ca6942" },
|
"smart-open.nvim": { "branch": "0.3.x", "commit": "e7f27218bd43de5262d3e8e3e84a135737ca6942" },
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
return {
|
return require("schema-companion").setup_client(
|
||||||
|
require("schema-companion").adapters.jsonls.setup({
|
||||||
|
sources = {
|
||||||
|
require("schema-companion").sources.lsp.setup(),
|
||||||
|
require("schema-companion").sources.none.setup(),
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
{
|
||||||
settings = {
|
settings = {
|
||||||
json = {
|
json = {
|
||||||
validate = { enable = true },
|
validate = { enable = true },
|
||||||
@@ -6,3 +13,4 @@ return {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
|||||||
9
nvim/dot-config/nvim/lsp/taplo.lua
Normal file
9
nvim/dot-config/nvim/lsp/taplo.lua
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
return require("schema-companion").setup_client(
|
||||||
|
require("schema-companion").adapters.taplo.setup({
|
||||||
|
sources = {
|
||||||
|
require("schema-companion").sources.lsp.setup(),
|
||||||
|
require("schema-companion").sources.none.setup(),
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
{}
|
||||||
|
)
|
||||||
@@ -1,5 +1,10 @@
|
|||||||
return require("schema-companion").setup_client({
|
return require("schema-companion").setup_client(
|
||||||
settings = {
|
require("schema-companion").adapters.yamlls.setup({
|
||||||
yaml = {},
|
sources = {
|
||||||
|
require("matchers.kubernetes").setup({}),
|
||||||
|
require("schema-companion").sources.lsp.setup(),
|
||||||
|
require("schema-companion").sources.none.setup(),
|
||||||
},
|
},
|
||||||
})
|
}),
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
|||||||
57
nvim/dot-config/nvim/lua/matchers/kubernetes.lua
Normal file
57
nvim/dot-config/nvim/lua/matchers/kubernetes.lua
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
---@class schema_companion.Source
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
M.name = "Kubernetes"
|
||||||
|
|
||||||
|
M.config = {}
|
||||||
|
|
||||||
|
---@param config {}
|
||||||
|
---@return schema_companion.Source
|
||||||
|
function M.setup(config)
|
||||||
|
setmetatable(M, {})
|
||||||
|
M.config = vim.tbl_deep_extend("force", {}, M.config, config)
|
||||||
|
|
||||||
|
return M
|
||||||
|
end
|
||||||
|
|
||||||
|
function M:match(_, bufnr)
|
||||||
|
local resources = {}
|
||||||
|
|
||||||
|
local current = {}
|
||||||
|
for _, line in pairs(vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)) do
|
||||||
|
local _, _, group, version = line:find([[^apiVersion:%s*["']?([^%s"'/]*)/?([^%s"']*)]])
|
||||||
|
local _, _, kind = line:find([[^kind:%s*["']?([^%s"'/]*)]])
|
||||||
|
|
||||||
|
if group and group ~= "" then
|
||||||
|
current.group = group
|
||||||
|
end
|
||||||
|
if version and version ~= "" then
|
||||||
|
current.version = version
|
||||||
|
end
|
||||||
|
if kind and kind ~= "" then
|
||||||
|
current.kind = kind
|
||||||
|
end
|
||||||
|
|
||||||
|
if current.group and current.kind then
|
||||||
|
table.insert(resources, current)
|
||||||
|
current = {}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local schemas = {}
|
||||||
|
for _, resource in pairs(resources) do
|
||||||
|
local api = resource.version and ("%s/%s"):format(resource.group, resource.version) or resource.group
|
||||||
|
local schema = {
|
||||||
|
name = ("%s@%s"):format(resource.kind, api),
|
||||||
|
source = M.name,
|
||||||
|
uri = require("kubernetes").yamlls_schema(),
|
||||||
|
}
|
||||||
|
if schema then
|
||||||
|
table.insert(schemas, schema)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return schemas
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
-- https://github.com/nvim-lualine/lualine.nvim
|
-- https://github.com/nvim-lualine/lualine.nvim
|
||||||
|
|
||||||
local function get_schema()
|
local function get_schema()
|
||||||
if vim.bo.filetype ~= "yaml" then
|
if not (vim.bo.filetype == "yaml" or vim.bo.filetype == "json" or vim.bo.filetype == "toml") then
|
||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
|
|
||||||
local schema = require("schema-companion.context").get_buffer_schema()
|
local schema = (require("schema-companion").get_current_schemas() or "none")
|
||||||
if schema.name == "none" then
|
if schema == "none" then
|
||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
return schema.name
|
return schema
|
||||||
end
|
end
|
||||||
|
|
||||||
--- @module "lazy"
|
--- @module "lazy"
|
||||||
@@ -43,9 +43,11 @@ return {
|
|||||||
"encoding",
|
"encoding",
|
||||||
{ "fileformat", icons_enabled = false },
|
{ "fileformat", icons_enabled = false },
|
||||||
"filetype",
|
"filetype",
|
||||||
|
{
|
||||||
get_schema,
|
get_schema,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
inactive_sections = {
|
inactive_sections = {
|
||||||
lualine_c = {
|
lualine_c = {
|
||||||
{ "filename", path = 1 },
|
{ "filename", path = 1 },
|
||||||
|
|||||||
@@ -1,33 +1,6 @@
|
|||||||
-- https://github.com/cenk1cenk2/schema-companion.nvim
|
-- https://github.com/cenk1cenk2/schema-companion.nvim
|
||||||
--- @module "schema-companion"
|
--- @module "schema-companion"
|
||||||
--- @type schema_companion.Matcher
|
--- @type schema_companion.Matcher
|
||||||
local kubernetes = {
|
|
||||||
name = "Kubernetes",
|
|
||||||
match = function(bufnr)
|
|
||||||
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
|
|
||||||
local kind = false
|
|
||||||
local api_version = false
|
|
||||||
|
|
||||||
for _, line in ipairs(lines) do
|
|
||||||
if kind or vim.regex("^kind: .*$"):match_str(line) then
|
|
||||||
kind = true
|
|
||||||
end
|
|
||||||
|
|
||||||
if api_version or vim.regex("^apiVersion: .*$"):match_str(line) then
|
|
||||||
api_version = true
|
|
||||||
end
|
|
||||||
|
|
||||||
if kind and api_version then
|
|
||||||
return {
|
|
||||||
name = "Kubernetes",
|
|
||||||
uri = require("kubernetes").yamlls_schema(),
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return nil
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
|
|
||||||
--- @module "lazy"
|
--- @module "lazy"
|
||||||
--- @type LazySpec
|
--- @type LazySpec
|
||||||
@@ -35,14 +8,13 @@ return {
|
|||||||
"cenk1cenk2/schema-companion.nvim",
|
"cenk1cenk2/schema-companion.nvim",
|
||||||
dependencies = {
|
dependencies = {
|
||||||
"nvim-lua/plenary.nvim",
|
"nvim-lua/plenary.nvim",
|
||||||
"nvim-telescope/telescope.nvim",
|
|
||||||
"diogo464/kubernetes.nvim",
|
"diogo464/kubernetes.nvim",
|
||||||
},
|
},
|
||||||
keys = {
|
keys = {
|
||||||
{
|
{
|
||||||
"<leader>ys",
|
"<leader>ys",
|
||||||
function()
|
function()
|
||||||
require("telescope").extensions.schema_companion.select_schema()
|
require("schema-companion").select_schema()
|
||||||
end,
|
end,
|
||||||
desc = "Yaml schema",
|
desc = "Yaml schema",
|
||||||
ft = "yaml",
|
ft = "yaml",
|
||||||
@@ -50,11 +22,5 @@ return {
|
|||||||
},
|
},
|
||||||
--- @module "schema-companion"
|
--- @module "schema-companion"
|
||||||
--- @type schema_companion.Config
|
--- @type schema_companion.Config
|
||||||
opts = {
|
opts = {},
|
||||||
enable_telescope = true,
|
|
||||||
matchers = {
|
|
||||||
kubernetes,
|
|
||||||
},
|
|
||||||
schemas = {},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user