From a1ba655dee0f89230ea09712e4df981cc3b15bea Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 12 Sep 2024 03:04:33 +0200 Subject: test: spawn_wait() starts a non-RPC Nvim process Problem: Can't use `n.clear()` to test non-RPC `nvim` invocations. So tests end up creating ad-hoc wrappers around `system()` or `jobstart()`. Solution: - Introduce `n.spawn_wait()` - TODO (followup PR): Rename `n.spawn()` and `n.spawn_wait()`. It's misleading that `n.spawn()` returns a RPC session... --- runtime/lua/coxpcall.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'runtime/lua/coxpcall.lua') diff --git a/runtime/lua/coxpcall.lua b/runtime/lua/coxpcall.lua index 6b179f1ef0..75e7a43567 100644 --- a/runtime/lua/coxpcall.lua +++ b/runtime/lua/coxpcall.lua @@ -1,6 +1,10 @@ ------------------------------------------------------------------------------- +-- (Not needed for LuaJIT or Lua 5.2+) +-- -- Coroutine safe xpcall and pcall versions -- +-- https://keplerproject.github.io/coxpcall/ +-- -- Encapsulates the protected calls with a coroutine based loop, so errors can -- be dealed without the usual Lua 5.x pcall/xpcall issues with coroutines -- yielding inside the call to pcall or xpcall. -- cgit From 6aa42e8f92bd8bea49b7b2accfe4ab67a5344e41 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 24 Jan 2025 13:01:25 +0000 Subject: fix: resolve all remaining LuaLS diagnostics --- runtime/lua/coxpcall.lua | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'runtime/lua/coxpcall.lua') diff --git a/runtime/lua/coxpcall.lua b/runtime/lua/coxpcall.lua index 75e7a43567..43e321eac3 100644 --- a/runtime/lua/coxpcall.lua +++ b/runtime/lua/coxpcall.lua @@ -31,22 +31,23 @@ end -- No need to do anything if pcall and xpcall are already safe. if isCoroutineSafe(pcall) and isCoroutineSafe(xpcall) then - copcall = pcall - coxpcall = xpcall + _G.copcall = pcall + _G.coxpcall = xpcall return { pcall = pcall, xpcall = xpcall, running = coroutine.running } end ------------------------------------------------------------------------------- -- Implements xpcall with coroutines ------------------------------------------------------------------------------- -local performResume, handleReturnValue +local performResume local oldpcall, oldxpcall = pcall, xpcall local pack = table.pack or function(...) return {n = select("#", ...), ...} end local unpack = table.unpack or unpack local running = coroutine.running +--- @type table local coromap = setmetatable({}, { __mode = "k" }) -function handleReturnValue(err, co, status, ...) +local function handleReturnValue(err, co, status, ...) if not status then return false, err(debug.traceback(co, (...)), ...) end @@ -61,11 +62,12 @@ function performResume(err, co, ...) return handleReturnValue(err, co, coroutine.resume(co, ...)) end +--- @diagnostic disable-next-line: unused-vararg local function id(trace, ...) return trace end -function coxpcall(f, err, ...) +function _G.coxpcall(f, err, ...) local current = running() if not current then if err == id then @@ -88,6 +90,7 @@ function coxpcall(f, err, ...) end end +--- @param coro? thread local function corunning(coro) if coro ~= nil then assert(type(coro)=="thread", "Bad argument; expected thread, got: "..type(coro)) @@ -105,7 +108,7 @@ end -- Implements pcall with coroutines ------------------------------------------------------------------------------- -function copcall(f, ...) +function _G.copcall(f, ...) return coxpcall(f, id, ...) end -- cgit