From d41a3d64a7d3724f09bf07e90d799a837f268cd6 Mon Sep 17 00:00:00 2001 From: Bryan Ramos Date: Thu, 30 Apr 2026 13:28:31 -0400 Subject: [PATCH] feat(debug): add lazy dap setup --- lazy-lock.json | 6 ++ lua/plugins/debug.lua | 145 ++++++++++++++++++++++++++++++++++++++ lua/plugins/disabled.lua | 4 +- lua/plugins/which-key.lua | 1 + 4 files changed, 153 insertions(+), 3 deletions(-) create mode 100644 lua/plugins/debug.lua diff --git a/lazy-lock.json b/lazy-lock.json index f403e7c..6e957d0 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -12,15 +12,21 @@ "log-highlight.nvim": { "branch": "main", "commit": "ca88628f6dd3b9bb46f9a7401669e24cf7de47a4" }, "lualine.nvim": { "branch": "master", "commit": "131a558e13f9f28b15cd235557150ccb23f89286" }, "mason-lspconfig.nvim": { "branch": "main", "commit": "0c2823e0418f3d9230ff8b201c976e84de1cb401" }, + "mason-nvim-dap.nvim": { "branch": "main", "commit": "9a10e096703966335bd5c46c8c875d5b0690dade" }, "mason.nvim": { "branch": "main", "commit": "cb8445f8ce85d957416c106b780efd51c6298f89" }, "neo-tree.nvim": { "branch": "main", "commit": "19d20a99bf0061a5ecc4343d2f09fa713306c965" }, "nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" }, "nvim-cmp": { "branch": "main", "commit": "a1d504892f2bc56c2e79b65c6faded2fd21f3eca" }, + "nvim-dap": { "branch": "master", "commit": "45a69eba683a2c448dd9ecfc4de89511f0646b5f" }, + "nvim-dap-ui": { "branch": "master", "commit": "1a66cabaa4a4da0be107d5eda6d57242f0fe7e49" }, + "nvim-dap-virtual-text": { "branch": "master", "commit": "fbdb48c2ed45f4a8293d0d483f7730d24467ccb6" }, "nvim-lspconfig": { "branch": "master", "commit": "f7e89f3d19fb436e1fbeff3bf4291eef35da94e3" }, "nvim-navic": { "branch": "master", "commit": "f5eba192f39b453675d115351808bd51276d9de5" }, + "nvim-nio": { "branch": "master", "commit": "21f5324bfac14e22ba26553caf69ec76ae8a7662" }, "nvim-treesitter": { "branch": "main", "commit": "df7489eeea351bece7fd0f9c825be5cb6a1438f0" }, "nvim-web-devicons": { "branch": "master", "commit": "4fc505ac7bd7692824a142e96e5f529c133862f8" }, "plenary.nvim": { "branch": "master", "commit": "74b06c6c75e4eeb3108ec01852001636d85a932b" }, + "telescope-dap.nvim": { "branch": "master", "commit": "783366bd6c1e7fa0a5c59c07db37f49c805a28df" }, "telescope.nvim": { "branch": "0.1.x", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, "todo-comments.nvim": { "branch": "main", "commit": "31e3c38ce9b29781e4422fc0322eb0a21f4e8668" }, "treesitter-parser-registry": { "branch": "main", "commit": "6eb15358bb9fc88f0d3401d8538d56652e9bdf3c" }, diff --git a/lua/plugins/debug.lua b/lua/plugins/debug.lua new file mode 100644 index 0000000..1313692 --- /dev/null +++ b/lua/plugins/debug.lua @@ -0,0 +1,145 @@ +local dap_adapters = { + "python", + "codelldb", + "bash", + "js", +} + +return { + { + "mfussenegger/nvim-dap", + dependencies = { + "williamboman/mason.nvim", + "jay-babu/mason-nvim-dap.nvim", + "nvim-neotest/nvim-nio", + "rcarriga/nvim-dap-ui", + "theHamsta/nvim-dap-virtual-text", + "nvim-telescope/telescope-dap.nvim", + }, + cmd = { + "DapContinue", + "DapDisconnect", + "DapInstall", + "DapLoadLaunchJSON", + "DapNew", + "DapRestartFrame", + "DapSetLogLevel", + "DapShowLog", + "DapStepInto", + "DapStepOut", + "DapStepOver", + "DapTerminate", + "DapToggleBreakpoint", + "DapUninstall", + }, + keys = { + { "db", function() require("dap").toggle_breakpoint() end, desc = "Toggle Breakpoint" }, + { "dB", function() require("dap").set_breakpoint(vim.fn.input("Breakpoint condition: ")) end, desc = "Conditional Breakpoint" }, + { "dc", function() require("dap").continue() end, desc = "Continue" }, + { "di", function() require("dap").step_into() end, desc = "Step Into" }, + { "do", function() require("dap").step_over() end, desc = "Step Over" }, + { "dO", function() require("dap").step_out() end, desc = "Step Out" }, + { "dr", function() require("dap").repl.toggle() end, desc = "Toggle REPL" }, + { "dl", function() require("dap").run_last() end, desc = "Run Last" }, + { "du", function() require("dapui").toggle() end, desc = "Toggle Debug UI" }, + { "dt", function() require("dap").terminate() end, desc = "Terminate" }, + { "de", function() require("dapui").eval() end, mode = { "n", "v" }, desc = "Evaluate" }, + { "ds", function() require("telescope").extensions.dap.configurations() end, desc = "Debug Configurations" }, + { "dS", function() require("telescope").extensions.dap.list_breakpoints() end, desc = "Debug Breakpoints" }, + }, + config = function() + local dap = require("dap") + local dapui = require("dapui") + + require("mason").setup() + require("mason-nvim-dap").setup({ + ensure_installed = dap_adapters, + automatic_installation = false, + handlers = {}, + }) + + require("nvim-dap-virtual-text").setup({ + commented = true, + }) + + dapui.setup({ + layouts = { + { + elements = { + { id = "scopes", size = 0.45 }, + { id = "breakpoints", size = 0.15 }, + { id = "stacks", size = 0.25 }, + { id = "watches", size = 0.15 }, + }, + position = "right", + size = 50, + }, + { + elements = { + { id = "repl", size = 0.5 }, + { id = "console", size = 0.5 }, + }, + position = "bottom", + size = 10, + }, + }, + }) + + vim.fn.sign_define("DapBreakpoint", { text = "B", texthl = "DiagnosticSignError" }) + vim.fn.sign_define("DapBreakpointCondition", { text = "C", texthl = "DiagnosticSignWarn" }) + vim.fn.sign_define("DapLogPoint", { text = "L", texthl = "DiagnosticSignInfo" }) + vim.fn.sign_define("DapStopped", { text = ">", texthl = "DiagnosticSignWarn", linehl = "Visual" }) + vim.fn.sign_define("DapBreakpointRejected", { text = "R", texthl = "DiagnosticSignError" }) + + 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 + + dap.adapters["pwa-node"] = { + type = "server", + host = "localhost", + port = "${port}", + executable = { + command = vim.fn.stdpath("data") .. "/mason/bin/js-debug-adapter", + args = { "${port}" }, + }, + } + + local js_configurations = { + { + type = "pwa-node", + request = "launch", + name = "Node: Launch file", + program = "${file}", + cwd = "${workspaceFolder}", + console = "integratedTerminal", + }, + { + type = "pwa-node", + request = "attach", + name = "Node: Attach process", + processId = require("dap.utils").pick_process, + cwd = "${workspaceFolder}", + }, + } + + dap.configurations.javascript = js_configurations + dap.configurations.typescript = js_configurations + dap.configurations.javascriptreact = js_configurations + dap.configurations.typescriptreact = js_configurations + + pcall(function() + require("telescope").load_extension("dap") + end) + end, + }, +} diff --git a/lua/plugins/disabled.lua b/lua/plugins/disabled.lua index 0b7a483..a564707 100644 --- a/lua/plugins/disabled.lua +++ b/lua/plugins/disabled.lua @@ -1,3 +1 @@ -return { - { "jay-babu/mason-nvim-dap.nvim", enabled = false }, -} +return {} diff --git a/lua/plugins/which-key.lua b/lua/plugins/which-key.lua index 94aac0a..d137cdd 100644 --- a/lua/plugins/which-key.lua +++ b/lua/plugins/which-key.lua @@ -82,6 +82,7 @@ return { { "G", group = "Git"}, { "f", group = "Files"}, { "c", group = "Code"}, + { "d", group = "Debug"}, { "g", group = "Goto"}, }, },