diff options
| author | William Boman <william@redwill.se> | 2023-05-12 02:01:35 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-12 02:01:35 +0200 |
| commit | e634134312bb936f472468a401c9cae6485ab54b (patch) | |
| tree | 4ce5e521a9b8d8de24075e0b5e4cf08a1ba39e40 /lua | |
| parent | fix(sources): don't skip installation if fixed version is not currently insta... (diff) | |
| download | mason-e634134312bb936f472468a401c9cae6485ab54b.tar mason-e634134312bb936f472468a401c9cae6485ab54b.tar.gz mason-e634134312bb936f472468a401c9cae6485ab54b.tar.bz2 mason-e634134312bb936f472468a401c9cae6485ab54b.tar.lz mason-e634134312bb936f472468a401c9cae6485ab54b.tar.xz mason-e634134312bb936f472468a401c9cae6485ab54b.tar.zst mason-e634134312bb936f472468a401c9cae6485ab54b.zip | |
feat(ui): display "update all" hint (#1296)
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/mason/ui/components/main/package_list.lua | 27 | ||||
| -rw-r--r-- | lua/mason/ui/instance.lua | 26 |
2 files changed, 43 insertions, 10 deletions
diff --git a/lua/mason/ui/components/main/package_list.lua b/lua/mason/ui/components/main/package_list.lua index 55a0fd3d..a90af3e9 100644 --- a/lua/mason/ui/components/main/package_list.lua +++ b/lua/mason/ui/components/main/package_list.lua @@ -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 { @@ -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 diff --git a/lua/mason/ui/instance.lua b/lua/mason/ui/instance.lua index 9db3ed1f..be891af4 100644 --- a/lua/mason/ui/instance.lua +++ b/lua/mason/ui/instance.lua @@ -77,6 +77,8 @@ local INITIAL_STATE = { title_prefix = "", -- for animation }, packages = { + ---@type Package[] + outdated_packages = {}, new_versions_check = { is_checking = false, current = 0, @@ -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 @@ -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 @@ -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 @@ -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 @@ -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) |
