Merge co_resume_schedule and co_resume

This commit is contained in:
Mathias Fussenegger 2024-06-01 23:29:13 +02:00 committed by Mathias Fußenegger
parent b1d400ebb5
commit edb1020bcf
2 changed files with 18 additions and 16 deletions

View file

@ -23,7 +23,7 @@ function M.create_logger(filename)
loggers[filename] = logger
local path_sep = vim.loop.os_uname().sysname == "Windows" and "\\" or "/"
local joinpath = vim.fs.joinpath or function(...)
local joinpath = (vim.fs or {}).joinpath or function(...)
---@diagnostic disable-next-line: deprecated
return table.concat(vim.tbl_flatten{...}, path_sep)
end

View file

@ -93,19 +93,21 @@ local function defaults(session)
return dap().defaults[session.config.type]
end
local function co_resume_schedule(co)
return function(...)
local args = {...}
vim.schedule(function()
coroutine.resume(co, unpack(args))
end)
end
end
local function co_resume(co)
local function coresume(co)
return function(...)
coroutine.resume(co, ...)
if coroutine.status(co) == "suspended" then
coroutine.resume(co, ...)
else
local args = {...}
vim.schedule(function()
assert(
coroutine.status(co) == "suspended",
"Incorrect use of coresume. Callee must have yielded"
)
coroutine.resume(co, unpack(args))
end)
end
end
end
@ -520,7 +522,7 @@ local function frame_to_bufnr(session, frame)
end
local co = coroutine.running()
assert(co, 'Must run in coroutine')
session:source(source, co_resume(co))
session:source(source, coresume(co))
local _, bufnr = coroutine.yield()
return bufnr
end
@ -650,7 +652,7 @@ function Session:event_stopped(stopped)
local co = coroutine.running()
if self.dirty.threads or (stopped.threadId and self.threads[stopped.threadId] == nil) then
self:update_threads(co_resume(co))
self:update_threads(coresume(co))
local err = coroutine.yield()
if err then
utils.notify('Error retrieving threads: ' .. utils.fmt_error(err), vim.log.levels.ERROR)
@ -1037,7 +1039,7 @@ local function start_debugging(self, request)
config.request = body.request
if type(adapter) == "function" then
adapter(co_resume_schedule(co), config, self)
adapter(coresume(co), config, self)
adapter = coroutine.yield()
end
@ -1710,7 +1712,7 @@ function Session:request(command, arguments, callback)
if not callback then
co = coroutine.running()
if co then
callback = co_resume(co)
callback = coresume(co)
else
-- Assume missing callback is intentional.
-- Prevent error logging in Session:handle_body