From 4a218024294c2477b8a364d715a0295658e2c58f Mon Sep 17 00:00:00 2001 From: Oliver Hartmann Date: Tue, 9 Aug 2022 14:17:01 +0200 Subject: [PATCH 1/4] added python debug session with venv search --- lua/setup/my_dap.lua | 69 +++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 27 deletions(-) diff --git a/lua/setup/my_dap.lua b/lua/setup/my_dap.lua index 7b9ba0d..1926e06 100644 --- a/lua/setup/my_dap.lua +++ b/lua/setup/my_dap.lua @@ -18,33 +18,48 @@ vim.keymap.set('n', '', ":lua require('dap').step_out()", opts) -- detached = true; -- }; -- } --- dap.configurations.python = { --- { --- -- 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 venv = os.getenv("VIRTUAL_ENV") --- return string.format("%s\\bin\\python.exe",venv) --- -- 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; --- }, --- } +local function getVenvSuffix() + if vim.loop.os_uname().sysname == 'Linux' then + return 'bin/python' + elseif vim.loop.os_uname().sysname == 'Windows_NT' then + return 'Scripts/python.exe' + end +end + +function getPythonEnv() + + local venv = os.getenv("VIRTUAL_ENV") + if venv ~= nil then + return string.format("%s\\bin\\python.exe",venv) + end + + local cwd = vim.fn.getcwd() + if vim.fn.executable(cwd .. '/venv/' .. getVenvSuffix()) == 1 then + return cwd .. '/venv/' .. getVenvSuffix() + elseif vim.fn.executable(cwd .. '/.venv/' .. getVenvSuffix()) == 1 then + return cwd .. '/.venv/' .. getVenvSuffix() + else + if vim.loop.os_uname().sysname == 'Linux' then + return '/usr/bin/python' + elseif vim.loop.os_uname().sysname == 'Windows_NT' then + return os.getenv('SCOOP') .. '/apps/python/current/python.exe' + end + end +end + +dap.configurations.python = { + { + -- 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 with venv"; + + -- 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 = getPythonEnv() + }, +} require('dap-python').setup('C:\\Users\\oli\\AppData\\Local\\nvim\\venv_debugpy\\Scripts\\python') table.insert(require('dap').configurations.python, { From 1ba7731c16dd879f7c09de925abee4fe1e4c397d Mon Sep 17 00:00:00 2001 From: Oliver Hartmann Date: Tue, 9 Aug 2022 14:47:05 +0200 Subject: [PATCH 2/4] fixed visual selection in gruvbox baby --- lua/setup/my_gruvbox-baby.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/setup/my_gruvbox-baby.lua b/lua/setup/my_gruvbox-baby.lua index ea8d35f..fe8ce6c 100644 --- a/lua/setup/my_gruvbox-baby.lua +++ b/lua/setup/my_gruvbox-baby.lua @@ -1,2 +1,4 @@ vim.g.gruvbox_baby_telescope_theme = 1 +local colors = require("gruvbox-baby.colors").config() +vim.g.gruvbox_baby_highlights = {Visual = {bg = '#384741'}} vim.cmd[[colorscheme gruvbox-baby]] From 382871be03e03b4d431bac12fb37cab30bc27d36 Mon Sep 17 00:00:00 2001 From: Oliver Hartmann Date: Tue, 9 Aug 2022 14:47:20 +0200 Subject: [PATCH 3/4] auto launch debug ui --- lua/setup/my_dap.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lua/setup/my_dap.lua b/lua/setup/my_dap.lua index 1926e06..8a9fd20 100644 --- a/lua/setup/my_dap.lua +++ b/lua/setup/my_dap.lua @@ -18,6 +18,18 @@ vim.keymap.set('n', '', ":lua require('dap').step_out()", opts) -- detached = true; -- }; -- } +local dap, dapui = require("dap"), require("dapui") +dap.listeners.after.event_initialized["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() + dapui.close() +end + + local function getVenvSuffix() if vim.loop.os_uname().sysname == 'Linux' then return 'bin/python' From 99e11393371c3dc6e003e8e3c89991958ee807ae Mon Sep 17 00:00:00 2001 From: Oliver Hartmann Date: Tue, 9 Aug 2022 14:47:36 +0200 Subject: [PATCH 4/4] cleanup python debug config --- lua/setup/my_dap.lua | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lua/setup/my_dap.lua b/lua/setup/my_dap.lua index 8a9fd20..43bcf4a 100644 --- a/lua/setup/my_dap.lua +++ b/lua/setup/my_dap.lua @@ -61,15 +61,12 @@ end dap.configurations.python = { { - -- The first three options are required by nvim-dap - type = 'python'; -- the type here established the link to the adapter definition: `dap.adapters.python` + type = 'python'; request = 'launch'; name = "Launch file with venv"; - - -- 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 = getPythonEnv() + justMyCode = false; + program = "${file}"; + pythonPath = getPythonEnv(); }, }