mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-24 13:31:06 +00:00
refactor(lsp): cleanup lsp/mason-lspconfig code
This commit is contained in:
parent
775621ac0a
commit
16637dd655
1 changed files with 23 additions and 37 deletions
|
|
@ -68,7 +68,8 @@ return {
|
||||||
timeout_ms = nil,
|
timeout_ms = nil,
|
||||||
},
|
},
|
||||||
-- LSP Server Settings
|
-- LSP Server Settings
|
||||||
---@type table<string, vim.lsp.Config|{mason?:boolean, enabled?:boolean}|boolean>
|
---@alias lazyvim.lsp.Config vim.lsp.Config|{mason?:boolean, enabled?:boolean}
|
||||||
|
---@type table<string, lazyvim.lsp.Config|boolean>
|
||||||
servers = {
|
servers = {
|
||||||
lua_ls = {
|
lua_ls = {
|
||||||
-- mason = false, -- set to false if you don't want this server to be installed with mason
|
-- mason = false, -- set to false if you don't want this server to be installed with mason
|
||||||
|
|
@ -187,51 +188,36 @@ return {
|
||||||
and vim.tbl_keys(require("mason-lspconfig.mappings").get_mason_map().lspconfig_to_package)
|
and vim.tbl_keys(require("mason-lspconfig.mappings").get_mason_map().lspconfig_to_package)
|
||||||
or {} --[[ @as string[] ]]
|
or {} --[[ @as string[] ]]
|
||||||
|
|
||||||
local exclude_automatic_enable = {} ---@type string[]
|
---@return boolean? exclude automatic setup
|
||||||
|
|
||||||
local function configure(server)
|
local function configure(server)
|
||||||
local server_opts = opts.servers[server] or {}
|
local sopts = opts.servers[server]
|
||||||
|
sopts = sopts == true and {} or (not sopts) and { enabled = false } or sopts --[[@as lazyvim.lsp.Config]]
|
||||||
local setup = opts.setup[server] or opts.setup["*"]
|
if sopts.enabled == false then
|
||||||
if setup and setup(server, server_opts) then
|
|
||||||
return true -- lsp will be setup by the setup function
|
|
||||||
end
|
|
||||||
|
|
||||||
vim.lsp.config(server, server_opts)
|
|
||||||
|
|
||||||
-- manually enable if mason=false or if this is a server that cannot be installed with mason-lspconfig
|
|
||||||
if server_opts.mason == false or not vim.tbl_contains(mason_all, server) then
|
|
||||||
vim.lsp.enable(server)
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
local ensure_installed = {} ---@type string[]
|
local setup = opts.setup[server] or opts.setup["*"]
|
||||||
for server, server_opts in pairs(opts.servers) do
|
if setup and setup(server, sopts) then
|
||||||
server_opts = server_opts == true and {} or server_opts or false
|
return true -- lsp will be configured and enabled by the setup function
|
||||||
if server_opts and server_opts.enabled ~= false then
|
end
|
||||||
-- run manual setup if mason=false or if this is a server that cannot be installed with mason-lspconfig
|
|
||||||
if configure(server) then
|
vim.lsp.config(server, sopts) -- configure the server
|
||||||
exclude_automatic_enable[#exclude_automatic_enable + 1] = server
|
|
||||||
else
|
-- manually enable if mason=false or if this is a server that cannot be installed with mason-lspconfig
|
||||||
ensure_installed[#ensure_installed + 1] = server
|
if sopts.mason == false or not vim.tbl_contains(mason_all, server) then
|
||||||
end
|
vim.lsp.enable(server)
|
||||||
else
|
return true
|
||||||
exclude_automatic_enable[#exclude_automatic_enable + 1] = server
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if have_mason then
|
if have_mason then
|
||||||
|
local servers = vim.tbl_keys(opts.servers)
|
||||||
|
local exclude = vim.tbl_filter(configure, servers)
|
||||||
require("mason-lspconfig").setup({
|
require("mason-lspconfig").setup({
|
||||||
ensure_installed = vim.tbl_deep_extend(
|
ensure_installed = vim.tbl_filter(function(server)
|
||||||
"force",
|
return not vim.tbl_contains(exclude, server)
|
||||||
ensure_installed,
|
end, vim.list_extend(servers, LazyVim.opts("mason-lspconfig.nvim").ensure_installed or {})),
|
||||||
LazyVim.opts("mason-lspconfig.nvim").ensure_installed or {}
|
automatic_enable = { exclude = exclude },
|
||||||
),
|
|
||||||
automatic_enable = {
|
|
||||||
exclude = exclude_automatic_enable,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end),
|
end),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue