From 6c228e4b4b653363915fda06113213a17c94fb9e Mon Sep 17 00:00:00 2001 From: Joshua Finch Date: Thu, 29 May 2025 11:24:42 -0500 Subject: [PATCH] fix: Fixing the nvim-dap configuration setup to properly install the python debugpy debugger and set it up for use. --- nvim/lua/plugins.lua | 2 +- nvim/lua/plugins/dap.lua | 72 +++++++++++++++++++++++++++----------- nvim/lua/plugins/mason.lua | 1 - 3 files changed, 53 insertions(+), 22 deletions(-) diff --git a/nvim/lua/plugins.lua b/nvim/lua/plugins.lua index fcb167b..c3f7d8f 100644 --- a/nvim/lua/plugins.lua +++ b/nvim/lua/plugins.lua @@ -19,7 +19,7 @@ require('lazy').setup({ require('plugins/gruvbox'), require('plugins/comment'), require('plugins/dap'), - require('plugins/dap-python'), + -- require('plugins/dap-python'), require('plugins/treesitter'), require('plugins/gitsigns'), require('plugins/luasnip'), diff --git a/nvim/lua/plugins/dap.lua b/nvim/lua/plugins/dap.lua index 250bea7..b62863e 100644 --- a/nvim/lua/plugins/dap.lua +++ b/nvim/lua/plugins/dap.lua @@ -1,6 +1,9 @@ return { 'mfussenegger/nvim-dap', dependencies = { + { + 'jay-babu/mason-nvim-dap.nvim' + }, { 'nvim-neotest/nvim-nio', }, @@ -48,12 +51,6 @@ return { render = { max_type_length = nil, }, - ensure_installed = { - 'codelldb', - 'cpptools', - 'debugpy', - - }, }) end, }, @@ -65,15 +62,32 @@ return { }, }, config = function() + local mason_dap = require('mason-nvim-dap') local dap, dapui = require('dap'), require('dapui') - dap.listeners.after.event_initialized['dapui_config'] = function() + mason_dap.setup({ + ensure_installed = { + 'codelldb', + 'debugpy', + }, + automatic_installation = true, + handlers = { + function(config) + require('mason-nvim-dap').default_setup(config) + end, + } + }) + + dap.listeners.before.attach.dapui_config = function() dapui.open() end - dap.listeners.after.event_terminated['dapui_config'] = function() + 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() + dap.listeners.before.event_exited.dapui_config = function() dapui.close() end @@ -99,17 +113,35 @@ return { } dap.configurations = { - -- rust = { - -- { - -- type = 'gdb', - -- name = 'Debug', - -- request = 'launch', - -- program = function() - -- return vim.fn.getcwd() .. '/target/debug/faultybranches' - -- end, - -- stopAtBeginningOfMainSubprogram = true, - -- }, - -- }, + rust = { + { + type = 'gdb', + name = 'Debug', + request = 'launch', + program = function() + return vim.fn.getcwd() .. '/target/debug/faultybranches' + end, + stopAtBeginningOfMainSubprogram = true, + }, + }, + python = { + { + type = 'python', + request = 'launch', + name = 'Launch file', + program = '${file}', + pythonPath = function() + 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, + } + } } require('dap.ext.vscode').load_launchjs('.launch.json', {}) diff --git a/nvim/lua/plugins/mason.lua b/nvim/lua/plugins/mason.lua index ec1ca1a..0a4bbc5 100644 --- a/nvim/lua/plugins/mason.lua +++ b/nvim/lua/plugins/mason.lua @@ -121,7 +121,6 @@ return { end, dependencies = { 'mason-org/mason-lspconfig.nvim', - 'jay-babu/mason-nvim-dap.nvim', }, lazy = false, }