diff --git a/plugin/dap.lua b/plugin/dap.lua index 3bfec087..20106cee 100644 --- a/plugin/dap.lua +++ b/plugin/dap.lua @@ -1,4 +1,3 @@ - local api = vim.api if not api.nvim_create_user_command then return @@ -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 })