From 144d2b11cf0950e5b495880bee4a4340363ab572 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Thu, 4 Dec 2025 21:05:24 +0000 Subject: [PATCH] Add nvim-dap & nvim-dap-view Also don't enter insert mode when launching a debug session. --- lua/plugins/debugger.lua | 57 ++++++++++++++++++++++++++++++++++++++++ plugin/autocmds.lua | 13 ++++++--- 2 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 lua/plugins/debugger.lua diff --git a/lua/plugins/debugger.lua b/lua/plugins/debugger.lua new file mode 100644 index 0000000..9abd8a7 --- /dev/null +++ b/lua/plugins/debugger.lua @@ -0,0 +1,57 @@ +return { + 'mfussenegger/nvim-dap', + dependencies = { + 'igorlfs/nvim-dap-view', + 'kbenzie/mason.nvim', + 'jay-babu/mason-nvim-dap.nvim', + 'theHamsta/nvim-dap-virtual-text', + }, + config = function() + local dap = require('dap') + + local debug_adapters = { + 'codelldb', -- C/C++/Rust/Zig + } + + if vim.fn.executable('pip') == 1 then + for _, package in ipairs({ + 'python', -- Python + }) do table.insert(debug_adapters, package) end + end + + if vim.fn.executable('go') == 1 then + for _, package in ipairs({ + 'delve', -- Go + }) do table.insert(debug_adapters, package) end + end + + require("mason-nvim-dap").setup({ + ensure_installed = debug_adapters, + handlers = {}, + }) + + -- UI plugins + require('dap-view').setup({}) + require('nvim-dap-virtual-text').setup({}) + + vim.api.nvim_create_autocmd({ "FileType" }, { + pattern = { + 'dap-float', + }, + callback = function(args) + vim.keymap.set("n", "q", "q", { buffer = args.buf }) + end, + }) + + local widgets = require('dap.ui.widgets') + + vim.keymap.set('n', '', dap.continue) + vim.keymap.set('n', '', dap.terminate) -- Shift-F5 + vim.keymap.set('n', '', dap.toggle_breakpoint) + vim.keymap.set('n', '', vim.cmd.DapViewWatch) -- Shift-F9 + vim.keymap.set('n', '', dap.step_into) + vim.keymap.set('n', '', dap.step_out) -- Shift-F11 + vim.keymap.set('n', '', dap.step_over) + vim.keymap.set('n', 'K', widgets.hover) + end, +} diff --git a/plugin/autocmds.lua b/plugin/autocmds.lua index 7177209..e3dd69f 100644 --- a/plugin/autocmds.lua +++ b/plugin/autocmds.lua @@ -25,10 +25,17 @@ vim.api.nvim_create_autocmd('BufRead', { -- Start terminals in insert mode vim.api.nvim_create_autocmd('TermOpen', { - group = group, pattern = 'term://*', - callback = function() + group = group, + pattern = 'term://*', + callback = function(args) + -- nvim-dap/nvim-dap-view uses terminal buffers in the background which are + -- not visible, don't start insert mode if the dap-type variable exists. + local success, dap_type = pcall(vim.api.nvim_buf_get_var, args.buf, 'dap-type') + if success and dap_type then + return + end vim.cmd.startinsert() - end + end, }) -- Automatically press enter when the terminal process exit successfully