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
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",
"cssls",
"html",
@ -31,28 +41,22 @@ for key, value in pairs {
"svelte",
"tsserver",
"zls",
yamlls = default {
settings = {
yaml = {
format = { enable = true }
}
}
}, -- bun install --global yaml-language-server
"yamlls", -- bun install --global yaml-language-server
} do
local language, settings if type(key) == "string" then
language, settings = key, value
else
language, settings = value, default
end
config[language].setup(ensure_capabilities(settings))
config[language].setup(ensure_capabilities(configs[language]))
end
function _G.ls(name)
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)
-- 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
vim.api.nvim_create_user_command("LspAdd", function(params)
local language = params.args
local setup = config[language].setup -- temp variable for better stack trace
setup(ensure_capabilities(configs[language]))
end, {nargs = 1})