feat: add DAP configuration for Python and enhance debugging setup

This commit is contained in:
sharmaharshitnone 2025-05-30 22:56:04 +05:30
parent 1fdec71945
commit 87611001cf
3 changed files with 228 additions and 16 deletions

View file

@ -23,11 +23,13 @@ return {
-- Add your own debuggers here
'leoluz/nvim-dap-go',
'mfussenegger/nvim-dap-python',
'theHamsta/nvim-dap-virtual-text',
},
keys = {
-- Basic debugging keymaps, feel free to change to your liking!
{
'<F5>',
'g@',
function()
require('dap').continue()
end,
@ -55,7 +57,7 @@ return {
desc = 'Debug: Step Out',
},
{
'<leader>b',
'<leader>.',
function()
require('dap').toggle_breakpoint()
end,
@ -95,6 +97,7 @@ return {
ensure_installed = {
-- Update this to ensure that you have the debuggers for the langs you want
'delve',
'debugpy', -- Python debugger
},
}
@ -120,18 +123,6 @@ return {
},
}
-- Change breakpoint icons
-- vim.api.nvim_set_hl(0, 'DapBreak', { fg = '#e51400' })
-- vim.api.nvim_set_hl(0, 'DapStop', { fg = '#ffcc00' })
-- local breakpoint_icons = vim.g.have_nerd_font
-- and { Breakpoint = '', BreakpointCondition = '', BreakpointRejected = '', LogPoint = '', Stopped = '' }
-- or { Breakpoint = '●', BreakpointCondition = '⊜', BreakpointRejected = '⊘', LogPoint = '◆', Stopped = '⭔' }
-- for type, icon in pairs(breakpoint_icons) do
-- local tp = 'Dap' .. type
-- local hl = (type == 'Stopped') and 'DapStop' or 'DapBreak'
-- vim.fn.sign_define(tp, { text = icon, texthl = hl, numhl = hl })
-- end
dap.listeners.after.event_initialized['dapui_config'] = dapui.open
dap.listeners.before.event_terminated['dapui_config'] = dapui.close
dap.listeners.before.event_exited['dapui_config'] = dapui.close
@ -140,9 +131,51 @@ return {
require('dap-go').setup {
delve = {
-- On Windows delve must be run attached or it crashes.
-- See https://github.com/leoluz/nvim-dap-go/blob/main/README.md#configuring
-- See https://github.com/leoluz/nvim-dap-go/blob/main/README.md\#configuring
detached = vim.fn.has 'win32' == 0,
},
}
-- Python configuration
require('dap-python').setup('python')
require('dap-python').test_runner = 'pytest'
-- Initialize the Python configuration table if it doesn't exist
dap.configurations.python = dap.configurations.python or {
{
-- The first three options are required by nvim-dap
type = 'python'; -- the type here established the link to the adapter definition: `dap.adapters.python`
request = 'launch';
name = "Launch file";
-- Options below are for debugpy, see https://github.com/microsoft/debugpy/wiki/Debug-configuration-settings for supported options
program = "${file}"; -- This configuration will launch the current file if used.
pythonPath = function()
-- debugpy supports launching an application with a different interpreter then the one used to launch debugpy itself.
-- The code below looks for a `venv` or `.venv` folder in the current directly and uses the python within.
-- You could adapt this - to for example use the `VIRTUAL_ENV` environment variable.
local cwd = vim.fn.getcwd()
if vim.fn.executable(cwd .. '/venv/bin/python') == 1 then
return cwd .. '/venv/bin/python'
elseif vim.fn.executable(cwd .. '/.venv/bin/python') == 1 then
return cwd .. '/.venv/bin/python'
else
return '/usr/bin/python'
end
end;
},
}
-- Add a basic Python configuration if none exists
-- if #dap.configurations.python == 0 then
-- table.insert(dap.configurations.python, {
-- type = 'python',
-- request = 'launch',
-- name = 'Launch file',
-- program = '${file}',
-- pythonPath = 'python'
-- })
-- end
end,
}