@@ -983,6 +983,8 @@ session() *dap.session()*
983983 Returns the currently focused session or nil if no session exists or
984984 has focus.
985985
986+ See | dap-session | for a description of a session object.
987+
986988sessions() *dap.sessions()*
987989 Returns a table with the active top-level debug sessions.
988990 The keys are session ids and the values are the `Session` instances.
@@ -1234,5 +1236,69 @@ pick_process({opts}) *dap.utils.pick_process*
12341236 filter = function(proc) return vim.endswith(proc.name, "sway") end
12351237 })
12361238<
1239+ ==============================================================================
1240+ DAP Session *dap-session*
1241+
1242+ nvim-dap creates a session object per debug session. You can either get the current
1243+ session via | dap.session() | , or get access to one via a listener (| dap-extensions | ).
1244+
1245+ The session object is a low level primitive, used to interact with the debug
1246+ session. This is not indented for regular debug-client users, but rather for
1247+ extension authors, or power users.
1248+
1249+ The session contains methods - functions where the first parameter is the
1250+ session itself. To call them, you can use the method call syntax:
1251+ `obj: function_name ()` , instead of `obj.function_name (obj)` .
1252+ See | lua-function | .
1253+
1254+
1255+ request({command} , {arguments} , {callback} ) *dap-session:request()*
1256+
1257+ Send a request to the debug adapter.
1258+ See the requests section in https://microsoft.github.io/debug-adapter-protocol/specification
1259+ for a list of supported payloads.
1260+
1261+ Parameters:
1262+ {command} string The command to execute
1263+ {arguments} any|nil Arguments
1264+ {callback} function Callback called with two parameters: err and result.
1265+
1266+ For example, to make a `evaluate` request, you'd use:
1267+
1268+ >lua
1269+ local session = assert(require("dap").session(), "has active session")
1270+ local arguments = {
1271+ expression = "1 + 2"
1272+ }
1273+ session:request("evaluate", arguments, function(err, result)
1274+ vim.print(err or "No error")
1275+ vim.print(result or "No result")
1276+ end)
1277+ <
1278+
1279+ The method is coroutine aware. If it is running inside a coroutine you can
1280+ omit the callback and it will default to resume the coroutine with the
1281+ result.
1282+
1283+ An example:
1284+
1285+ >lua
1286+ local session = assert(require("dap").session(), "has active session")
1287+ local arguments = {
1288+ expression = "1 + 2"
1289+ }
1290+ coroutine.wrap(function()
1291+ local err, result = session:request("evaluate", arguments)
1292+ vim.print(err or "No error")
1293+ vim.print(result or "No result")
1294+ end)()
1295+ <
1296+
1297+ This is convenient if you want to make multiple requests as it helps
1298+ prevent callback nesting.
1299+
1300+ Note that `coroutine.wrap ` doesn't propagate errors but you could setup
1301+ error handling via | xpcall() |
1302+
12371303
12381304vim:ft=help
0 commit comments