Restructure nvim LSP setup and add LspAdd command
This commit is contained in:
parent
06bc34e586
commit
b404b0d34d
1 changed files with 27 additions and 23 deletions
|
@ -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
|
|
||||||
|
|
||||||
config[language].setup(ensure_capabilities(settings))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function _G.ls(name)
|
-- function _G.ls(name)
|
||||||
for _, server in pairs(vim.lsp.get_clients()) do
|
-- for _, server in pairs(vim.lsp.get_clients()) do
|
||||||
if server.config.name == name then
|
-- if server.config.name == name then
|
||||||
return server
|
-- return server
|
||||||
end
|
-- end
|
||||||
error("No running language server with name " .. name)
|
-- error("No running language server with name " .. name)
|
||||||
end
|
-- end
|
||||||
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})
|
||||||
|
|
Loading…
Reference in a new issue