mirror of
https://github.com/mfussenegger/nvim-dap
synced 2024-09-16 14:24:03 +02:00
Add dap. namespace to luacats class definitions
This commit is contained in:
parent
54f891ae4c
commit
36e72ed2a6
3 changed files with 141 additions and 125 deletions
|
@ -1381,16 +1381,18 @@ request({command}, {arguments}, {callback}) *dap-session:request()*
|
|||
{callback} function Callback called with two parameters: err and result.
|
||||
|
||||
For example, to make a `evaluate` request, you'd use:
|
||||
|
||||
>lua
|
||||
local session = assert(require("dap").session(), "has active session")
|
||||
local arguments = {
|
||||
expression = "1 + 2"
|
||||
}
|
||||
session:request("evaluate", arguments, function(err, result)
|
||||
---@param err dap.ErrorResponse
|
||||
---@param result dap.EvaluateResponse
|
||||
local function on_result(err, result)
|
||||
vim.print(err or "No error")
|
||||
vim.print(result or "No result")
|
||||
end)
|
||||
end
|
||||
session:request("evaluate", arguments, on_result)
|
||||
<
|
||||
|
||||
The method is coroutine aware. If it is running inside a coroutine you can
|
||||
|
|
208
lua/dap.lua
208
lua/dap.lua
|
@ -4,15 +4,22 @@ local M = {}
|
|||
---@diagnostic disable-next-line: deprecated
|
||||
local islist = vim.islist or vim.tbl_islist
|
||||
|
||||
---@type table<number, Session>
|
||||
---@type table<number, dap.Session>
|
||||
local sessions = {}
|
||||
|
||||
---@type Session|nil
|
||||
---@type dap.Session|nil
|
||||
local session = nil
|
||||
local last_run = nil
|
||||
|
||||
|
||||
-- lazy import other modules to have a lower startup footprint
|
||||
local lazy = setmetatable({}, {
|
||||
local lazy = setmetatable({
|
||||
async = nil, --- @module "dap.async"
|
||||
utils = nil, --- @module "dap.utils"
|
||||
progress = nil, --- @module "dap.progress"
|
||||
ui = nil, --- @module "dap.ui"
|
||||
breakpoints = nil, --- @module "dap.breakpoints"
|
||||
}, {
|
||||
__index = function(_, key)
|
||||
return require('dap.' .. key)
|
||||
end
|
||||
|
@ -31,9 +38,11 @@ end
|
|||
---@class dap.Abort
|
||||
M.ABORT = {}
|
||||
|
||||
M.status = function(...)
|
||||
return lazy.progress.status(...)
|
||||
M.status = function()
|
||||
return lazy.progress.status()
|
||||
end
|
||||
|
||||
--- @module "dap.repl"
|
||||
M.repl = setmetatable({}, {
|
||||
__index = function(_, key)
|
||||
return require('dap.repl')[key]
|
||||
|
@ -41,76 +50,76 @@ M.repl = setmetatable({}, {
|
|||
})
|
||||
|
||||
|
||||
---@class DapListeners
|
||||
---@field event_breakpoint table<string, fun(session: Session, body: any)>
|
||||
---@field event_capabilities table<string, fun(session: Session, body: any)>
|
||||
---@field event_continued table<string, fun(session: Session, body: any)>
|
||||
---@field event_exited table<string, fun(session: Session, body: any)>
|
||||
---@field event_initialized table<string, fun(session: Session, body: any)>
|
||||
---@field event_invalidated table<string, fun(session: Session, body: any)>
|
||||
---@field event_loadedSource table<string, fun(session: Session, body: any)>
|
||||
---@field event_memory table<string, fun(session: Session, body: any)>
|
||||
---@field event_module table<string, fun(session: Session, body: any)>
|
||||
---@field event_output table<string, fun(session: Session, body: any)>
|
||||
---@field event_process table<string, fun(session: Session, body: any)>
|
||||
---@field event_progressEnd table<string, fun(session: Session, body: dap.ProgressEndEvent)>
|
||||
---@field event_progressStart table<string, fun(session: Session, body: dap.ProgressStartEvent)>
|
||||
---@field event_progressUpdate table<string, fun(session: Session, body: dap.ProgressUpdateEvent)>
|
||||
---@field event_stopped table<string, fun(session: Session, body: dap.StoppedEvent)>
|
||||
---@field event_terminated table<string, fun(session: Session, body: dap.TerminatedEvent)>
|
||||
---@field event_thread table<string, fun(session: Session, body: any)>
|
||||
---@field attach table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field breakpointLocations table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field completions table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field configurationDone table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field continue table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field dataBreakpointInfo table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field disassemble table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field disconnect table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field evaluate table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field exceptionInfo table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field goto table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field gotoTargets table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field initialize table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field launch table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field loadedSources table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field modules table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field next table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field pause table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field readMemory table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field restart table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field restartFrame table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field reverseContinue table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field scopes table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field setBreakpoints table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field setDataBreakpoints table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field setExceptionBreakpoints table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field setExpression table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field setFunctionBreakpoints table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field setInstructionBreakpoints table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field setVariable table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field source table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field stackTrace table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field stepBack table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field stepIn table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field stepInTargets table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field stepOut table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field terminate table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field terminateThreads table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field threads table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field variables table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@field writeMemory table<string, fun(session: Session, err: any, body: any, request: any, seq: number)>
|
||||
---@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)>
|
||||
|
||||
|
||||
M.listeners = {
|
||||
---@type DapListeners
|
||||
---@type dap.listeners
|
||||
before = setmetatable({}, {
|
||||
__index = function(tbl, key)
|
||||
rawset(tbl, key, {})
|
||||
return rawget(tbl, key)
|
||||
end
|
||||
});
|
||||
---@type DapListeners
|
||||
---@type dap.listeners
|
||||
after = setmetatable({}, {
|
||||
__index = function(tbl, key)
|
||||
rawset(tbl, key, {})
|
||||
|
@ -164,57 +173,57 @@ M.defaults = setmetatable(
|
|||
local DAP_QUICKFIX_TITLE = "DAP Breakpoints"
|
||||
local DAP_QUICKFIX_CONTEXT = DAP_QUICKFIX_TITLE
|
||||
|
||||
---@class Adapter
|
||||
---@class dap.Adapter
|
||||
---@field type string
|
||||
---@field id string|nil
|
||||
---@field options nil|AdapterOptions
|
||||
---@field enrich_config? fun(config: Configuration, on_config: fun(config: Configuration))
|
||||
---@field reverse_request_handlers? table<string, fun(session: Session, request: dap.Request)>
|
||||
---@field options nil|dap.Adapter.options
|
||||
---@field enrich_config? fun(config: dap.Configuration, on_config: fun(config: dap.Configuration))
|
||||
---@field reverse_request_handlers? table<string, fun(session: dap.Session, request: dap.Request)>
|
||||
|
||||
---@class AdapterOptions
|
||||
---@class dap.Adapter.options
|
||||
---@field initialize_timeout_sec nil|number
|
||||
---@field disconnect_timeout_sec nil|number
|
||||
---@field source_filetype nil|string
|
||||
|
||||
---@class ExecutableAdapter : Adapter
|
||||
---@class dap.ExecutableAdapter : dap.Adapter
|
||||
---@field type "executable"
|
||||
---@field command string
|
||||
---@field args string[]
|
||||
---@field options nil|ExecutableOptions
|
||||
---@field options nil|dap.ExecutableAdapter.options
|
||||
|
||||
---@class ExecutableOptions : AdapterOptions
|
||||
---@class dap.ExecutableAdapter.options : dap.Adapter.options
|
||||
---@field env nil|table<string, string>
|
||||
---@field cwd nil|string
|
||||
---@field detached nil|boolean
|
||||
|
||||
---@class ServerOptions : AdapterOptions
|
||||
---@class ServerOptions : dap.Adapter.options
|
||||
---@field max_retries nil|number
|
||||
|
||||
---@class ServerAdapter : Adapter
|
||||
---@class dap.ServerAdapter : dap.Adapter
|
||||
---@field type "server"
|
||||
---@field host string|nil
|
||||
---@field port integer
|
||||
---@field executable nil|ServerAdapterExecutable
|
||||
---@field executable nil|dap.ServerAdapterExecutable
|
||||
---@field options nil|ServerOptions
|
||||
|
||||
|
||||
---@class DapPipeOptions
|
||||
---@class dap.PipeAdapter.options
|
||||
---@field timeout? integer max amount of time in ms to wait between spawning the executable and connecting. This gives the executable time to create the pipe. Defaults to 5000
|
||||
|
||||
---@class PipeAdapter : Adapter
|
||||
---@class dap.PipeAdapter : dap.Adapter
|
||||
---@field type "pipe"
|
||||
---@field pipe string absolute path to the pipe or ${pipe} to use random tmp path
|
||||
---@field executable? ServerAdapterExecutable
|
||||
---@field options? DapPipeOptions
|
||||
---@field executable? dap.ServerAdapterExecutable
|
||||
---@field options? dap.PipeAdapter.options
|
||||
|
||||
---@class ServerAdapterExecutable
|
||||
---@class dap.ServerAdapterExecutable
|
||||
---@field command string
|
||||
---@field args nil|string[]
|
||||
---@field cwd nil|string
|
||||
---@field detached nil|boolean
|
||||
|
||||
|
||||
---@alias Dap.AdapterFactory fun(callback: fun(adapter: Adapter), config: Configuration, parent?: Session)
|
||||
---@alias Dap.AdapterFactory fun(callback: fun(adapter: dap.Adapter), config: dap.Configuration, parent?: dap.Session)
|
||||
|
||||
--- Adapter definitions. See `:help dap-adapter` for more help
|
||||
---
|
||||
|
@ -229,11 +238,11 @@ local DAP_QUICKFIX_CONTEXT = DAP_QUICKFIX_TITLE
|
|||
--- },
|
||||
--- }
|
||||
--- ```
|
||||
---@type table<string, Adapter|Dap.AdapterFactory>
|
||||
---@type table<string, dap.Adapter|Dap.AdapterFactory>
|
||||
M.adapters = {}
|
||||
|
||||
|
||||
---@class Configuration
|
||||
---@class dap.Configuration
|
||||
---@field type string
|
||||
---@field request "launch"|"attach"
|
||||
---@field name string
|
||||
|
@ -253,7 +262,7 @@ M.adapters = {}
|
|||
--- },
|
||||
--- }
|
||||
--- ```
|
||||
---@type table<string, Configuration[]>
|
||||
---@type table<string, dap.Configuration[]>
|
||||
M.configurations = {}
|
||||
|
||||
local providers_mt = {
|
||||
|
@ -263,7 +272,7 @@ local providers_mt = {
|
|||
}
|
||||
M.providers = setmetatable({
|
||||
|
||||
---@type table<string, fun(bufnr: integer): thread|Configuration[]>
|
||||
---@type table<string, fun(bufnr: integer): thread|dap.Configuration[]>
|
||||
configs = {
|
||||
},
|
||||
}, providers_mt)
|
||||
|
@ -395,7 +404,7 @@ local function expand_config_variables(option)
|
|||
return ret
|
||||
end
|
||||
|
||||
---@param lsession Session
|
||||
---@param lsession dap.Session
|
||||
local function add_reset_session_hook(lsession)
|
||||
lsession.on_close['dap.session'] = function(s)
|
||||
assert(s.id == lsession.id, "on_close must not be called with a foreign session")
|
||||
|
@ -510,7 +519,7 @@ end
|
|||
|
||||
--- Get the first stopped session.
|
||||
--- If no session is stopped, it returns the active session or next in sessions.
|
||||
---@return Session|nil
|
||||
---@return dap.Session|nil
|
||||
local function first_stopped_session()
|
||||
if session and session.stopped_thread_id then
|
||||
return session
|
||||
|
@ -529,7 +538,7 @@ end
|
|||
|
||||
|
||||
--- Start a debug session
|
||||
---@param config Configuration
|
||||
---@param config dap.Configuration
|
||||
---@param opts table|nil
|
||||
function M.run(config, opts)
|
||||
assert(
|
||||
|
@ -645,6 +654,7 @@ function M.step_into(opts)
|
|||
if not session then
|
||||
return
|
||||
end
|
||||
---@type {[any]: any}
|
||||
opts = opts or {}
|
||||
local askForTargets = opts.askForTargets
|
||||
opts.askForTargets = nil
|
||||
|
@ -868,8 +878,8 @@ function M.set_breakpoint(condition, hit_condition, log_message)
|
|||
end
|
||||
|
||||
|
||||
---@param lsessions table<integer, Session>
|
||||
---@param fn fun(lsession: Session)
|
||||
---@param lsessions table<integer, dap.Session>
|
||||
---@param fn fun(lsession: dap.Session)
|
||||
local function broadcast(lsessions, fn)
|
||||
for _, lsession in pairs(lsessions) do
|
||||
fn(lsession)
|
||||
|
@ -1088,8 +1098,8 @@ end
|
|||
|
||||
|
||||
--- Connect to a debug adapter via TCP
|
||||
---@param adapter ServerAdapter
|
||||
---@param config Configuration
|
||||
---@param adapter dap.ServerAdapter
|
||||
---@param config dap.Configuration
|
||||
---@param opts table
|
||||
function M.attach(adapter, config, opts)
|
||||
if not config.request then
|
||||
|
@ -1118,8 +1128,8 @@ end
|
|||
|
||||
--- Launch an executable debug adapter and initialize a session
|
||||
---
|
||||
---@param adapter ExecutableAdapter
|
||||
---@param config Configuration
|
||||
---@param adapter dap.ExecutableAdapter
|
||||
---@param config dap.Configuration
|
||||
---@param opts table
|
||||
function M.launch(adapter, config, opts)
|
||||
local s = require('dap.session'):spawn(adapter, opts)
|
||||
|
@ -1152,19 +1162,19 @@ end
|
|||
|
||||
|
||||
--- Currently focused session
|
||||
---@return Session|nil
|
||||
---@return dap.Session|nil
|
||||
function M.session()
|
||||
return session
|
||||
end
|
||||
|
||||
|
||||
---@return table<number, Session>
|
||||
---@return table<number, dap.Session>
|
||||
function M.sessions()
|
||||
return sessions
|
||||
end
|
||||
|
||||
|
||||
---@param new_session Session|nil
|
||||
---@param new_session dap.Session|nil
|
||||
function M.set_session(new_session)
|
||||
if new_session then
|
||||
if new_session.parent == nil then
|
||||
|
|
|
@ -39,11 +39,11 @@ do
|
|||
end
|
||||
|
||||
|
||||
---@class Session
|
||||
---@class dap.Session
|
||||
---@field capabilities dap.Capabilities
|
||||
---@field adapter Adapter
|
||||
---@field adapter dap.Adapter
|
||||
---@field private dirty table<string, boolean>
|
||||
---@field private handlers table<string, fun(self: Session, payload: table)|fun()>
|
||||
---@field private handlers table<string, fun(self: dap.Session, payload: table)|fun()>
|
||||
---@field private message_callbacks table<number, fun(err: nil|dap.ErrorResponse, body: nil|table, seq: number)>
|
||||
---@field private message_requests table<number, any>
|
||||
---@field private client Client
|
||||
|
@ -57,16 +57,16 @@ end
|
|||
---@field ns number Namespace id. Valid during lifecycle of a session
|
||||
---@field sign_group string
|
||||
---@field closed boolean
|
||||
---@field on_close table<string, fun(session: Session)> Handler per plugin-id. Invoked when a session closes (due to terminated event, disconnect or error cases like initialize errors, debug adapter process exit, ...). Session is assumed non-functional at this point and handler can be invoked within luv event loop (not API safe, may require vim.schedule)
|
||||
---@field children table<number, Session>
|
||||
---@field parent Session|nil
|
||||
---@field on_close table<string, fun(session: dap.Session)> Handler per plugin-id. Invoked when a session closes (due to terminated event, disconnect or error cases like initialize errors, debug adapter process exit, ...). Session is assumed non-functional at this point and handler can be invoked within luv event loop (not API safe, may require vim.schedule)
|
||||
---@field children table<number, dap.Session>
|
||||
---@field parent dap.Session|nil
|
||||
|
||||
|
||||
---@class Client
|
||||
---@field close fun(cb: function)
|
||||
---@field write fun(line: string)
|
||||
|
||||
---@class Session
|
||||
---@class dap.Session
|
||||
local Session = {}
|
||||
local session_mt = { __index = Session }
|
||||
|
||||
|
@ -203,7 +203,7 @@ do
|
|||
end
|
||||
|
||||
|
||||
---@param lsession Session
|
||||
---@param lsession dap.Session
|
||||
local function run_in_terminal(lsession, request)
|
||||
local body = request.arguments
|
||||
log.debug('run_in_terminal', body)
|
||||
|
@ -512,7 +512,7 @@ end
|
|||
--- Might load source as a side effect if frame.source has sourceReference ~= 0
|
||||
--- Must be called in a coroutine
|
||||
---
|
||||
---@param session Session
|
||||
---@param session dap.Session
|
||||
---@param frame dap.StackFrame
|
||||
---@return number|nil
|
||||
local function frame_to_bufnr(session, frame)
|
||||
|
@ -539,7 +539,7 @@ local function frame_to_bufnr(session, frame)
|
|||
end
|
||||
|
||||
|
||||
---@param session Session
|
||||
---@param session dap.Session
|
||||
---@param frame dap.StackFrame
|
||||
---@param preserve_focus_hint boolean
|
||||
---@param stopped nil|dap.StoppedEvent
|
||||
|
@ -561,7 +561,7 @@ local function jump_to_frame(session, frame, preserve_focus_hint, stopped)
|
|||
vim.fn.bufload(bufnr)
|
||||
local ok, failure = pcall(vim.fn.sign_place, 0, session.sign_group, 'DapStopped', bufnr, { lnum = frame.line; priority = 22 })
|
||||
if not ok then
|
||||
utils.notify(failure, vim.log.levels.ERROR)
|
||||
utils.notify(tostring(failure), vim.log.levels.ERROR)
|
||||
end
|
||||
local switchbuf = defaults(session).switchbuf or vim.o.switchbuf or 'uselast'
|
||||
jump_to_location(bufnr, frame.line, frame.column, switchbuf, session.filetype)
|
||||
|
@ -734,6 +734,8 @@ function Session:event_terminated(body)
|
|||
self:close()
|
||||
if body and body.restart ~= nil and body.restart ~= false then
|
||||
local config = vim.deepcopy(self.config)
|
||||
|
||||
---@diagnostic disable-next-line: inject-field
|
||||
config.__restart = body.restart
|
||||
-- This will set global session, is this still okay once startDebugging is implemented?
|
||||
dap().run(config, { filetype = self.filetype, new = true })
|
||||
|
@ -1021,7 +1023,7 @@ function Session:handle_body(body)
|
|||
end
|
||||
|
||||
|
||||
---@param self Session
|
||||
---@param self dap.Session
|
||||
local function start_debugging(self, request)
|
||||
local body = request.arguments --[[@as dap.StartDebuggingRequestArguments]]
|
||||
coroutine.wrap(function()
|
||||
|
@ -1043,6 +1045,7 @@ local function start_debugging(self, request)
|
|||
-- Spawning a new executable is likely the wrong thing to do
|
||||
if self.adapter.type == "server" and adapter.executable then
|
||||
adapter = vim.deepcopy(self.adapter)
|
||||
---@diagnostic disable-next-line: inject-field
|
||||
adapter.executable = nil
|
||||
end
|
||||
|
||||
|
@ -1053,7 +1056,7 @@ local function start_debugging(self, request)
|
|||
return
|
||||
end
|
||||
|
||||
---@param session Session
|
||||
---@param session dap.Session
|
||||
local function on_child_session(session)
|
||||
session.parent = self
|
||||
self.children[session.id] = session
|
||||
|
@ -1096,9 +1099,9 @@ local default_reverse_request_handlers = {
|
|||
|
||||
local next_session_id = 1
|
||||
|
||||
---@param adapter Adapter
|
||||
---@param adapter dap.Adapter
|
||||
---@param handle uv.uv_stream_t
|
||||
---@return Session
|
||||
---@return dap.Session
|
||||
local function new_session(adapter, opts, handle)
|
||||
local handlers = {}
|
||||
handlers.after = opts.after
|
||||
|
@ -1166,8 +1169,8 @@ end
|
|||
--- Adds a on_close hook on the session to terminate the executable once the
|
||||
--- session closes.
|
||||
---
|
||||
---@param executable ServerAdapterExecutable
|
||||
---@param session Session
|
||||
---@param executable dap.ServerAdapterExecutable
|
||||
---@param session dap.Session
|
||||
local function spawn_server_executable(executable, session)
|
||||
local cmd = assert(executable.command, "executable of server adapter must have a `command` property")
|
||||
log.debug("Starting debug adapter server executable", executable)
|
||||
|
@ -1222,10 +1225,10 @@ local function spawn_server_executable(executable, session)
|
|||
end
|
||||
|
||||
|
||||
---@param adapter PipeAdapter
|
||||
---@param adapter dap.PipeAdapter
|
||||
---@param opts? table
|
||||
---@param on_connect fun(err?: string)
|
||||
---@return Session
|
||||
---@return dap.Session
|
||||
function Session.pipe(adapter, opts, on_connect)
|
||||
local pipe = assert(uv.new_pipe(), "Must be able to create pipe")
|
||||
local session = new_session(adapter, opts or {}, pipe)
|
||||
|
@ -1358,6 +1361,7 @@ function Session.connect(_, adapter, opts, on_connect)
|
|||
-- getaddrinfo fails for some users with `bad argument #3 to 'getaddrinfo' (Invalid protocol hint)`
|
||||
-- It should generally work with luv 1.42.0 but some still get errors
|
||||
if uv.version() >= 76288 then
|
||||
---@diagnostic disable-next-line: missing-fields
|
||||
local ok, err = pcall(uv.getaddrinfo, host, nil, { protocol = 'tcp' }, on_addresses)
|
||||
if not ok then
|
||||
log.warn(err)
|
||||
|
@ -1370,9 +1374,9 @@ function Session.connect(_, adapter, opts, on_connect)
|
|||
end
|
||||
|
||||
|
||||
---@param adapter ExecutableAdapter
|
||||
---@param adapter dap.ExecutableAdapter
|
||||
---@param opts table|nil
|
||||
---@return Session
|
||||
---@return dap.Session
|
||||
function Session.spawn(_, adapter, opts)
|
||||
log.debug('Spawning debug adapter', adapter)
|
||||
|
||||
|
@ -1511,7 +1515,7 @@ function Session:_pause(thread_id, cb)
|
|||
end
|
||||
|
||||
|
||||
---@param session Session
|
||||
---@param session dap.Session
|
||||
local function clear_running(session, thread_id)
|
||||
vim.fn.sign_unplace(session.sign_group)
|
||||
thread_id = thread_id or session.stopped_thread_id
|
||||
|
@ -1734,7 +1738,7 @@ end
|
|||
|
||||
|
||||
--- Initialize the debug session
|
||||
---@param config Configuration
|
||||
---@param config dap.Configuration
|
||||
function Session:initialize(config)
|
||||
vim.schedule(repl.clear)
|
||||
local adapter_responded = false
|
||||
|
|
Loading…
Reference in a new issue