Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions lua/mason/ui/components/main/package_list.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,20 @@ local function PackageComponent(state, pkg, opts)
}
end

local get_outdated_packages_preview = _.if_else(
_.compose(_.lte(4), _.size),
_.compose(_.join ", ", _.map(_.prop "name")),
_.compose(
_.join ", ",
_.converge(_.concat, {
_.compose(_.map(_.prop "name"), _.take(3)),
function(pkgs)
return { ("and %d more…"):format(#pkgs - 3) }
end,
})
)
)

---@param state InstallerUiState
local function Installed(state)
return Ui.Node {
Expand All @@ -172,6 +186,19 @@ local function Installed(state)
styling((" "):rep(new_versions_check.percentage_complete * 15)),
}
end),
Ui.When(
not state.packages.new_versions_check.is_checking and #state.packages.outdated_packages > 0,
function()
return Ui.VirtualTextNode {
p.muted "Press ",
p.highlight(settings.current.ui.keymaps.update_all_packages),
p.muted " to update ",
p.highlight(tostring(#state.packages.outdated_packages)),
p.muted(#state.packages.outdated_packages > 1 and " packages " or " package "),
p.Comment(("(%s)"):format(get_outdated_packages_preview(state.packages.outdated_packages))),
}
end
),
},
packages = state.packages.installed,
---@param pkg Package
Expand Down
26 changes: 16 additions & 10 deletions lua/mason/ui/instance.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ local INITIAL_STATE = {
title_prefix = "", -- for animation
},
packages = {
---@type Package[]
outdated_packages = {},
new_versions_check = {
is_checking = false,
current = 0,
Expand Down Expand Up @@ -271,6 +273,8 @@ local function setup_handle(handle)
handle_spawnhandle_change()
mutate_state(function(state)
state.packages.states[handle.package.name] = create_initial_package_state()
state.packages.outdated_packages =
_.filter(_.complement(_.equals(handle.package)), state.packages.outdated_packages)
end)
end

Expand Down Expand Up @@ -426,7 +430,7 @@ local function check_new_package_version(pkg)
mutate_state(function(state)
state.packages.states[pkg.name].is_checking_new_version = true
end)
a.wait(function(resolve, reject)
return a.wait(function(resolve, reject)
pkg:check_new_version(function(success, new_version)
mutate_state(function(state)
state.packages.states[pkg.name].is_checking_new_version = false
Expand Down Expand Up @@ -467,6 +471,7 @@ local function check_new_visible_package_versions()
)(state.packages.installed)

mutate_state(function(state)
state.packages.outdated_packages = {}
state.packages.new_versions_check.is_checking = true
state.packages.new_versions_check.current = 0
state.packages.new_versions_check.total = #installed_visible_packages
Expand All @@ -488,11 +493,14 @@ local function check_new_visible_package_versions()
a.wait_all(_.map(function(package)
return function()
local permit = sem:acquire()
pcall(check_new_package_version, package)
local has_new_version = pcall(check_new_package_version, package)
mutate_state(function(state)
state.packages.new_versions_check.current = state.packages.new_versions_check.current + 1
state.packages.new_versions_check.percentage_complete = state.packages.new_versions_check.current
/ state.packages.new_versions_check.total
if has_new_version then
table.insert(state.packages.outdated_packages, package)
end
end)
permit:forget()
end
Expand Down Expand Up @@ -551,14 +559,12 @@ end

local function update_all_packages()
local state = get_state()
_.each(
function(pkg)
pkg:install(pkg)
end,
_.filter(function(pkg)
return state.packages.visible[pkg.name] and state.packages.states[pkg.name].new_version
end, state.packages.installed)
)
_.each(function(pkg)
pkg:install(pkg)
end, state.packages.outdated_packages)
mutate_state(function(state)
state.packages.outdated_packages = {}
end)
end

local function toggle_install_log(event)
Expand Down