330 lines
10 KiB
Lua
330 lines
10 KiB
Lua
-- Debug Adapter Protocol (DAP) configuration for Go & JS
|
|
-- Uses delve for Go debugging
|
|
-- Loads only when a <leader>d* key is pressed (see keys = {...} below).
|
|
|
|
return {
|
|
-- ─────────────────────────────────────────────────────────────────────────
|
|
-- Core DAP + Go adapter + UI extras
|
|
-- ─────────────────────────────────────────────────────────────────────────
|
|
{
|
|
"mfussenegger/nvim-dap",
|
|
dependencies = {
|
|
-- Fold these under nvim-dap so they share its keys-based lazy trigger
|
|
-- instead of loading eagerly at startup.
|
|
{ "rcarriga/nvim-dap-ui", dependencies = { "nvim-neotest/nvim-nio" } },
|
|
"theHamsta/nvim-dap-virtual-text",
|
|
"jay-babu/mason-nvim-dap.nvim",
|
|
{
|
|
"leoluz/nvim-dap-go",
|
|
-- IMPORTANT: opts is a FUNCTION, not a table literal.
|
|
-- The attach config references require("dap.utils"), which must not run until
|
|
-- nvim-dap is actually loaded.
|
|
opts = function()
|
|
return {
|
|
delve = {
|
|
path = "dlv",
|
|
initialize_timeout_sec = 20,
|
|
port = "${port}",
|
|
build_flags = "",
|
|
},
|
|
dap_configurations = {
|
|
{ type = "go", name = "Debug", request = "launch", program = "${file}" },
|
|
{ type = "go", name = "Debug Test", request = "launch", program = "${file}" },
|
|
{ type = "go", name = "Debug Package", request = "launch", program = "${filDirname}" },
|
|
{
|
|
type = "go",
|
|
name = "Debug test (go.mod)",
|
|
request = "launch",
|
|
mode = "test",
|
|
program = "./${relativeFileDirname}",
|
|
},
|
|
{
|
|
type = "go",
|
|
name = "Attach",
|
|
request = "attach",
|
|
mode = "local",
|
|
processId = require("dap.utils").pick_process,
|
|
},
|
|
},
|
|
}
|
|
end,
|
|
},
|
|
},
|
|
keys = {
|
|
{
|
|
"<leader>dB",
|
|
function()
|
|
require("dap").set_breakpoint(vim.fn.input("Breakpoint condition: "))
|
|
end,
|
|
desc = "Breakpoint Condition",
|
|
},
|
|
{
|
|
"<leader>db",
|
|
function()
|
|
require("dap").toggle_breakpoint()
|
|
end,
|
|
desc = "Toggle Breakpoint",
|
|
},
|
|
{
|
|
"<leader>dc",
|
|
function()
|
|
require("dap").continue()
|
|
end,
|
|
desc = "Continue",
|
|
},
|
|
{
|
|
"<leader>dC",
|
|
function()
|
|
require("dap").run_to_cursor()
|
|
end,
|
|
desc = "Run to Cursor",
|
|
},
|
|
{
|
|
"<leader>dg",
|
|
function()
|
|
require("dap").goto_()
|
|
end,
|
|
desc = "Go to Line (No Execute)",
|
|
},
|
|
{
|
|
"<leader>di",
|
|
function()
|
|
require("dap").step_into()
|
|
end,
|
|
desc = "Step Into",
|
|
},
|
|
{
|
|
"<leader>dj",
|
|
function()
|
|
require("dap").down()
|
|
end,
|
|
desc = "Down",
|
|
},
|
|
{
|
|
"<leader>dk",
|
|
function()
|
|
require("dap").up()
|
|
end,
|
|
desc = "Up",
|
|
},
|
|
{
|
|
"<leader>dO",
|
|
function()
|
|
require("dap").step_over()
|
|
end,
|
|
desc = "Step Over",
|
|
},
|
|
{
|
|
"<leader>dp",
|
|
function()
|
|
require("dap").pause()
|
|
end,
|
|
desc = "Pause",
|
|
},
|
|
{
|
|
"<leader>dr",
|
|
function()
|
|
require("dap").repl.toggle()
|
|
end,
|
|
desc = "Toggle REPL",
|
|
},
|
|
{
|
|
"<leader>ds",
|
|
function()
|
|
require("dap").session()
|
|
end,
|
|
desc = "Session",
|
|
},
|
|
{
|
|
"<leader>dt",
|
|
function()
|
|
require("dap").terminate()
|
|
end,
|
|
desc = "Terminate",
|
|
},
|
|
{
|
|
"<leader>dw",
|
|
function()
|
|
require("dap.ui.widgets").hover()
|
|
end,
|
|
desc = "Widgets",
|
|
},
|
|
-- Go-specific
|
|
{
|
|
"<leader>dT",
|
|
function()
|
|
require("dap-go").debug_test()
|
|
end,
|
|
desc = "Debug Go Test",
|
|
},
|
|
{
|
|
"<leader>dL",
|
|
function()
|
|
require("dap-go").debug_last_test()
|
|
end,
|
|
desc = "Debug Last Go Test",
|
|
},
|
|
},
|
|
},
|
|
|
|
-- -------------------------------------------------------------------------
|
|
-- Zig (+ C/C++) debugging via codelldb
|
|
-- -------------------------------------------------------------------------
|
|
{
|
|
"mfussenegger/nvim-dap",
|
|
ft = { "zig" },
|
|
config = function()
|
|
local dap = require("dap")
|
|
|
|
-- Prefer codelldb on $PATH, fall back to Mason's install location
|
|
local codelldb = vim.fn.exepath("codelldb")
|
|
if codelldb == "" then
|
|
codelldb = vim.fn.stdpath("data") .. "/mason/bin/codelldb"
|
|
end
|
|
|
|
dap.adapters.codelldb = {
|
|
type = "server",
|
|
port = "${port}",
|
|
executable = {
|
|
command = codelldb,
|
|
args = { "--port", "${port}" },
|
|
},
|
|
}
|
|
|
|
dap.configurations.zig = {
|
|
{
|
|
-- Project build (build.zig). Runs `zig build` first so a fresh
|
|
-- debug binary exists, then asks which exec under zig-out/bin to run.
|
|
name = "Launch (zig build)",
|
|
type = "codelldb",
|
|
request = "launch",
|
|
program = function()
|
|
vim.fn.system({ "zig", "build", "--summary", "none" })
|
|
return vim.fn.input("Executable: ", vim.fn.getcwd() .. "/zig-out/bin/", "file")
|
|
end,
|
|
cwd = "${workspaceFolder}",
|
|
stopOnEntry = false,
|
|
args = {},
|
|
},
|
|
{
|
|
-- Single file. Compiles the current .zig with debug info next to it,
|
|
-- then launches that binary.
|
|
name = "Launch (current file)",
|
|
type = "codelldb",
|
|
request = "launch",
|
|
program = function()
|
|
local src = vim.fn.expand("%:p")
|
|
local out = vim.fn.expand("%:p:r")
|
|
vim.fn.system({ "zig", "build-exe", src, "-O", "Debug", "-femit-bin=" .. out })
|
|
return out
|
|
end,
|
|
cwd = "${workspaceFolder}",
|
|
stopOnEntry = false,
|
|
args = {},
|
|
},
|
|
}
|
|
|
|
-- Reuse the same configs for C/C++ buffers - codelldb handles them too
|
|
dap.configurations.c = dap.configurations.zig
|
|
dap.configurations.cpp = dap.configurations.zig
|
|
end,
|
|
},
|
|
-- ─────────────────────────────────────────────────────────────────────────
|
|
-- DAP UI keymaps + auto open/close (the spec itself is loaded as a dep above)
|
|
-- ─────────────────────────────────────────────────────────────────────────
|
|
{
|
|
"rcarriga/nvim-dap-ui",
|
|
keys = {
|
|
{
|
|
"<leader>du",
|
|
function()
|
|
require("dapui").toggle({})
|
|
end,
|
|
desc = "Dap UI",
|
|
},
|
|
{
|
|
"<leader>de",
|
|
function()
|
|
require("dapui").eval()
|
|
end,
|
|
desc = "Eval",
|
|
mode = { "n", "v" },
|
|
},
|
|
},
|
|
opts = {
|
|
layouts = {
|
|
{
|
|
elements = {
|
|
{ id = "scopes", size = 0.25 },
|
|
{ id = "breakpoints", size = 0.25 },
|
|
{ id = "stacks", size = 0.25 },
|
|
{ id = "watches", size = 0.25 },
|
|
},
|
|
position = "left",
|
|
size = 40,
|
|
},
|
|
{
|
|
elements = {
|
|
{ id = "repl", size = 0.5 },
|
|
{ id = "console", size = 0.5 },
|
|
},
|
|
position = "bottom",
|
|
size = 10,
|
|
},
|
|
},
|
|
},
|
|
config = function(_, opts)
|
|
local dap = require("dap")
|
|
local dapui = require("dapui")
|
|
|
|
dapui.setup(opts)
|
|
-- Auto open/close DAP UI on debug session start/end
|
|
dap.listeners.after.event_initialized["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
|
|
end,
|
|
},
|
|
|
|
-- ─────────────────────────────────────────────────────────────────────────
|
|
-- mason-nvim-dap: install DAP adapters via Mason
|
|
-- ─────────────────────────────────────────────────────────────────────────
|
|
-- Note: delve and js-debug-adapter are also listed in mason.lua's
|
|
-- ensure_installed (under "DAP adapters"). Either source
|
|
-- can install them; mason-nvim-dap is preferred when present because it also
|
|
-- auto-registers the adapters with nvim-dap.
|
|
{
|
|
"jay-babu/mason-nvim-dap.nvim",
|
|
opts = {
|
|
ensure_installed = { "python", "delve", "js", "codelldb" },
|
|
},
|
|
},
|
|
|
|
-- ─────────────────────────────────────────────────────────────────────────
|
|
-- Inline variable values during debug sessions
|
|
-- ─────────────────────────────────────────────────────────────────────────
|
|
{
|
|
"theHamsta/nvim-dap-virtual-text",
|
|
opts = {
|
|
enabled = true,
|
|
enabled_commands = true,
|
|
highlight_changed_variables = true,
|
|
highlight_new_as_changed = false,
|
|
show_stop_reason = true,
|
|
commented = false,
|
|
only_first_definition = true,
|
|
all_references = false,
|
|
filter_references_pattern = "<module",
|
|
virt_text_pos = "eol",
|
|
all_frames = false,
|
|
virt_lines = false,
|
|
virt_text_win_col = nil,
|
|
},
|
|
},
|
|
}
|