From b0d1bb1d7305d5175113f4e6f68f801df8672f03 Mon Sep 17 00:00:00 2001 From: Fabio Scotto di Santolo Date: Mon, 11 Aug 2025 17:01:53 +0200 Subject: [PATCH] Added DAP config --- lazyvim/.config/nvim/lua/plugins/dap.lua | 108 +++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 lazyvim/.config/nvim/lua/plugins/dap.lua diff --git a/lazyvim/.config/nvim/lua/plugins/dap.lua b/lazyvim/.config/nvim/lua/plugins/dap.lua new file mode 100644 index 0000000..0a1991e --- /dev/null +++ b/lazyvim/.config/nvim/lua/plugins/dap.lua @@ -0,0 +1,108 @@ +return { + { + "mfussenegger/nvim-dap", + dependencies = { + "leoluz/nvim-dap-go", + "rcarriga/nvim-dap-ui", + "theHamsta/nvim-dap-virtual-text", + "nvim-neotest/nvim-nio", + "williamboman/mason.nvim", + "jay-babu/mason-nvim-dap.nvim", -- Dependency for managing DAP adapters with Mason + "mfussenegger/nvim-dap-python", -- Dependency for Python debugging + }, + config = function() + local dap = require("dap") + local dapui = require("dapui") + local mason_dap = require("mason-nvim-dap") + + -- Configure mason-nvim-dap to automatically install DAP adapters + mason_dap.setup({ + ensure_installed = { + "delve", -- Go Debugger Adapter + "codelldb", -- C/C++ Debugger Adapter + "debugpy", -- Python Debugger Adapter + }, + handlers = {}, + }) + + -- Set up the DAP UI + dapui.setup() + + -- Set up the Go debugging configurations + require("dap-go").setup() + + -- Set up the Python debugging configurations + require("dap-python").setup() + + -- Configure nvim-dap-virtual-text + require("nvim-dap-virtual-text").setup({ + display_callback = function(variable) + local name = string.lower(variable.name) + local value = string.lower(variable.value) + if name:match("secret") or name:match("api") or value:match("secret") or value:match("api") then + return "*****" + end + + if #variable.value > 15 then + return " " .. string.sub(variable.value, 1, 15) .. "... " + end + + return " " .. variable.value + end, + }) + + -- Configure the CodeLLDB adapter for C/C++ + dap.adapters.codelldb = { + type = "server", + port = "${port}", + executable = { + command = vim.fn.stdpath("data") .. "/mason/bin/codelldb", + args = { "--port", "${port}" }, + }, + } + + -- Define launch configurations for C/C++ + dap.configurations.c = { + { + name = "Launch C", + type = "codelldb", + request = "launch", + program = function() + return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file") + end, + cwd = "${workspaceFolder}", + stopOnEntry = false, + }, + } + + dap.configurations.cpp = dap.configurations.c + + -- Your keyboard shortcuts for debugging + vim.keymap.set("n", "b", dap.toggle_breakpoint) + vim.keymap.set("n", "gb", dap.run_to_cursor) + vim.keymap.set("n", "?", function() + dapui.eval(nil, { enter = true }) + end) + vim.keymap.set("n", "", dap.continue) + vim.keymap.set("n", "", dap.step_into) + vim.keymap.set("n", "", dap.step_over) + vim.keymap.set("n", "", dap.step_out) + vim.keymap.set("n", "", dap.step_back) + vim.keymap.set("n", "", dap.restart) + + -- Listeners to open and close the DAP UI automatically + 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 + end, + }, +}