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
vim.cmd("MasonInstall " .. tool)
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,26 +1,31 @@
return {
"williamboman/mason.nvim",
-- event = "VeryLazy",
cmd = {
"Mason",
"MasonUpdate",
"MasonInstall",
"MasonUninstall",
"MasonUninstallAll",
"MasonLog",
},
config = function()
local mason = require("mason")
{
"williamboman/mason.nvim",
-- event = "VeryLazy",
cmd = {
"Mason",
"MasonUpdate",
"MasonInstall",
"MasonUninstall",
"MasonUninstallAll",
"MasonLog",
},
config = function()
local mason = require("mason")
-- enable mason and configure icons
mason.setup({
ui = {
icons = {
package_installed = "",
package_pending = "",
package_uninstalled = "",
-- enable mason and configure icons
mason.setup({
ui = {
icons = {
package_installed = "",
package_pending = "",
package_uninstalled = "",
},
},
},
})
end,
})
end,
},
{
"mason-org/mason-registry",
},
}