mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	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.
This commit is contained in:
		| @@ -1,6 +1,7 @@ | |||||||
| local M = {} | local M = {} | ||||||
|  |  | ||||||
| local max_timeout = 30000 | local max_timeout = 30000 | ||||||
|  | local copcall = package.loaded.jit and pcall or require('coxpcall').pcall | ||||||
|  |  | ||||||
| --- @param thread thread | --- @param thread thread | ||||||
| --- @param on_finish fun(err: string?, ...:any) | --- @param on_finish fun(err: string?, ...:any) | ||||||
| @@ -21,7 +22,7 @@ local function resume(thread, on_finish, ...) | |||||||
|     --- @cast fn -string |     --- @cast fn -string | ||||||
|  |  | ||||||
|     --- @type boolean, string? |     --- @type boolean, string? | ||||||
|     local ok, err = pcall(fn, function(...) |     local ok, err = copcall(fn, function(...) | ||||||
|       resume(thread, on_finish, ...) |       resume(thread, on_finish, ...) | ||||||
|     end) |     end) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -374,6 +374,7 @@ local function new_progress_report(title) | |||||||
| end | end | ||||||
|  |  | ||||||
| local n_threads = 2 * #(uv.cpu_info() or { {} }) | 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 | --- Execute function in parallel for each non-errored plugin in the list | ||||||
| --- @param plug_list vim.pack.Plug[] | --- @param plug_list vim.pack.Plug[] | ||||||
| @@ -390,7 +391,7 @@ local function run_list(plug_list, f, progress_title) | |||||||
|     if p.info.err == '' then |     if p.info.err == '' then | ||||||
|       --- @async |       --- @async | ||||||
|       funs[#funs + 1] = function() |       funs[#funs + 1] = function() | ||||||
|         local ok, err = pcall(f, p) --[[@as string]] |         local ok, err = copcall(f, p) --[[@as string]] | ||||||
|         if not ok then |         if not ok then | ||||||
|           p.info.err = err --- @as string |           p.info.err = err --- @as string | ||||||
|         end |         end | ||||||
| @@ -458,7 +459,7 @@ local function resolve_version(p) | |||||||
|   local tags = git_get_tags(p.path) |   local tags = git_get_tags(p.path) | ||||||
|   if type(version) == 'string' then |   if type(version) == 'string' then | ||||||
|     local is_branch = vim.tbl_contains(branches, version) |     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 |     if not (is_branch or is_tag_or_hash) then | ||||||
|       local err = ('`%s` is not a branch/tag/commit. Available:'):format(version) |       local err = ('`%s` is not a branch/tag/commit. Available:'):format(version) | ||||||
|         .. list_in_line('Tags', tags) |         .. list_in_line('Tags', tags) | ||||||
| @@ -529,7 +530,7 @@ local function checkout(p, timestamp, skip_same_sha) | |||||||
|   -- directory or if it is empty. |   -- directory or if it is empty. | ||||||
|   local doc_dir = vim.fs.joinpath(p.path, 'doc') |   local doc_dir = vim.fs.joinpath(p.path, 'doc') | ||||||
|   vim.fn.delete(vim.fs.joinpath(doc_dir, 'tags')) |   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 | end | ||||||
|  |  | ||||||
| --- @param plug_list vim.pack.Plug[] | --- @param plug_list vim.pack.Plug[] | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Evgeni Chasnovski
					Evgeni Chasnovski