From 6a39b2f1123fccc6a869eecca1abde1736fcf3a5 Mon Sep 17 00:00:00 2001 From: William Boman Date: Tue, 27 Dec 2022 06:09:24 +0100 Subject: fix(api/command): instantiate UI before package installation (#810) This fixes situations where the UI would be come desynced should a package installation complete immediately (i.e. in the very same event loop as it was started in). --- lua/mason/api/command.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lua') diff --git a/lua/mason/api/command.lua b/lua/mason/api/command.lua index 8cadbc33..3343ea1d 100644 --- a/lua/mason/api/command.lua +++ b/lua/mason/api/command.lua @@ -94,18 +94,20 @@ local function MasonInstall(package_specifiers, opts) return end - ---@type InstallHandle[] - local handles = _.map(function(pkg_specifier) + local install_packages = _.map(function(pkg_specifier) local package_name, version = Package.Parse(pkg_specifier) local pkg = registry.get_package(package_name) return pkg:install { version = version, debug = opts.debug } - end, valid_packages) + end) if is_headless then - join_handles(handles) + join_handles(install_packages(valid_packages)) else local ui = require "mason.ui" ui.open() + -- Important: We start installation of packages _after_ opening the UI. This gives the UI components a chance to + -- register the necessary event handlers in time, avoiding desynced state. + install_packages(valid_packages) vim.schedule(function() ui.set_sticky_cursor "installing-section" end) -- cgit v1.2.3-70-g09d2