Public Access
91 lines
3.9 KiB
Lua
91 lines
3.9 KiB
Lua
local dap, dapui = require("dap"), require("dapui")
|
|
|
|
-- Install debug adapters via Mason (same pattern as the LSP tool loop in
|
|
-- plugins.lua). codelldb -> c/cpp/rust, debugpy -> python,
|
|
-- js-debug-adapter -> node/ts. java-debug-adapter is installed by the LSP
|
|
-- ensure loop and wired through jdtls (see lua/lsp.lua).
|
|
local registry = require("mason-registry")
|
|
registry.refresh(function()
|
|
for _, tool in ipairs({ "debugpy", "codelldb", "js-debug-adapter" }) do
|
|
local ok, pkg = pcall(registry.get_package, tool)
|
|
if ok and not pkg:is_installed() then pkg:install() end
|
|
end
|
|
end)
|
|
|
|
dapui.setup()
|
|
require("nvim-dap-virtual-text").setup()
|
|
|
|
-- Auto-wire adapters + default launch configs for every mason-installed
|
|
-- adapter. Empty handlers = use mason-nvim-dap's default handler for all.
|
|
-- To add a language later: install its adapter in the loop above; it is
|
|
-- configured here automatically. Override by defining dap.configurations.<ft>
|
|
-- below this call.
|
|
require("mason-nvim-dap").setup({
|
|
ensure_installed = {},
|
|
automatic_installation = false,
|
|
handlers = {},
|
|
})
|
|
|
|
-- JS/TS (node): mason-nvim-dap ships no default handler for js-debug-adapter,
|
|
-- so wire the pwa-node adapter and launch/attach configs manually.
|
|
dap.adapters["pwa-node"] = {
|
|
type = "server",
|
|
host = "localhost",
|
|
port = "${port}",
|
|
executable = {
|
|
command = "node",
|
|
args = {
|
|
vim.fs.joinpath(vim.fn.stdpath("data"), "mason", "packages",
|
|
"js-debug-adapter", "js-debug", "src", "dapDebugServer.js"),
|
|
"${port}",
|
|
},
|
|
},
|
|
}
|
|
for _, ft in ipairs({ "javascript", "typescript" }) do
|
|
dap.configurations[ft] = {
|
|
{
|
|
type = "pwa-node",
|
|
request = "launch",
|
|
name = "Launch file",
|
|
program = "${file}",
|
|
cwd = "${workspaceFolder}",
|
|
},
|
|
{
|
|
type = "pwa-node",
|
|
request = "attach",
|
|
name = "Attach to process",
|
|
processId = require("dap.utils").pick_process,
|
|
cwd = "${workspaceFolder}",
|
|
},
|
|
}
|
|
end
|
|
|
|
-- Open/close the dap-ui panels automatically with the session.
|
|
dap.listeners.before.attach.dapui_config = function() dapui.open() end
|
|
dap.listeners.before.launch.dapui_config = function() dapui.open() end
|
|
dap.listeners.before.event_terminated.dapui_config = function() dapui.close() end
|
|
dap.listeners.before.event_exited.dapui_config = function() dapui.close() end
|
|
|
|
-- VS Code standard F-keys
|
|
local map = vim.keymap.set
|
|
map("n", "<F5>", dap.continue, { desc = "Debug: continue / start" })
|
|
map("n", "<S-F5>", dap.terminate, { desc = "Debug: stop" })
|
|
map("n", "<C-S-F5>", dap.restart, { desc = "Debug: restart" })
|
|
map("n", "<F6>", dap.pause, { desc = "Debug: pause" })
|
|
map("n", "<F9>", dap.toggle_breakpoint, { desc = "Debug: toggle breakpoint" })
|
|
map("n", "<F10>", dap.step_over, { desc = "Debug: step over" })
|
|
map("n", "<F11>", dap.step_into, { desc = "Debug: step into" })
|
|
map("n", "<S-F11>", dap.step_out, { desc = "Debug: step out" })
|
|
|
|
-- Leader maps (preserve the previous <leader>d* bindings + a few niceties;
|
|
-- discoverable via <C-k> Pick keymaps thanks to desc).
|
|
map("n", "<leader>duo", dapui.open, { desc = "Debug: open UI" })
|
|
map("n", "<leader>duc", dapui.close, { desc = "Debug: close UI" })
|
|
map("n", "<leader>dbp", dap.toggle_breakpoint, { desc = "Debug: toggle breakpoint" })
|
|
map("n", "<leader>drc", dap.run_to_cursor, { desc = "Debug: run to cursor" })
|
|
map("n", "<leader>dr", dap.repl.toggle, { desc = "Debug: toggle REPL" })
|
|
map("n", "<leader>de", function() dapui.eval() end, { desc = "Debug: eval under cursor" })
|
|
map("n", "<leader>dB", function()
|
|
dap.set_breakpoint(vim.fn.input("Breakpoint condition: "))
|
|
end, { desc = "Debug: conditional breakpoint" })
|