aboutsummaryrefslogtreecommitdiffstats
path: root/neovim/.config/nvim/lua/plugins/dap-python.lua
diff options
context:
space:
mode:
authorGravatar Tom van der Lee <t0m.vd.l33@gmail.com>2026-09-16 08:47:13 +0200
committerGravatar Tom van der Lee <t0m.vd.l33@gmail.com>2026-09-16 08:47:13 +0200
commita5e8bbeb9d79d905a193e95a39acd29bc37e6c66 (patch)
tree5b42d54e6b91d454bcbac89f7aac42b0863a869d /neovim/.config/nvim/lua/plugins/dap-python.lua
parent6906a9d55928c6250ff106d041b73fdd1ac8aae6 (diff)
downloaddotfiles-a5e8bbeb9d79d905a193e95a39acd29bc37e6c66.tar.gz
dotfiles-a5e8bbeb9d79d905a193e95a39acd29bc37e6c66.tar.bz2
dotfiles-a5e8bbeb9d79d905a193e95a39acd29bc37e6c66.zip
Updated dotfiles
Diffstat (limited to 'neovim/.config/nvim/lua/plugins/dap-python.lua')
-rw-r--r--neovim/.config/nvim/lua/plugins/dap-python.lua71
1 files changed, 71 insertions, 0 deletions
diff --git a/neovim/.config/nvim/lua/plugins/dap-python.lua b/neovim/.config/nvim/lua/plugins/dap-python.lua
new file mode 100644
index 0000000..b61e0f4
--- /dev/null
+++ b/neovim/.config/nvim/lua/plugins/dap-python.lua
@@ -0,0 +1,71 @@
1-- Python launch configs (nvim-dap-python), wired to the debugpy adapter
2-- that mason-nvim-dap.nvim installs (dap.lua). Kept in its own file since
3-- this is the "per-language" half of debugging, parallel to how
4-- ftplugin/python.lua holds Python-only settings.
5return {
6 "mfussenegger/nvim-dap-python",
7 -- Not left to lazy-load off `ft = "python"`: dap.lua's <leader>dc picker
8 -- works from any window (not just a Python buffer) and needs
9 -- dap.adapters.python already registered by the time a config is picked,
10 -- even if no .py buffer has been opened yet this session.
11 lazy = false,
12 -- mason.nvim is listed directly (not just transitively via dap.lua)
13 -- because config() below needs require("mason-registry") to be loadable
14 -- from startup, same reasoning as lazy = false above.
15 dependencies = { "mfussenegger/nvim-dap", "mason-org/mason.nvim" },
16 config = function()
17 local registry = require("mason-registry")
18 local pkg = registry.get_package("debugpy")
19
20 -- debugpy_path is the interpreter that runs the debug *adapter* itself
21 -- (Mason's isolated venv) - it does not control which Python runs your
22 -- script. dap-python defaults that to the active venv/system python3;
23 -- project-specific venvs may need a manual `pythonPath` override in a
24 -- generated launch config later.
25 local debugpy_path = pkg:get_install_path() .. "/venv/bin/python"
26
27 local function setup()
28 require("dap-python").setup(debugpy_path)
29
30 -- nvim-dap-python doesn't expose adapter.options for tuning, and
31 -- nvim-dap's default terminate-request timeout (3s) is tight enough
32 -- that debugpy's real response can arrive just after nvim-dap already
33 -- gave up and moved on ("No callback found" in dap.log) - <leader>dt
34 -- still works, but dap.session() doesn't clear for a few extra
35 -- seconds, so <leader>dc right after can catch it still "active".
36 -- Wrap the adapter dap-python just registered to give it more room.
37 local dap = require("dap")
38 local base_adapter = dap.adapters.python
39 dap.adapters.python = function(cb, config)
40 base_adapter(function(adapter)
41 adapter.options = adapter.options or {}
42 adapter.options.disconnect_timeout_sec = 8
43 cb(adapter)
44 end, config)
45 end
46 end
47
48 if pkg:is_installed() then
49 setup()
50 else
51 -- dap.lua's mason-nvim-dap ensure_installed triggers debugpy's
52 -- install, but that's async - on a fresh machine (or before it
53 -- finishes) debugpy_path doesn't exist on disk yet, and <leader>dc
54 -- would fail with a raw ENOENT from debugpy itself instead of a clear
55 -- message. Wire up the adapter once the install actually completes
56 -- instead of pointing it at a path that isn't there yet.
57 vim.notify(
58 "debugpy not installed yet - dap.lua's ensure_installed should be"
59 .. " installing it now (check :Mason); run :MasonInstall debugpy"
60 .. " if it doesn't show up there. Debugging will work once it's"
61 .. " done.",
62 vim.log.levels.WARN
63 )
64 registry:on("package:install:success", function(installed_pkg)
65 if installed_pkg.name == "debugpy" then
66 setup()
67 end
68 end)
69 end
70 end,
71}