Skip to content

Commit

Permalink
feat: MasonUpdateAll
Browse files Browse the repository at this point in the history
  • Loading branch information
snelling-a committed Sep 25, 2023
1 parent bf464ee commit d78e387
Showing 1 changed file with 64 additions and 1 deletion.
65 changes: 64 additions & 1 deletion lua/plugins/mason.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local Icons = require("config.ui.icons").progress
local Logger = require("config.util.logger"):new("Mason")

--- @type LazySpec
local M = {
Expand All @@ -7,6 +8,13 @@ local M = {

M.build = ":MasonUpdate"

M.cmd = {
"Mason",
"MasonInstall",
"MasonUpdate",
"MasonUpdateAll",
}

M.opts = {
ui = {
border = "rounded",
Expand All @@ -18,6 +26,61 @@ M.opts = {
},
}

M.config = true
function M.config(_, opts)
require("mason").setup(opts)

vim.api.nvim_create_user_command("MasonUpdateAll", function()
local ok, registry = pcall(require, "mason-registry")
if not ok then
Logger:warn("Unable to access mason registry")

return
end
Logger:info("Checking for package updates...")

registry.update(vim.schedule_wrap(function(success, updated_registries)
if success then
local installed_pkgs = registry.get_installed_packages()
local running = #installed_pkgs
local no_pkgs = running == 0

if no_pkgs then
Logger:info("No updates available")
else
local updated = false

for _, pkg in ipairs(installed_pkgs) do
pkg:check_new_version(function(update_available, version)
if update_available then
updated = true

Logger:info(("Updating `%s` to %s"):format(pkg.name, version.latest_version))

pkg:install():on("closed", function()
running = running - 1
if running == 0 then
Logger:info("Update Complete")
end
end)
else
running = running - 1

if running == 0 then
if updated then
Logger:info("Update Complete")
else
Logger:info("No updates available")
end
end
end
end)
end
end
else
Logger:error(("Failed to update registries: %s"):format(updated_registries))
end
end))
end, {})
end

return M

0 comments on commit d78e387

Please sign in to comment.