mirror of
https://github.com/mfussenegger/nvim-dap
synced 2024-09-16 14:24:03 +02:00
Add :DapNew command start new session
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
This commit is contained in:
parent
09b54e03d4
commit
c18767707d
1 changed files with 42 additions and 1 deletions
|
@ -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 })
|
||||
|
|
Loading…
Reference in a new issue