feat(mason): compatibility with the new mason registry
This commit is contained in:
@ -101,15 +101,19 @@ return {
|
|||||||
require("lspconfig")[server].setup(server_opts)
|
require("lspconfig")[server].setup(server_opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- get all the servers that are available thourgh mason-lspconfig
|
||||||
local have_mason, mlsp = pcall(require, "mason-lspconfig")
|
local have_mason, mlsp = pcall(require, "mason-lspconfig")
|
||||||
local available = have_mason and mlsp.get_available_servers() or {}
|
local all_mslp_servers = {}
|
||||||
|
if have_mason then
|
||||||
|
all_mslp_servers = vim.tbl_keys(require("mason-lspconfig.mappings.server").lspconfig_to_package)
|
||||||
|
end
|
||||||
|
|
||||||
local ensure_installed = {} ---@type string[]
|
local ensure_installed = {} ---@type string[]
|
||||||
for server, server_opts in pairs(servers) do
|
for server, server_opts in pairs(servers) do
|
||||||
if server_opts then
|
if server_opts then
|
||||||
server_opts = server_opts == true and {} or server_opts
|
server_opts = server_opts == true and {} or server_opts
|
||||||
-- run manual setup if mason=false or if this is a server that cannot be installed with mason-lspconfig
|
-- 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(available, server) then
|
if server_opts.mason == false or not vim.tbl_contains(all_mslp_servers, server) then
|
||||||
setup(server)
|
setup(server)
|
||||||
else
|
else
|
||||||
ensure_installed[#ensure_installed + 1] = server
|
ensure_installed[#ensure_installed + 1] = server
|
||||||
@ -161,12 +165,19 @@ return {
|
|||||||
config = function(_, opts)
|
config = function(_, opts)
|
||||||
require("mason").setup(opts)
|
require("mason").setup(opts)
|
||||||
local mr = require("mason-registry")
|
local mr = require("mason-registry")
|
||||||
for _, tool in ipairs(opts.ensure_installed) do
|
local function ensure_installed()
|
||||||
local p = mr.get_package(tool)
|
for _, tool in ipairs(opts.ensure_installed) do
|
||||||
if not p:is_installed() then
|
local p = mr.get_package(tool)
|
||||||
p:install()
|
if not p:is_installed() then
|
||||||
|
p:install()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if mr.refresh then
|
||||||
|
mr.refresh(ensure_installed)
|
||||||
|
else
|
||||||
|
ensure_installed()
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user