refactor: update mason install all command

skip packages already installed
This commit is contained in:
xfy
2025-03-24 09:17:20 +08:00
parent 49fc19c88d
commit 99e566c502
2 changed files with 41 additions and 24 deletions

View File

@ -116,8 +116,20 @@ for _, group in pairs(ensure_installed) do
end
-- Create user command to synchronously install all Mason tools in `opts.ensure_installed`.
user_command("MasonInstallAll", function()
vim.api.nvim_create_user_command("MasonInstallAll", function()
-- 使用 pcall 引入 mason-registry
local success, registry = pcall(require, "mason-registry")
if not success then
vim.notify("Failed to load mason-registry: " .. registry, vim.log.levels.ERROR)
return
end
for _, tool in ipairs(flattened_ensure_installed) do
local pkg = registry.get_package(tool)
if not pkg:is_installed() then
vim.cmd("MasonInstall " .. tool)
else
vim.notify(tool .. " is already installed", vim.log.levels.INFO)
end
end
end, {})

View File

@ -1,4 +1,5 @@
return {
{
"williamboman/mason.nvim",
-- event = "VeryLazy",
cmd = {
@ -23,4 +24,8 @@ return {
},
})
end,
},
{
"mason-org/mason-registry",
},
}