diff --git a/nvim/dot-config/nvim/lazy-lock.json b/nvim/dot-config/nvim/lazy-lock.json index 05d5c47..d997f98 100644 --- a/nvim/dot-config/nvim/lazy-lock.json +++ b/nvim/dot-config/nvim/lazy-lock.json @@ -32,7 +32,7 @@ "peek.nvim": { "branch": "master", "commit": "5820d937d5414baea5f586dc2a3d912a74636e5b" }, "plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" }, "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" }, "scrollEOF.nvim": { "branch": "master", "commit": "aeedfad14e4a0cfa31b44b531c1ad8fd4696b551" }, "smart-open.nvim": { "branch": "0.3.x", "commit": "e7f27218bd43de5262d3e8e3e84a135737ca6942" }, diff --git a/nvim/dot-config/nvim/lsp/jsonls.lua b/nvim/dot-config/nvim/lsp/jsonls.lua index 03e1cbb..b7db323 100644 --- a/nvim/dot-config/nvim/lsp/jsonls.lua +++ b/nvim/dot-config/nvim/lsp/jsonls.lua @@ -1,8 +1,16 @@ -return { - settings = { - json = { - validate = { enable = true }, - schemas = require("schemastore").json.schemas(), +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 = { + json = { + validate = { enable = true }, + schemas = require("schemastore").json.schemas(), + }, + }, + } +) diff --git a/nvim/dot-config/nvim/lsp/taplo.lua b/nvim/dot-config/nvim/lsp/taplo.lua new file mode 100644 index 0000000..2c46331 --- /dev/null +++ b/nvim/dot-config/nvim/lsp/taplo.lua @@ -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(), + }, + }), + {} +) diff --git a/nvim/dot-config/nvim/lsp/yamlls.lua b/nvim/dot-config/nvim/lsp/yamlls.lua index ec1496a..0739b8d 100644 --- a/nvim/dot-config/nvim/lsp/yamlls.lua +++ b/nvim/dot-config/nvim/lsp/yamlls.lua @@ -1,5 +1,10 @@ -return require("schema-companion").setup_client({ - settings = { - yaml = {}, - }, -}) +return require("schema-companion").setup_client( + require("schema-companion").adapters.yamlls.setup({ + sources = { + require("matchers.kubernetes").setup({}), + require("schema-companion").sources.lsp.setup(), + require("schema-companion").sources.none.setup(), + }, + }), + {} +) diff --git a/nvim/dot-config/nvim/lua/matchers/kubernetes.lua b/nvim/dot-config/nvim/lua/matchers/kubernetes.lua new file mode 100644 index 0000000..008818c --- /dev/null +++ b/nvim/dot-config/nvim/lua/matchers/kubernetes.lua @@ -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 diff --git a/nvim/dot-config/nvim/lua/plugins/lualine.lua b/nvim/dot-config/nvim/lua/plugins/lualine.lua index a949e7f..994404e 100644 --- a/nvim/dot-config/nvim/lua/plugins/lualine.lua +++ b/nvim/dot-config/nvim/lua/plugins/lualine.lua @@ -1,15 +1,15 @@ -- https://github.com/nvim-lualine/lualine.nvim 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 "" end - local schema = require("schema-companion.context").get_buffer_schema() - if schema.name == "none" then + local schema = (require("schema-companion").get_current_schemas() or "none") + if schema == "none" then return "" end - return schema.name + return schema end --- @module "lazy" @@ -43,7 +43,9 @@ return { "encoding", { "fileformat", icons_enabled = false }, "filetype", - get_schema, + { + get_schema, + }, }, }, inactive_sections = { diff --git a/nvim/dot-config/nvim/lua/plugins/schema-companion.lua b/nvim/dot-config/nvim/lua/plugins/schema-companion.lua index 205caaa..7382da3 100644 --- a/nvim/dot-config/nvim/lua/plugins/schema-companion.lua +++ b/nvim/dot-config/nvim/lua/plugins/schema-companion.lua @@ -1,33 +1,6 @@ -- https://github.com/cenk1cenk2/schema-companion.nvim --- @module "schema-companion" --- @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" --- @type LazySpec @@ -35,14 +8,13 @@ return { "cenk1cenk2/schema-companion.nvim", dependencies = { "nvim-lua/plenary.nvim", - "nvim-telescope/telescope.nvim", "diogo464/kubernetes.nvim", }, keys = { { "ys", function() - require("telescope").extensions.schema_companion.select_schema() + require("schema-companion").select_schema() end, desc = "Yaml schema", ft = "yaml", @@ -50,11 +22,5 @@ return { }, --- @module "schema-companion" --- @type schema_companion.Config - opts = { - enable_telescope = true, - matchers = { - kubernetes, - }, - schemas = {}, - }, + opts = {}, }