From 291ab46489946a11d10f2f0abb2033b1d837695e Mon Sep 17 00:00:00 2001 From: Fabrice Mouhartem Date: Sun, 27 Jul 2025 18:55:18 +0200 Subject: [PATCH] feat(DAP): Add DAP configuration - Inspired from https://www.youtube.com/watch?v=lyNfnI-B640 --- lua/lsp.lua | 4 +++- lua/plugins-configure.lua | 42 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/lua/lsp.lua b/lua/lsp.lua index 323dcd8..bb65c4e 100644 --- a/lua/lsp.lua +++ b/lua/lsp.lua @@ -64,8 +64,10 @@ vim.api.nvim_create_autocmd("LspAttach", { require('which-key').add { -- { "c", group = "[C]ode" }, -- { "c_", hidden = true }, - { "d", group = "[D]ocument / [D]iagnostic" }, + { "d", group = "[D]ocument / [D]iagnostic/ [D]ebug" }, { "d_", hidden = true }, + { "ds", group = "[D]ebug [S]tep" }, + { "ds_", hidden = true }, { "g", group = "[G]it" }, { "g_", hidden = true }, { "h", group = "Git [H]unk" }, diff --git a/lua/plugins-configure.lua b/lua/plugins-configure.lua index 2dcf655..b854ae9 100644 --- a/lua/plugins-configure.lua +++ b/lua/plugins-configure.lua @@ -36,7 +36,47 @@ require('lazy').setup({ }, -- DAP: Debug Adapter Protocol - 'mfussenegger/nvim-dap', + { + 'mfussenegger/nvim-dap', + dependencies = { + 'rcarriga/nvim-dap-ui', + 'theHamsta/nvim-dap-virtual-text', + }, + config = function() + local dap = require('dap'); + local ui = require('dapui'); + ui.setup(); + require("nvim-dap-virtual-text").setup(); + + vim.keymap.set("n", "b", dap.toggle_breakpoint, { desc = "Debug [B]reakpoint", silent = true }); + vim.keymap.set("n", "dr", dap.run_to_cursor, { desc = "[D]ebug [R]un to cursor" }); + vim.keymap.set("n", "de", function() + ui.eval(nil, { enter = true }) + end, { desc = "[D]ebug [E]val under cursor", silent = true }); + + -- TODO: add some DAP configs to test + + vim.keymap.set("n", "dc", dap.continue , {desc="[D]ebug [C]ontinue", silent = true}) + vim.keymap.set("n", "dsi", dap.step_into , {desc="[D]ebug [S]tep [I]nto", silent = true}) + vim.keymap.set("n", "dso", dap.step_over , {desc="[D]ebug [S]tep [O]ver", silent = true}) + vim.keymap.set("n", "dsu", dap.step_out , {desc="[D]ebug [S]tep o[U]t", silent = true}) + vim.keymap.set("n", "dsb", dap.step_back , {desc="[D]ebug [S]tep [B]ack", silent = true}) + vim.keymap.set("n", "dr", dap.restart , {desc="[D]ebug [R]estart", silent = true}) + + dap.listeners.before.attach.dapui_config = function() + ui.open() + end + dap.listeners.before.launch.dapui_config = function() + ui.open() + end + dap.listeners.before.event_terminated.dapui_config = function() + ui.close() + end + dap.listeners.before.event_exited.dapui_config = function() + ui.close() + end + end, + }, { -- [[ Autocompletion ]]