Restructure nvim LSP setup and add LspAdd command

This commit is contained in:
Talia 2024-09-16 14:55:50 +02:00
parent 06bc34e586
commit b404b0d34d

View file

@ -20,7 +20,17 @@ setmetatable(default, {__call = function(self, other)
return new return new
end}) end})
for key, value in pairs { local configs = setmetatable({
yamlls = default {
settings = {
yaml = {
format = { enable = true }
}
}
},
}, {__index = function() return default end})
for _, language in ipairs {
"clangd", "clangd",
"cssls", "cssls",
"html", "html",
@ -31,28 +41,22 @@ for key, value in pairs {
"svelte", "svelte",
"tsserver", "tsserver",
"zls", "zls",
yamlls = default { "yamlls", -- bun install --global yaml-language-server
settings = {
yaml = {
format = { enable = true }
}
}
}, -- bun install --global yaml-language-server
} do } do
local language, settings if type(key) == "string" then config[language].setup(ensure_capabilities(configs[language]))
language, settings = key, value
else
language, settings = value, default
end end
config[language].setup(ensure_capabilities(settings)) -- function _G.ls(name)
end -- for _, server in pairs(vim.lsp.get_clients()) do
-- if server.config.name == name then
-- return server
-- end
-- error("No running language server with name " .. name)
-- end
-- end
function _G.ls(name) vim.api.nvim_create_user_command("LspAdd", function(params)
for _, server in pairs(vim.lsp.get_clients()) do local language = params.args
if server.config.name == name then local setup = config[language].setup -- temp variable for better stack trace
return server setup(ensure_capabilities(configs[language]))
end end, {nargs = 1})
error("No running language server with name " .. name)
end
end