From 3454c60c44c43de6327f837a851a3920116efbd4 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Mon, 2 Jun 2025 10:22:39 +0200 Subject: [PATCH] nvim: Add nvim-dap configuration Automatically opens dap-view when in debugging session (and closes when done), sets some breakpoint jump logic and makes the gutter symbols nicer. Adds keybinds for most of the dap operations with `d` where something is the operation (i.e. `c` for continue, `b` for breakpoint and so on). --- nvim/.config/nvim/lazy-lock.json | 3 + nvim/.config/nvim/lua/plugins/testing.lua | 107 +++++++++++++++++++++- 2 files changed, 108 insertions(+), 2 deletions(-) diff --git a/nvim/.config/nvim/lazy-lock.json b/nvim/.config/nvim/lazy-lock.json index ae3021e..bdd0f91 100644 --- a/nvim/.config/nvim/lazy-lock.json +++ b/nvim/.config/nvim/lazy-lock.json @@ -56,6 +56,9 @@ "nvim-FeMaco.lua": { "branch": "main", "commit": "96bbf843595dbe865838b3f2484b73557f34700c" }, "nvim-colorizer.lua": { "branch": "master", "commit": "517df88cf2afb36652830df2c655df2da416a0ae" }, "nvim-coverage": { "branch": "main", "commit": "a939e425e363319d952a6c35fb3f38b34041ded2" }, + "nvim-dap": { "branch": "master", "commit": "6a5bba0ddea5d419a783e170c20988046376090d" }, + "nvim-dap-python": { "branch": "master", "commit": "261ce649d05bc455a29f9636dc03f8cdaa7e0e2c" }, + "nvim-dap-view": { "branch": "main", "commit": "fc0315087a871f9e74ef88559760b81dae81bc6d" }, "nvim-lint": { "branch": "master", "commit": "9dfb77ef6c5092a19502883c02dc5a02ec648729" }, "nvim-lspconfig": { "branch": "master", "commit": "77d3fdfb3554632c7a3b101ded643d422de7626f" }, "nvim-nio": { "branch": "master", "commit": "21f5324bfac14e22ba26553caf69ec76ae8a7662" }, diff --git a/nvim/.config/nvim/lua/plugins/testing.lua b/nvim/.config/nvim/lua/plugins/testing.lua index ab07007..8b9de35 100644 --- a/nvim/.config/nvim/lua/plugins/testing.lua +++ b/nvim/.config/nvim/lua/plugins/testing.lua @@ -94,13 +94,13 @@ return { { "tw", [[lua require('neotest').watch.toggle()]], - desc = "watch current test", + desc = "watch current test toggle", silent = true, }, { "tW", [[lua require('neotest').watch.toggle(vim.fn.expand("%"))]], - desc = "watch current file", + desc = "watch current file toggle", silent = true, }, }, @@ -149,4 +149,107 @@ return { }, }, }, + { + "mfussenegger/nvim-dap", + dependencies = { + -- { + -- "rcarriga/nvim-dap-ui", + -- config = true, + -- keys = { + -- { + -- "sb", + -- function() + -- require("dapui").toggle({}) + -- end, + -- desc = "Dap UI", + -- }, + -- }, + -- }, + { + "igorlfs/nvim-dap-view", + opts = {}, + keys = { + { + "sb", + function() + require("dap-view").toggle() + end, + desc = "Dap UI", + }, + }, + }, + }, + init = function() + if require("core.util").is_available("which-key") then + require("which-key").add({ "d", group = "debug" }) + end + end, + config = function() + local dap, dv = require("dap"), require("dap-view") + dap.listeners.before.attach["dap-view-config"] = function() + dv.open() + end + dap.listeners.before.launch["dap-view-config"] = function() + dv.open() + end + dap.listeners.before.event_terminated["dap-view-config"] = function() + dv.close() + end + dap.listeners.before.event_exited["dap-view-config"] = function() + dv.close() + end + -- Signs + for _, group in pairs({ + "DapBreakpoint", + "DapBreakpointCondition", + "DapBreakpointRejected", + "DapLogPoint", + }) do + vim.fn.sign_define(group, { text = "●", texthl = group }) + end + vim.fn.sign_define("DapStopped", { text = "", texthl = "DapStopped", numhl = "debugPC" }) + -- jump to stopped-at breakpoint if it is visible in a tab or open a new tab + require("dap").defaults.fallback.switchbuf = "usevisible,usetab,newtab" + end, + keys = { + { "dc", require("dap").continue, desc = "continue" }, + { "dt", require("dap").terminate, desc = "terminate" }, + { "dr", require("dap").run_to_cursor, desc = "run to cursor" }, + { "dj", require("dap").step_over, desc = "step over" }, + { "dl", require("dap").step_into, desc = "step into" }, + { "dh", require("dap").step_out, desc = "step out" }, + { "[d", require("dap").up, desc = "DAP up" }, + { "]d", require("dap").down, desc = "DAP down" }, + + { "db", require("dap").toggle_breakpoint, desc = "toggle breakpoint" }, + { + "dB", + function() + vim.ui.input({ prompt = "Breakpoint condition: " }, function(input) + require("dap").set_breakpoint(input) + end) + end, + desc = "set logpoint", + }, + { + "dL", + function() + vim.ui.input({ prompt = "Log point message: " }, function(input) + require("dap").set_breakpoint(nil, nil, input) + end) + end, + desc = "set logpoint", + }, + + { "dk", require("dap.ui.widgets").hover, desc = "hover" }, + }, + }, + { + "mfussenegger/nvim-dap-python", + dependencies = { { "mfussenegger/nvim-dap", optional = true } }, + ft = { "python" }, + config = function() + require("dap-python").setup("debugpy-adapter") + end, + }, }