nvim/lua/custom/plugins/dap.lua
Jeremie Fraeys 375584629e
Some checks failed
Luacheck / luacheck (push) Failing after 10s
StyLua / stylua (push) Successful in 3s
feat(neotest): add notifications, smart test discovery, fix DAP integration, and improve keymaps
- Add notify function for user feedback on all test operations
- Make <leader>tn smart: runs nearest in test files, finds matching test file from source
- Add same smart logic to <leader>td (debug) and <leader>tw (watch)
- Fix <leader>ts to auto-focus summary window for Enter navigation
- Add summary keymaps for <CR> to expand/jump to tests
- Add nvim-dap as dependency to fix debug strategy
- Fix DAP UI to not auto-close and not enter insert mode
- Fix watch to load test file buffer for LSP attachment
- Make python path detection use VIRTUAL_ENV env var first
- Fix neotest-python adapter configuration
2026-02-09 13:42:17 -05:00

227 lines
5.9 KiB
Lua
Executable file

return {
-- Define language plugins at top level to prevent luarocks installation
{
'mfussenegger/nvim-dap-python',
ft = 'python',
rocks = { enabled = false },
},
{
'leoluz/nvim-dap-go',
ft = 'go',
rocks = { enabled = false },
},
{
'mfussenegger/nvim-dap',
dependencies = {
'rcarriga/nvim-dap-ui',
'nvim-neotest/nvim-nio',
{ 'thehamsta/nvim-dap-virtual-text', opts = {} },
'mfussenegger/nvim-dap-python',
'leoluz/nvim-dap-go',
'jay-babu/mason-nvim-dap.nvim',
},
config = function()
local dap = require('dap')
local dapui = require('dapui')
dapui.setup({
-- Prevent entering insert mode when UI opens
enter = false,
layouts = {
{
elements = {
{ id = 'scopes', size = 0.25 },
{ id = 'breakpoints', size = 0.25 },
{ id = 'stacks', size = 0.25 },
{ id = 'watches', size = 0.25 },
},
size = 40,
position = 'left',
},
{
elements = {
{ id = 'repl', size = 0.5 },
{ id = 'console', size = 0.5 },
},
size = 10,
position = 'bottom',
},
},
})
-- Mason handles debugger installation and configuration
require('mason-nvim-dap').setup({
automatic_installation = true,
ensure_installed = { 'codelldb', 'python', 'delve' },
handlers = {},
})
-- Python setup with proper path detection
local function get_python_path()
-- Check if we're in a virtual environment
local venv = os.getenv('VIRTUAL_ENV')
if venv then
local venv_python = venv .. '/bin/python'
if vim.fn.executable(venv_python) == 1 then
return venv_python
end
end
-- Fall back to system python3 or python
local python3 = vim.fn.exepath('python3')
if python3 ~= '' then
return python3
end
local python = vim.fn.exepath('python')
if python ~= '' then
return python
end
-- Last resort - use system default
return 'python3'
end
require('dap-python').setup(get_python_path())
-- Go setup (helper does the heavy lifting)
require('dap-go').setup()
-- C/C++ configurations
dap.configurations.c = {
{
name = 'Launch',
type = 'codelldb',
request = 'launch',
program = function()
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
end,
cwd = '${workspaceFolder}',
stopOnEntry = false,
},
{
name = 'Launch with ASan',
type = 'codelldb',
request = 'launch',
program = function()
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
end,
cwd = '${workspaceFolder}',
stopOnEntry = false,
env = { ASAN_OPTIONS = 'detect_leaks=1' },
},
}
dap.configurations.cpp = dap.configurations.c
-- Rust configuration
dap.configurations.rust = {
{
name = 'Launch',
type = 'codelldb',
request = 'launch',
program = function()
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/target/debug/', 'file')
end,
cwd = '${workspaceFolder}',
stopOnEntry = false,
},
}
-- Zig configuration
dap.configurations.zig = {
{
name = 'Launch',
type = 'codelldb',
request = 'launch',
program = function()
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/zig-out/bin/', 'file')
end,
cwd = '${workspaceFolder}',
stopOnEntry = false,
},
}
-- Auto-open UI when debugging starts
dap.listeners.after.event_initialized['dapui_config'] = dapui.open
-- Don't auto-close UI - let user close it manually with <leader>du
-- This prevents UI disappearing when running multiple debug sessions
-- Breakpoint signs
vim.fn.sign_define('DapBreakpoint', { text = '🔴', texthl = '', linehl = '', numhl = '' })
vim.fn.sign_define('DapStopped', { text = '➡️', texthl = '', linehl = 'debugPC', numhl = '' })
end,
keys = {
{
'<leader>dc',
function()
require('dap').continue()
end,
desc = 'Debug: Continue',
},
{
'<leader>ds',
function()
require('dap').step_over()
end,
desc = 'Debug: Step Over',
},
{
'<leader>di',
function()
require('dap').step_into()
end,
desc = 'Debug: Step Into',
},
{
'<leader>do',
function()
require('dap').step_out()
end,
desc = 'Debug: Step Out',
},
{
'<leader>db',
function()
require('dap').toggle_breakpoint()
end,
desc = 'Debug: Toggle Breakpoint',
},
{
'<leader>dB',
function()
require('dap').set_breakpoint(vim.fn.input('Breakpoint condition: '))
end,
desc = 'Debug: Conditional Breakpoint',
},
{
'<leader>dr',
function()
require('dap').repl.toggle()
end,
desc = 'Debug: Toggle REPL',
},
{
'<leader>dl',
function()
require('dap').run_last()
end,
desc = 'Debug: Run Last',
},
{
'<leader>du',
function()
require('dapui').toggle()
end,
desc = 'Debug: Toggle UI',
},
{
'<leader>dt',
function()
require('dap').terminate()
end,
desc = 'Debug: Terminate',
},
},
ft = { 'python', 'go', 'rust', 'c', 'cpp', 'zig' },
},
}