Skip to content

Commit 7389e85

Browse files
committed
Pass parent session to adapter factory
For the `startDebugging` implementation of `vscode-js-debug` the client needs to connect to the parent adapter instance. This change enables an adapter configuration like this: ```lua require("dap").adapters["pwa-node"] = function(on_config, config, parent) local target = config["__pendingTargetId"] if target and parent then local adapter = parent.adapter --[[@as ServerAdapter]] on_config({ type = "server", host = "localhost", port = adapter.port }) else on_config({ type = "server", host = "localhost", port = "${port}", executable = { command = "node", args = {"/path/to/js-debug/src/dapDebugServer.js", "${port}"}, } }) end end ```
1 parent 7e81998 commit 7389e85

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

doc/dap.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,13 @@ Both types support the following additional options:
143143
-- retrieved via a source request.
144144
145145
146-
`dap.adapters.<name>` can also be set to a function which takes two arguments.
147-
This first argument is a callback which must be called with the adapter table.
148-
The second argument is the |dap-configuration| which the user wants to use.
146+
`dap.adapters.<name>` can also be set to a function which takes three arguments:
147+
148+
- A `on_config` callback. This must be called with the actual adapter table.
149+
- The |dap-configuration| which the user wants to use.
150+
- An optional parent session. This is only available if the debug-adapter
151+
wants to start a child-session via a `startDebugging` request.
152+
149153

150154
This can be used to defer the resolving of the values to when a configuration
151155
is used. A use-case for this is starting an adapter asynchronous. For example,

lua/dap.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ local DAP_QUICKFIX_CONTEXT = DAP_QUICKFIX_TITLE
197197
---@field detached nil|boolean
198198

199199

200+
---@alias Dap.AdapterFactory fun(callback: fun(adapter: Adapter), config: Configuration, parent?: Session)
201+
200202
--- Adapter definitions. See `:help dap-adapter` for more help
201203
---
202204
--- An example:
@@ -210,7 +212,7 @@ local DAP_QUICKFIX_CONTEXT = DAP_QUICKFIX_TITLE
210212
--- },
211213
--- }
212214
--- ```
213-
---@type table<string, Adapter|fun(callback: fun(adapter: Adapter), config: Configuration)>
215+
---@type table<string, Adapter|Dap.AdapterFactory>
214216
M.adapters = {}
215217

216218

lua/dap/session.lua

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -871,9 +871,6 @@ do
871871
breakpoints.set_state(bufnr, bp.line, bp)
872872
if not bp.verified then
873873
log.info('Server rejected breakpoint', bp)
874-
if bp.message then
875-
utils.notify(bp.message, vim.log.levels.ERROR)
876-
end
877874
end
878875
end
879876
end
@@ -1014,7 +1011,7 @@ local function start_debugging(self, request)
10141011
config.request = body.request
10151012

10161013
if type(adapter) == "function" then
1017-
adapter(co_resume_schedule(co), config)
1014+
adapter(co_resume_schedule(co), config, self)
10181015
adapter = coroutine.yield()
10191016
end
10201017

@@ -1200,6 +1197,7 @@ function Session.connect(_, adapter, opts, on_connect)
12001197

12011198
if adapter.executable then
12021199
adapter = spawn_server_executable(adapter)
1200+
session.adapter = adapter
12031201
end
12041202
log.debug('Connecting to debug adapter', adapter)
12051203
local max_retries = (adapter.options or {}).max_retries or 14

0 commit comments

Comments
 (0)