diff --git a/after/plugin/dap.lua b/after/plugin/dap.lua index ea086ea..c1d0bd7 100644 --- a/after/plugin/dap.lua +++ b/after/plugin/dap.lua @@ -32,6 +32,27 @@ dap.adapters.lldb = { -- args = { "--interpreter=dap", "--eval-command", "set print pretty on" } } +auto_python_path = 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' + elseif vim.fn.executable('/usr/bin/python') == 1 then + return '/usr/bin/python' + else + return '/bin/python' + end +end + +local python_path = auto_python_path() + +get_path = function() + vim.ui.select({'./venv/bin/python', '/usr/bin/python'}, { + prompt = "Choose a python variable", + }, function(selected) python_path = selected end) +end + dap.adapters.python = function(cb, config) if config.request == 'attach' then ---@diagnostic disable-next-line: undefined-field @@ -49,7 +70,7 @@ dap.adapters.python = function(cb, config) else cb({ type = 'executable', - command = './venv/bin/python', + command = python_path, args = { '-m', 'debugpy.adapter' }, options = { source_filetype = 'python', @@ -69,20 +90,7 @@ dap.configurations.python = { -- 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; - }, + pythonPath = python_path }, } dap.configurations.cpp = { @@ -124,6 +132,7 @@ end vim.keymap.set("n", "tb", "DapToggleBreakpoint",{ desc = '[t]oggle [b]reakpoint' }) vim.keymap.set("n", "dn", "DapNew",{ desc = '[d]ebugger [n]ew' }) +vim.keymap.set("n", "dps", get_path,{ desc = '[d]ebugger [p]ython [s]elect' }) vim.keymap.set("n", "", "DapContinue",{ desc = 'continuej:Da' }) vim.keymap.set("n", "", "DapStepInto",{ desc = 'step into' }) vim.keymap.set("n", "", "DapStepOver",{ desc = 'step over' }) diff --git a/lua/pippy/lazy.lua b/lua/pippy/lazy.lua index f064dfc..70ec9c5 100644 --- a/lua/pippy/lazy.lua +++ b/lua/pippy/lazy.lua @@ -15,6 +15,7 @@ require("lazy").setup({ {"folke/which-key.nvim"}, {"nvim-treesitter/nvim-treesitter", build = ':TSUpdate'}, {"nvim-treesitter/playground"}, + {'stevearc/dressing.nvim'}, { "nvim-neo-tree/neo-tree.nvim", branch = "v3.x",