aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2025-02-15 21:00:35 +0100
committerGitHub <noreply@github.com>2025-02-15 21:00:35 +0100
commit3a444cb7b0cee6b1e2ed31b7e76f37509075dc46 (patch)
tree4cfc848de225c78f0b9ff63a64902203b9c043b7
parentfix(ui): reposition window if border is different than "none" (#1859) (diff)
downloadmason-3a444cb7b0cee6b1e2ed31b7e76f37509075dc46.tar
mason-3a444cb7b0cee6b1e2ed31b7e76f37509075dc46.tar.gz
mason-3a444cb7b0cee6b1e2ed31b7e76f37509075dc46.tar.bz2
mason-3a444cb7b0cee6b1e2ed31b7e76f37509075dc46.tar.lz
mason-3a444cb7b0cee6b1e2ed31b7e76f37509075dc46.tar.xz
mason-3a444cb7b0cee6b1e2ed31b7e76f37509075dc46.tar.zst
mason-3a444cb7b0cee6b1e2ed31b7e76f37509075dc46.zip
fix: avoid calling vim.fn in fast event (#1878)
-rw-r--r--lua/mason-core/package/init.lua3
-rw-r--r--lua/mason-core/platform.lua5
-rw-r--r--tests/mason-core/package/package_spec.lua24
3 files changed, 29 insertions, 3 deletions
diff --git a/lua/mason-core/package/init.lua b/lua/mason-core/package/init.lua
index a5b14548..899370fa 100644
--- a/lua/mason-core/package/init.lua
+++ b/lua/mason-core/package/init.lua
@@ -7,6 +7,7 @@ local a = require "mason-core.async"
local fs = require "mason-core.fs"
local log = require "mason-core.log"
local path = require "mason-core.path"
+local platform = require "mason-core.platform"
local registry = require "mason-registry"
local is_not_nil = _.complement(_.is_nil)
@@ -87,7 +88,7 @@ local PackageMt = { __index = Package }
---@param spec PackageSpec | RegistryPackageSpec
local function validate_spec(spec)
- if vim.fn.has "nvim-0.11" ~= 1 then
+ if platform.cached_features["nvim-0.11"] ~= 1 then
return
end
if is_registry_spec(spec) then
diff --git a/lua/mason-core/platform.lua b/lua/mason-core/platform.lua
index cd958abc..1fe20e5e 100644
--- a/lua/mason-core/platform.lua
+++ b/lua/mason-core/platform.lua
@@ -66,7 +66,7 @@ end)
-- Most of the code that calls into these functions executes outside of the main event loop, where API/fn functions are
-- disabled. We evaluate these immediately here to avoid issues with main loop synchronization.
-local cached_features = {
+M.cached_features = {
["win"] = vim.fn.has "win32",
["win32"] = vim.fn.has "win32",
["win64"] = vim.fn.has "win64",
@@ -74,6 +74,7 @@ local cached_features = {
["darwin"] = vim.fn.has "mac",
["unix"] = vim.fn.has "unix",
["linux"] = vim.fn.has "linux",
+ ["nvim-0.11"] = vim.fn.has "nvim-0.11",
}
---@type fun(env: string): boolean
@@ -104,7 +105,7 @@ local check_env = _.memoize(_.cond {
M.is = setmetatable({}, {
__index = function(__, key)
local os, arch, env = unpack(vim.split(key, "_", { plain = true }))
- if not cached_features[os] or cached_features[os] ~= 1 then
+ if not M.cached_features[os] or M.cached_features[os] ~= 1 then
return false
end
if arch and arch ~= M.arch then
diff --git a/tests/mason-core/package/package_spec.lua b/tests/mason-core/package/package_spec.lua
index 2cd47452..a667cc58 100644
--- a/tests/mason-core/package/package_spec.lua
+++ b/tests/mason-core/package/package_spec.lua
@@ -193,4 +193,28 @@ describe("package", function()
end)
end)
)
+
+ it(
+ "should be able to instantiate package outside of main loop",
+ async_test(function()
+ local dummy = registry.get_package "registry"
+
+ -- Move outside the main loop
+ a.wait(function(resolve)
+ local timer = vim.loop.new_timer()
+ timer:start(0, 0, function()
+ timer:close()
+ resolve()
+ end)
+ end)
+
+ assert.is_true(vim.in_fast_event())
+
+ local pkg = assert.is_not.has_error(function()
+ return Pkg.new(dummy.spec)
+ end)
+
+ assert.same(dummy.spec, pkg.spec)
+ end)
+ )
end)