Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add :DapNew command start new session #1243

Merged
merged 1 commit into from
Jun 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading