From 9f4e06029b1d8cd3bb4438f6b3de6d5c42d2d8d1 Mon Sep 17 00:00:00 2001 From: William Boman Date: Thu, 23 Mar 2023 18:35:49 +0100 Subject: fix(api): refresh registry before installing packages in :MasonInstall (#1128) --- lua/mason/api/command.lua | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'lua') diff --git a/lua/mason/api/command.lua b/lua/mason/api/command.lua index 4be13d86..8fba7ea0 100644 --- a/lua/mason/api/command.lua +++ b/lua/mason/api/command.lua @@ -83,17 +83,8 @@ local function MasonInstall(package_specifiers, opts) opts = opts or {} local Package = require "mason-core.package" local registry = require "mason-registry" - local valid_packages = filter_valid_packages(package_specifiers) local is_headless = #vim.api.nvim_list_uis() == 0 - if is_headless and #valid_packages ~= #package_specifiers then - -- When executing in headless mode we don't allow any of the provided packages to be invalid. - -- This is to avoid things like scripts silently not erroring even if they've provided one or more invalid packages. - return vim.cmd [[1cq]] - elseif #valid_packages == 0 then - return - end - local install_packages = _.map(function(pkg_specifier) local package_name, version = Package.Parse(pkg_specifier) local pkg = registry.get_package(package_name) @@ -106,15 +97,25 @@ local function MasonInstall(package_specifiers, opts) end) if is_headless then + registry.refresh() + local valid_packages = filter_valid_packages(package_specifiers) + if #valid_packages ~= #package_specifiers then + -- When executing in headless mode we don't allow any of the provided packages to be invalid. + -- This is to avoid things like scripts silently not erroring even if they've provided one or more invalid packages. + return vim.cmd [[1cq]] + end 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" + registry.refresh(function() + local valid_packages = filter_valid_packages(package_specifiers) + install_packages(valid_packages) + vim.schedule(function() + ui.set_sticky_cursor "installing-section" + end) end) end end -- cgit v1.2.3-70-g09d2