mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-07-14 11:24:38 +02:00
fix(mason): conform to v2 changes
This commit is contained in:
parent
cb223553ff
commit
8a52e1bf75
24 changed files with 84 additions and 54 deletions
|
@ -2,10 +2,14 @@ return {
|
|||
-- lspconfig
|
||||
{
|
||||
"neovim/nvim-lspconfig",
|
||||
event = "LazyFile",
|
||||
event = vim.fn.has("nvim-0.11") == 1 and { "BufReadPre", "BufNewFile", "BufWritePre" } or "LazyFile",
|
||||
dependencies = {
|
||||
"mason.nvim",
|
||||
{ "williamboman/mason-lspconfig.nvim", config = function() end },
|
||||
{
|
||||
"mason-org/mason-lspconfig.nvim",
|
||||
version = vim.fn.has("nvim-0.11") == 0 and "1.32.0" or false,
|
||||
config = function() end,
|
||||
},
|
||||
},
|
||||
opts = function()
|
||||
---@class PluginLspOpts
|
||||
|
@ -188,7 +192,18 @@ return {
|
|||
opts.capabilities or {}
|
||||
)
|
||||
|
||||
local function setup(server)
|
||||
-- get all the servers that are available through mason-lspconfig
|
||||
local have_mason, mlsp = pcall(require, "mason-lspconfig")
|
||||
local all_mslp_servers = {}
|
||||
if have_mason and vim.fn.has("nvim-0.11") == 1 then
|
||||
all_mslp_servers = vim.tbl_keys(require("mason-lspconfig").get_mappings().lspconfig_to_package)
|
||||
elseif have_mason then
|
||||
all_mslp_servers = vim.tbl_keys(require("mason-lspconfig.mappings.server").lspconfig_to_package)
|
||||
end
|
||||
|
||||
local exclude_automatic_enable = {} ---@type string[]
|
||||
|
||||
local function configure(server)
|
||||
local server_opts = vim.tbl_deep_extend("force", {
|
||||
capabilities = vim.deepcopy(capabilities),
|
||||
}, servers[server] or {})
|
||||
|
@ -205,14 +220,22 @@ return {
|
|||
return
|
||||
end
|
||||
end
|
||||
require("lspconfig")[server].setup(server_opts)
|
||||
end
|
||||
if vim.fn.has("nvim-0.11") == 1 then
|
||||
vim.lsp.config(server, server_opts)
|
||||
else
|
||||
require("lspconfig")[server].setup(server_opts)
|
||||
end
|
||||
|
||||
-- get all the servers that are available through mason-lspconfig
|
||||
local have_mason, mlsp = pcall(require, "mason-lspconfig")
|
||||
local all_mslp_servers = {}
|
||||
if have_mason then
|
||||
all_mslp_servers = vim.tbl_keys(require("mason-lspconfig.mappings.server").lspconfig_to_package)
|
||||
-- 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(all_mslp_servers, server) then
|
||||
if vim.fn.has("nvim-0.11") == 1 then
|
||||
vim.lsp.enable(server)
|
||||
else
|
||||
configure(server)
|
||||
end
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local ensure_installed = {} ---@type string[]
|
||||
|
@ -221,8 +244,8 @@ return {
|
|||
server_opts = server_opts == true and {} or server_opts
|
||||
if server_opts.enabled ~= false then
|
||||
-- run manual setup 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(all_mslp_servers, server) then
|
||||
setup(server)
|
||||
if configure(server) then
|
||||
exclude_automatic_enable[#exclude_automatic_enable + 1] = server
|
||||
else
|
||||
ensure_installed[#ensure_installed + 1] = server
|
||||
end
|
||||
|
@ -231,14 +254,23 @@ return {
|
|||
end
|
||||
|
||||
if have_mason then
|
||||
mlsp.setup({
|
||||
local setup_config = {
|
||||
ensure_installed = vim.tbl_deep_extend(
|
||||
"force",
|
||||
ensure_installed,
|
||||
LazyVim.opts("mason-lspconfig.nvim").ensure_installed or {}
|
||||
),
|
||||
handlers = { setup },
|
||||
})
|
||||
}
|
||||
|
||||
if vim.fn.has("nvim-0.11") == 1 then
|
||||
setup_config.automatic_enable = {
|
||||
exclude = exclude_automatic_enable,
|
||||
}
|
||||
else
|
||||
setup_config.handlers = { configure }
|
||||
end
|
||||
|
||||
mlsp.setup(setup_config)
|
||||
end
|
||||
|
||||
if LazyVim.lsp.is_enabled("denols") and LazyVim.lsp.is_enabled("vtsls") then
|
||||
|
@ -257,8 +289,9 @@ return {
|
|||
-- cmdline tools and lsp servers
|
||||
{
|
||||
|
||||
"williamboman/mason.nvim",
|
||||
"mason-org/mason.nvim",
|
||||
cmd = "Mason",
|
||||
version = vim.fn.has("nvim-0.11") == 0 and "1.11.0" or false,
|
||||
keys = { { "<leader>cm", "<cmd>Mason<cr>", desc = "Mason" } },
|
||||
build = ":MasonUpdate",
|
||||
opts_extend = { "ensure_installed" },
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue