From be762f0754b0d3853a33711dc49310e55517e82b Mon Sep 17 00:00:00 2001 From: robin Date: Fri, 23 Jan 2026 14:39:57 +0100 Subject: [PATCH] lsp: refactor configs without massive table --- config/lsp/jsonls.lua | 10 +++ config/lsp/lua_ls.lua | 41 +++++++++++ config/lsp/yamlls.lua | 11 +++ config/lua/ivy/config/lsp.lua | 131 ++++++++++------------------------ config/plugin/lsp.lua | 36 +--------- 5 files changed, 99 insertions(+), 130 deletions(-) create mode 100644 config/lsp/jsonls.lua create mode 100644 config/lsp/lua_ls.lua create mode 100644 config/lsp/yamlls.lua diff --git a/config/lsp/jsonls.lua b/config/lsp/jsonls.lua new file mode 100644 index 0000000..898b461 --- /dev/null +++ b/config/lsp/jsonls.lua @@ -0,0 +1,10 @@ +return { + before_init = function(_, config) + config.settings.json.schemas = require("schemastore").json.schemas() + end, + settings = { + json = { + validate = { enable = true }, + }, + }, +} diff --git a/config/lsp/lua_ls.lua b/config/lsp/lua_ls.lua new file mode 100644 index 0000000..0c69003 --- /dev/null +++ b/config/lsp/lua_ls.lua @@ -0,0 +1,41 @@ +return { + on_init = function(client) + if client.workspace_folders then + local path = client.workspace_folders[1].name + if + path ~= vim.fn.stdpath("config") + and (vim.uv.fs_stat(path .. "/.luarc.json") or vim.uv.fs_stat(path .. "/.luarc.jsonc")) + then + return + end + end + client.config.settings.Lua = vim.tbl_deep_extend("force", client.config.settings.Lua, { + workspace = { + checkThirdParty = false, + library = { + vim.env.VIMRUNTIME, + -- Depending on the usage, you might want to add additional paths here. + -- "${3rd}/luv/library" + }, + }, + }) + end, + settings = { + Lua = { + runtime = { + version = "LuaJIT", + path = { + "lua/?.lua", + "lua/?/init.lua", + }, + }, + diagnostics = { + globals = { "vim", "package", "table" }, + }, + hint = { + enable = true, + arrayIndex = "Disable", + }, + }, + }, +} diff --git a/config/lsp/yamlls.lua b/config/lsp/yamlls.lua new file mode 100644 index 0000000..950777a --- /dev/null +++ b/config/lsp/yamlls.lua @@ -0,0 +1,11 @@ +return { + before_init = function(_, config) + config.settings.yaml.schemas = vim.tbl_extend("keep", { + ["https://json.schemastore.org/github-action"] = ".github/action.{yaml,yml}", + ["https://json.schemastore.org/github-workflow"] = ".github/workflows/*", + ["https://gitlab.com/gitlab-org/gitlab/-/raw/master/app/assets/javascripts/editor/schema/ci.json"] = "*lab-ci.{yaml,yml}", + ["https://raw.githubusercontent.com/compose-spec/compose-spec/master/schema/compose-spec.json"] = "docker-compose.{yml,yaml}", + ["https://goreleaser.com/static/schema.json"] = ".goreleaser.{yml,yaml}", + }, require("schemastore").yaml.schemas()) + end, +} diff --git a/config/lua/ivy/config/lsp.lua b/config/lua/ivy/config/lsp.lua index 484570f..37135e8 100644 --- a/config/lua/ivy/config/lsp.lua +++ b/config/lua/ivy/config/lsp.lua @@ -1,95 +1,36 @@ -vim.g.lsp_config = { - common = {}, - servers = function() - return { - astro = {}, - bashls = {}, - clangd = {}, - colorlsp = {}, - cssls = {}, - denols = {}, - dockerls = {}, - emmet_language_server = {}, - gopls = {}, - hls = {}, - html = {}, - jsonls = { - settings = { - json = { - schemas = require("schemastore").json.schemas(), - validate = { enable = true }, - }, - }, - }, - lua_ls = { - on_init = function(client) - if client.workspace_folders then - local path = client.workspace_folders[1].name - if - path ~= vim.fn.stdpath("config") - and (vim.uv.fs_stat(path .. "/.luarc.json") or vim.uv.fs_stat(path .. "/.luarc.jsonc")) - then - return - end - end - client.config.settings.Lua = vim.tbl_deep_extend("force", client.config.settings.Lua, { - workspace = { - checkThirdParty = false, - library = { - vim.env.VIMRUNTIME, - -- Depending on the usage, you might want to add additional paths here. - -- "${3rd}/luv/library" - }, - }, - }) - end, - settings = { - Lua = { - runtime = { - version = "LuaJIT", - path = { - "lua/?.lua", - "lua/?/init.lua", - }, - }, - diagnostics = { - globals = { "vim", "package", "table" }, - }, - hint = { - enable = true, - arrayIndex = "Disable", - }, - }, - }, - }, - marksman = {}, - nil_ls = {}, - nushell = {}, - taplo = {}, - teal_ls = {}, - tinymist = {}, - ts_ls = {}, - tailwindcss = {}, - vue_ls = {}, - yamlls = { - settings = { - yaml = { - schemas = vim.tbl_extend("keep", { - ["https://json.schemastore.org/github-action"] = ".github/action.{yaml,yml}", - ["https://json.schemastore.org/github-workflow"] = ".github/workflows/*", - ["https://gitlab.com/gitlab-org/gitlab/-/raw/master/app/assets/javascripts/editor/schema/ci.json"] = "*lab-ci.{yaml,yml}", - ["https://raw.githubusercontent.com/compose-spec/compose-spec/master/schema/compose-spec.json"] = "docker-compose.{yml,yaml}", - ["https://goreleaser.com/static/schema.json"] = ".goreleaser.{yml,yaml}", - }, require("schemastore").yaml.schemas()), - }, - }, - }, - zk = {}, - zls = {}, - } - end, - on_attach = function(_, buf) - local opts = { buffer = buf } - vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) - end, -} +-- common ===================================================================== +-- vim.lsp.config('*', {}) + +-- enable ===================================================================== +vim.lsp.enable({ + "astro", + "bashls", + "clangd", + "colorlsp", + "cssls", + "denols", + "dockerls", + "emmet_language_server", + "gopls", + "hls", + "html", + "jsonls", + "lua_ls", + "marksman", + "nil_ls", + "nushell", + "taplo", + "teal_ls", + "tinymist", + "ts_ls", + "tailwindcss", + "vue_ls", + "yamlls", + "zk", + "zls", +}) + +vim.g.lsp_on_attach = function(_, buf) + local opts = { buffer = buf } + vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) +end diff --git a/config/plugin/lsp.lua b/config/plugin/lsp.lua index 9cd1832..6b9b896 100644 --- a/config/plugin/lsp.lua +++ b/config/plugin/lsp.lua @@ -1,9 +1,3 @@ -local props = vim.g.lsp_config or {} - -vim.validate("vim.g.lsp_config.common", props.common, { "table", "function" }) -vim.validate("vim.g.lsp_config.servers", props.servers, { "table", "function" }) -vim.validate("vim.g.lsp_config.on_attach", props.on_attach, "function") - local components = { { name = "inlay_hint", @@ -50,7 +44,7 @@ local components = { end end, }, - { name = "user", callback = props.on_attach }, + { name = "user", callback = vim.g.lsp_on_attach }, } vim.iter(ipairs(components)):each(function(_, fn) @@ -69,31 +63,3 @@ vim.iter(ipairs(components)):each(function(_, fn) end end) end) - -local common = props.common -if type(common) == "function" then - common = common() -end - -vim.lsp.config("*", common) - -local function setup_ls(name, cfg) - ---@diagnostic disable-next-line: param-type-mismatch - local ok, result = pcall(vim.lsp.config, name, cfg) - if not ok then - vim.notify(("unable to configure lsp server %s:\n\t%s"):format(name, result)) - return - end - vim.lsp.enable(name) -end - -local servers = props.servers -if type(servers) == "function" then - ---@diagnostic disable-next-line: cast-local-type - servers = servers() -end - -vim.once(function() - ---@diagnostic disable-next-line: param-type-mismatch - vim.iter(pairs(servers)):each(setup_ls) -end) -- 2.51.2