adding dressing and keymap to be able to select python environment

This commit is contained in:
Daniel Weber 2024-12-22 21:55:25 -05:00
parent f6861907e6
commit c3d68c8a0a
2 changed files with 25 additions and 15 deletions

View File

@ -32,6 +32,27 @@ dap.adapters.lldb = {
-- args = { "--interpreter=dap", "--eval-command", "set print pretty on" } -- 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) dap.adapters.python = function(cb, config)
if config.request == 'attach' then if config.request == 'attach' then
---@diagnostic disable-next-line: undefined-field ---@diagnostic disable-next-line: undefined-field
@ -49,7 +70,7 @@ dap.adapters.python = function(cb, config)
else else
cb({ cb({
type = 'executable', type = 'executable',
command = './venv/bin/python', command = python_path,
args = { '-m', 'debugpy.adapter' }, args = { '-m', 'debugpy.adapter' },
options = { options = {
source_filetype = 'python', 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 -- 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. program = "${file}"; -- This configuration will launch the current file if used.
pythonPath = function() pythonPath = python_path },
-- 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;
},
} }
dap.configurations.cpp = { dap.configurations.cpp = {
@ -124,6 +132,7 @@ end
vim.keymap.set("n", "<leader>tb", "<cmd>DapToggleBreakpoint<CR>",{ desc = '[t]oggle [b]reakpoint' }) vim.keymap.set("n", "<leader>tb", "<cmd>DapToggleBreakpoint<CR>",{ desc = '[t]oggle [b]reakpoint' })
vim.keymap.set("n", "<leader>dn", "<cmd>DapNew<CR>",{ desc = '[d]ebugger [n]ew' }) vim.keymap.set("n", "<leader>dn", "<cmd>DapNew<CR>",{ desc = '[d]ebugger [n]ew' })
vim.keymap.set("n", "<leader>dps", get_path,{ desc = '[d]ebugger [p]ython [s]elect' })
vim.keymap.set("n", "<F1>", "<cmd>DapContinue<CR>",{ desc = 'continuej:Da' }) vim.keymap.set("n", "<F1>", "<cmd>DapContinue<CR>",{ desc = 'continuej:Da' })
vim.keymap.set("n", "<F2>", "<cmd>DapStepInto<CR>",{ desc = 'step into' }) vim.keymap.set("n", "<F2>", "<cmd>DapStepInto<CR>",{ desc = 'step into' })
vim.keymap.set("n", "<F3>", "<cmd>DapStepOver<CR>",{ desc = 'step over' }) vim.keymap.set("n", "<F3>", "<cmd>DapStepOver<CR>",{ desc = 'step over' })

View File

@ -15,6 +15,7 @@ require("lazy").setup({
{"folke/which-key.nvim"}, {"folke/which-key.nvim"},
{"nvim-treesitter/nvim-treesitter", build = ':TSUpdate'}, {"nvim-treesitter/nvim-treesitter", build = ':TSUpdate'},
{"nvim-treesitter/playground"}, {"nvim-treesitter/playground"},
{'stevearc/dressing.nvim'},
{ {
"nvim-neo-tree/neo-tree.nvim", "nvim-neo-tree/neo-tree.nvim",
branch = "v3.x", branch = "v3.x",