Skip to content

Commit

Permalink
Add :DapNew command start new session
Browse files Browse the repository at this point in the history
If no args: calls dap.continue({ new = true })
If args: calls dap.run for each configuration where name=arg

E.g.: `:DapNew celery django`

If config names contain spaces they need to be escaped
  • Loading branch information
mfussenegger committed Jun 1, 2024
1 parent 09b54e0 commit c187677
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion plugin/dap.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

local api = vim.api
if not api.nvim_create_user_command then
return
Expand Down Expand Up @@ -27,6 +26,48 @@ cmd('DapTerminate', function() require('dap').terminate() end, { nargs = 0 })
cmd('DapLoadLaunchJSON', function() require('dap.ext.vscode').load_launchjs() end, { nargs = 0 })
cmd('DapRestartFrame', function() require('dap').restart_frame() end, { nargs = 0 })

local function dapnew(args)
local dap = require("dap")
local fargs = args.fargs
if not next(fargs) then
dap.continue({ new = true })
return
end
local bufnr = api.nvim_get_current_buf()
require("dap.async").run(function()
for _, get_configs in pairs(dap.providers.configs) do
local configs = get_configs(bufnr)
for _, config in ipairs(configs) do
if vim.tbl_contains(fargs, config.name) then
dap.run(config)
end
end
end
end)
end
cmd("DapNew", dapnew, {
nargs = "*",
desc = "Start one or more new debug sessions",
complete = function ()
local bufnr = api.nvim_get_current_buf()
local dap = require("dap")
local candidates = {}
local done = false
require("dap.async").run(function()
for _, get_configs in pairs(dap.providers.configs) do
local configs = get_configs(bufnr)
for _, config in ipairs(configs) do
local name = config.name:gsub(" ", "\\ ")
table.insert(candidates, name)
end
end
done = true
end)
vim.wait(2000, function() return done == true end)
return candidates
end
})


if api.nvim_create_autocmd then
local launchjson_group = api.nvim_create_augroup('dap-launch.json', { clear = true })
Expand Down

0 comments on commit c187677

Please sign in to comment.