Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
fix: access of mason package before they are available
Browse files Browse the repository at this point in the history
Wrap `mason.get_package()` call with `registry.refresh()` in order to
make sure the packages are actually loaded, see: williamboman/mason.nvim#1133
  • Loading branch information
pauldub committed Oct 29, 2023
1 parent 15a94ae commit 51412f2
Showing 1 changed file with 37 additions and 34 deletions.
71 changes: 37 additions & 34 deletions lua/doom/modules/langs/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,47 +121,50 @@ module.use_mason_package = function(package_name, success_handler, error_handler
end
profiler.start("mason|using package " .. package_name)
local ok, err = xpcall(function()
local package = mason.get_package(package_name)
if not package:is_installed() then
-- If statusline enabled, push the package to the statusline state
-- So we can provide feedback to user
local statusline = doom.features.statusline
if statusline then
statusline.state.start_mason_package(package_name)
end

package:install()
package:on("install:success", function(handle)
-- Remove package from statusline state to hide it
local registry = require("mason-registry")
registry.refresh(function ()
local package = mason.get_package(package_name)
if not package:is_installed() then
-- If statusline enabled, push the package to the statusline state
-- So we can provide feedback to user
local statusline = doom.features.statusline
if statusline then
statusline.state.finish_mason_package(package_name)
statusline.state.start_mason_package(package_name)
end
vim.schedule(function()
success_handler(handle)

package:install()
package:on("install:success", function(handle)
-- Remove package from statusline state to hide it
if statusline then
statusline.state.finish_mason_package(package_name)
end
vim.schedule(function()
success_handler(handle)
end)
profiler.stop("mason|using package " .. package_name)
end)
profiler.stop("mason|using package " .. package_name)
end)
package:on("install:failed", function(pkg)
-- Remove package from statusline state to hide it
if statusline then
statusline.state.finish_mason_package(package_name)
end
local err = "Mason.nvim install failed. Reason:\n"
if pkg and pkg.stdio and pkg.stdio.buffers and pkg.stdio.buffers.stderr then
for _, line in ipairs(pkg.stdio.buffers.stderr) do
err = err .. line
package:on("install:failed", function(pkg)
-- Remove package from statusline state to hide it
if statusline then
statusline.state.finish_mason_package(package_name)
end
local err = "Mason.nvim install failed. Reason:\n"
if pkg and pkg.stdio and pkg.stdio.buffers and pkg.stdio.buffers.stderr then
for _, line in ipairs(pkg.stdio.buffers.stderr) do
err = err .. line
end
end
end

vim.schedule(function()
on_err(package_name, err)
vim.schedule(function()
on_err(package_name, err)
end)
profiler.stop("mason|using package " .. package_name)
end)
else
profiler.stop("mason|using package " .. package_name)
end)
else
profiler.stop("mason|using package " .. package_name)
success_handler(package, package.get_handle(package))
end
success_handler(package, package.get_handle(package))
end
end)
end, debug.traceback)
if not ok then
profiler.stop("mason|using package " .. package_name)
Expand Down

0 comments on commit 51412f2

Please sign in to comment.