commit 1ee18b40611487e50abbec425d74d3af7de7897d
parent 1240d29f8fcf390bcd2cb2fd6e916c629364009a
Author: Evgeni Chasnovski <evgeni.chasnovski@gmail.com>
Date: Tue, 29 Jul 2025 16:00:03 +0300
fix(pack): use 'coxpcall.lua' on non-LuaJIT
Problem: `attempt to yield across metamethod/C-call boundary` error when
trying to use `vim.pack.add()`.
Solution: use `pcall()` variant from 'coxpcall' on non-LuaJIT version of
Lua.
Diffstat:
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/runtime/lua/vim/_async.lua b/runtime/lua/vim/_async.lua
@@ -1,6 +1,7 @@
local M = {}
local max_timeout = 30000
+local copcall = package.loaded.jit and pcall or require('coxpcall').pcall
--- @param thread thread
--- @param on_finish fun(err: string?, ...:any)
@@ -21,7 +22,7 @@ local function resume(thread, on_finish, ...)
--- @cast fn -string
--- @type boolean, string?
- local ok, err = pcall(fn, function(...)
+ local ok, err = copcall(fn, function(...)
resume(thread, on_finish, ...)
end)
diff --git a/runtime/lua/vim/pack.lua b/runtime/lua/vim/pack.lua
@@ -374,6 +374,7 @@ local function new_progress_report(title)
end
local n_threads = 2 * #(uv.cpu_info() or { {} })
+local copcall = package.loaded.jit and pcall or require('coxpcall').pcall
--- Execute function in parallel for each non-errored plugin in the list
--- @param plug_list vim.pack.Plug[]
@@ -390,7 +391,7 @@ local function run_list(plug_list, f, progress_title)
if p.info.err == '' then
--- @async
funs[#funs + 1] = function()
- local ok, err = pcall(f, p) --[[@as string]]
+ local ok, err = copcall(f, p) --[[@as string]]
if not ok then
p.info.err = err --- @as string
end
@@ -458,7 +459,7 @@ local function resolve_version(p)
local tags = git_get_tags(p.path)
if type(version) == 'string' then
local is_branch = vim.tbl_contains(branches, version)
- local is_tag_or_hash = pcall(git_get_hash, version, p.path)
+ local is_tag_or_hash = copcall(git_get_hash, version, p.path)
if not (is_branch or is_tag_or_hash) then
local err = ('`%s` is not a branch/tag/commit. Available:'):format(version)
.. list_in_line('Tags', tags)
@@ -529,7 +530,7 @@ local function checkout(p, timestamp, skip_same_sha)
-- directory or if it is empty.
local doc_dir = vim.fs.joinpath(p.path, 'doc')
vim.fn.delete(vim.fs.joinpath(doc_dir, 'tags'))
- pcall(vim.cmd.helptags, vim.fn.fnameescape(doc_dir))
+ copcall(vim.cmd.helptags, vim.fn.fnameescape(doc_dir))
end
--- @param plug_list vim.pack.Plug[]