Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add __tostring for dap.ErrorResponse #1406

Merged
merged 3 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/dap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,9 @@ For events, the listeners are called with two arguments:
2. The event payload


Both command and event listeners can return a boolean `true` to remove the
registered listener.

==============================================================================
BUILT-IN CLIENT EVENTS *dap-listeners-ext*

Expand Down
125 changes: 64 additions & 61 deletions lua/dap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,66 +56,69 @@ M.repl = setmetatable({}, {
end
})

---@alias dap.RequestListener<T, U> fun(session: dap.Session, err: dap.ErrorResponse?, response: T, args: U, seq: number):boolean?

---@alias dap.EventListener<T> fun(session: dap.Session, body: T):boolean?

---@class dap.listeners
---@field event_breakpoint table<string, fun(session: dap.Session, body: any)>
---@field event_capabilities table<string, fun(session: dap.Session, body: any)>
---@field event_continued table<string, fun(session: dap.Session, body: any)>
---@field event_exited table<string, fun(session: dap.Session, body: any)>
---@field event_initialized table<string, fun(session: dap.Session, body: any)>
---@field event_invalidated table<string, fun(session: dap.Session, body: any)>
---@field event_loadedSource table<string, fun(session: dap.Session, body: any)>
---@field event_memory table<string, fun(session: dap.Session, body: any)>
---@field event_module table<string, fun(session: dap.Session, body: any)>
---@field event_output table<string, fun(session: dap.Session, body: any)>
---@field event_process table<string, fun(session: dap.Session, body: any)>
---@field event_progressEnd table<string, fun(session: dap.Session, body: dap.ProgressEndEvent)>
---@field event_progressStart table<string, fun(session: dap.Session, body: dap.ProgressStartEvent)>
---@field event_progressUpdate table<string, fun(session: dap.Session, body: dap.ProgressUpdateEvent)>
---@field event_stopped table<string, fun(session: dap.Session, body: dap.StoppedEvent)>
---@field event_terminated table<string, fun(session: dap.Session, body: dap.TerminatedEvent)>
---@field event_thread table<string, fun(session: dap.Session, body: any)>
---@field attach table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field breakpointLocations table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field completions table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field configurationDone table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field continue table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field dataBreakpointInfo table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field disassemble table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field disconnect table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field evaluate table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field exceptionInfo table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field goto table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field gotoTargets table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field initialize table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field launch table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field loadedSources table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field modules table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field next table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field pause table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field readMemory table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field restart table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field restartFrame table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field reverseContinue table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field scopes table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field setBreakpoints table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field setDataBreakpoints table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field setExceptionBreakpoints table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field setExpression table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field setFunctionBreakpoints table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field setInstructionBreakpoints table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field setVariable table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field source table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field stackTrace table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field stepBack table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field stepIn table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field stepInTargets table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field stepOut table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field terminate table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field terminateThreads table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field threads table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field variables table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field writeMemory table<string, fun(session: dap.Session, err: any, body: any, request: any, seq: number)>
---@field event_breakpoint table<string, dap.EventListener<dap.BreakpointEvent>>
---@field event_capabilities table<string, dap.EventListener<any>>
---@field event_continued table<string, dap.EventListener<dap.ContinuedEvent>>
---@field event_exited table<string, dap.EventListener<any>>
---@field event_initialized table<string, dap.EventListener<dap.InitializedEvent>>
---@field event_invalidated table<string, dap.EventListener<any>>
---@field event_loadedSource table<string, dap.EventListener<any>>
---@field event_memory table<string, dap.EventListener<any>>
---@field event_module table<string, dap.EventListener<any>>
---@field event_output table<string, dap.EventListener<dap.OutputEvent>>
---@field event_process table<string, dap.EventListener<any>>
---@field event_progressEnd table<string, dap.EventListener<dap.ProgressEndEvent>>
---@field event_progressStart table<string, dap.EventListener<dap.ProgressStartEvent>>
---@field event_progressUpdate table<string, dap.EventListener<dap.ProgressUpdateEvent>>
---@field event_stopped table<string, dap.EventListener<dap.StoppedEvent>>
---@field event_terminated table<string, dap.EventListener<dap.TerminatedEvent>>
---@field event_thread table<string, dap.EventListener<dap.ThreadEvent>>
---@field attach table<string, dap.RequestListener>
---@field breakpointLocations table<string, dap.RequestListener>
---@field completions table<string, dap.RequestListener<dap.CompletionsResponse, dap.CompletionsArguments>>
---@field configurationDone table<string, dap.RequestListener>
---@field continue table<string, dap.RequestListener>
---@field dataBreakpointInfo table<string, dap.RequestListener>
---@field disassemble table<string, dap.RequestListener>
---@field disconnect table<string, dap.RequestListener<any, dap.DisconnectArguments>>
---@field evaluate table<string, dap.RequestListener<dap.EvaluateResponse, dap.EvaluateArguments>>
---@field exceptionInfo table<string, dap.RequestListener>
---@field goto table<string, dap.RequestListener>
---@field gotoTargets table<string, dap.RequestListener>
---@field initialize table<string, dap.RequestListener>
---@field launch table<string, dap.RequestListener>
---@field loadedSources table<string, dap.RequestListener>
---@field modules table<string, dap.RequestListener>
---@field next table<string, dap.RequestListener>
---@field pause table<string, dap.RequestListener>
---@field readMemory table<string, dap.RequestListener>
---@field restart table<string, dap.RequestListener>
---@field restartFrame table<string, dap.RequestListener>
---@field reverseContinue table<string, dap.RequestListener>
---@field scopes table<string, dap.RequestListener>
---@field setBreakpoints table<string, dap.RequestListener>
---@field setDataBreakpoints table<string, dap.RequestListener>
---@field setExceptionBreakpoints table<string, dap.RequestListener>
---@field setExpression table<string, dap.RequestListener>
---@field setFunctionBreakpoints table<string, dap.RequestListener>
---@field setInstructionBreakpoints table<string, dap.RequestListener>
---@field setVariable table<string, dap.RequestListener>
---@field source table<string, dap.RequestListener>
---@field stackTrace table<string, dap.RequestListener>
---@field stepBack table<string, dap.RequestListener>
---@field stepIn table<string, dap.RequestListener>
---@field stepInTargets table<string, dap.RequestListener>
---@field stepOut table<string, dap.RequestListener>
---@field terminate table<string, dap.RequestListener>
---@field terminateThreads table<string, dap.RequestListener>
---@field threads table<string, dap.RequestListener>
---@field variables table<string, dap.RequestListener<dap.VariableResponse, dap.VariablesArguments>>
---@field writeMemory table<string, dap.RequestListener>


M.listeners = {
Expand Down Expand Up @@ -708,7 +711,7 @@ function M.step_into(opts)
session:request('stepInTargets', { frameId = session.current_frame.id }, function(err, response)
if err then
notify(
'Error on step_into: ' .. lazy.utils.fmt_error(err) .. ' (while requesting stepInTargets)',
'Error on step_into: ' .. tostring(err) .. ' (while requesting stepInTargets)',
vim.log.levels.ERROR
)
return
Expand Down Expand Up @@ -798,7 +801,7 @@ local function terminate(lsession, opts)
local timeout_ms = timeout_sec * 1000
lsession:request_with_timeout('terminate', args, timeout_ms, function(err)
if err then
log():warn(lazy.utils.fmt_error(err))
log():warn(tostring(err))
end
if not lsession.closed then
lsession:close()
Expand Down Expand Up @@ -928,7 +931,7 @@ function M.restart(config, opts)
config = prepare_config(config)
lsession:request('restart', config, function(err0, _)
if err0 then
notify('Error restarting debug adapter: ' .. lazy.utils.fmt_error(err0), vim.log.levels.ERROR)
notify('Error restarting debug adapter: ' .. tostring(err0), vim.log.levels.ERROR)
else
notify('Restarted debug adapter', vim.log.levels.INFO)
end
Expand Down
8 changes: 4 additions & 4 deletions lua/dap/entity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ local function set_expression(_, item, _, context)
}
session:request('setExpression', params, function(err)
if err then
utils.notify('Error on setExpression: ' .. err.message, vim.log.levels.WARN)
utils.notify('Error on setExpression: ' .. tostring(err), vim.log.levels.WARN)
else
session:_request_scopes(session.current_frame)
end
Expand Down Expand Up @@ -354,14 +354,14 @@ function threads_spec.fetch_children(thread, cb)
local params = { threadId = thread.id }
local err, resp = session:request('stackTrace', params)
if err then
utils.notify('Error fetching stackTrace: ' .. utils.fmt_error(err), vim.log.levels.WARN)
utils.notify('Error fetching stackTrace: ' .. tostring(err), vim.log.levels.WARN)
else
thread.frames = resp.stackFrames
end
if not is_stopped then
local err0 = session:request('continue', params)
if err0 then
utils.notify('Error on continue: ' .. utils.fmt_error(err), vim.log.levels.WARN)
utils.notify('Error on continue: ' .. tostring(err0), vim.log.levels.WARN)
else
thread.stopped = false
local progress = require('dap.progress')
Expand Down Expand Up @@ -409,7 +409,7 @@ function threads_spec.compute_actions(info)
thread.stopped = false
session:request('continue', { threadId = thread.id }, function(err)
if err then
utils.notify('Error on continue: ' .. err.message, vim.log.levels.WARN)
utils.notify('Error on continue: ' .. tostring(err), vim.log.levels.WARN)
end
context.refresh()
end)
Expand Down
3 changes: 1 addition & 2 deletions lua/dap/protocol.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
---@meta


---@class dap.ProtocolMessage
---@field seq number
---@field type "request"|"response"|"event"|string


---@class dap.Request: dap.ProtocolMessage
---@field type "request"
---@field command string
Expand Down Expand Up @@ -297,6 +295,7 @@
---@field instructionReference? string
---@field offset? number

---@class dap.InitializedEvent

---@class dap.StoppedEvent
---@field reason "step"|"breakpoint"|"exception"|"pause"|"entry"|"goto"|"function breakpoint"|"data breakpoint"|"instruction breakpoint"|string;
Expand Down
5 changes: 1 addition & 4 deletions lua/dap/repl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,7 @@ end

local function evaluate_handler(err, resp)
if err then
local message = utils.fmt_error(err)
if message then
M.append(message, nil, { newline = false })
end
M.append(tostring(err), nil, { newline = false })
return
end
local layer = ui.layer(repl.buf)
Expand Down
Loading
Loading