From eb220f56b67ffb48bf2ecb11981096c877c9ea0a Mon Sep 17 00:00:00 2001 From: William Boman Date: Mon, 3 Mar 2025 16:10:48 +0100 Subject: fix(ui): fix initializing state --- lua/mason/ui/components/main/package_list.lua | 13 ++++++++++- lua/mason/ui/instance.lua | 32 ++++++++++++++------------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/lua/mason/ui/components/main/package_list.lua b/lua/mason/ui/components/main/package_list.lua index ba05a9bd..8d1dc803 100644 --- a/lua/mason/ui/components/main/package_list.lua +++ b/lua/mason/ui/components/main/package_list.lua @@ -199,8 +199,19 @@ local function Installed(state) Ui.When(state.packages.new_versions_check.is_checking, function() local new_versions_check = state.packages.new_versions_check local styling = new_versions_check.percentage_complete == 1 and p.highlight_block or p.muted_block + local is_all_registries_installed = _.all(_.prop "is_installed", state.info.registries) + local registry_count = #state.info.registries + local text + if registry_count > 1 then + text = p.Comment( + is_all_registries_installed and ("updating %d registries "):format(registry_count) + or ("installing %d registries "):format(registry_count) + ) + else + text = p.Comment(is_all_registries_installed and "updating registry " or "installing registry ") + end return Ui.VirtualTextNode { - p.Comment "updating registry ", + text, styling(("%-4s"):format(math.floor(new_versions_check.percentage_complete * 100) .. "%")), styling((" "):rep(new_versions_check.percentage_complete * 15)), } diff --git a/lua/mason/ui/instance.lua b/lua/mason/ui/instance.lua index 4302685a..3035d6c6 100644 --- a/lua/mason/ui/instance.lua +++ b/lua/mason/ui/instance.lua @@ -607,7 +607,12 @@ local function setup_package(pkg) end mutate_state(function(state) - for _, group in ipairs { state.packages.installed, state.packages.uninstalled, state.packages.failed } do + for _, group in ipairs { + state.packages.installed, + state.packages.uninstalled, + state.packages.failed, + state.packages.outdated_packages, + } do for i, existing_pkg in ipairs(group) do if existing_pkg.name == pkg.name and pkg ~= existing_pkg then -- New package instance (i.e. from a new, updated, registry source). @@ -705,13 +710,19 @@ local function setup_packages(packages) end) end -setup_packages(registry.get_all_packages()) update_registry_info() - -registry.refresh(function() +if registry.sources:is_all_installed() then setup_packages(registry.get_all_packages()) - update_registry_info() -end) +end + +if settings.current.ui.check_outdated_packages_on_open then + a.run(check_new_package_versions, function() end) +else + registry.refresh(function() + setup_packages(registry.get_all_packages()) + update_registry_info() + end) +end registry:on("update", function() setup_packages(registry.get_all_packages()) @@ -726,15 +737,6 @@ window.init { }, } -if settings.current.ui.check_outdated_packages_on_open then - vim.defer_fn( - a.scope(function() - check_new_package_versions() - end), - 100 - ) -end - return { window = window, set_view = function(view) -- cgit v1.2.3-70-g09d2