Skip to content

Commit 3cdde12

Browse files
committed
refactor(python): make mason optional during dap-python setup
- Change Python debugger adapter path to first check for `debugpy-adapter` before falling back to `python` - Only attempt to get `debugpy` package if Mason registry is available Signed-off-by: Sped0n <hi@sped0n.com>
1 parent d78c9d0 commit 3cdde12

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

lua/astrocommunity/pack/python/init.lua

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,30 @@ return {
101101
dependencies = "mfussenegger/nvim-dap",
102102
ft = "python", -- NOTE: ft: lazy-load on filetype
103103
config = function(_, opts)
104-
local path = vim.fn.exepath "python"
105-
local debugpy = require("mason-registry").get_package "debugpy"
106-
if debugpy:is_installed() then
107-
path = vim.fn.expand "$MASON/packages/debugpy"
108-
if vim.fn.has "win32" == 1 then
109-
path = path .. "/venv/Scripts/python"
104+
local path = function()
105+
local ret = nil
106+
107+
local ok, mason_registry = pcall(require, "mason-registry")
108+
if ok then
109+
local debugpy = mason_registry.get_package "debugpy"
110+
if debugpy:is_installed() then
111+
ret = vim.fn.expand "$MASON/packages/debugpy"
112+
if vim.fn.has "win32" == 1 then
113+
return ret .. "/venv/Scripts/python"
114+
else
115+
return ret .. "/venv/bin/python"
116+
end
117+
end
118+
end
119+
120+
ret = vim.fn.exepath "debugpy-adapter"
121+
if ret == "" then
122+
return vim.fn.exepath "python"
110123
else
111-
path = path .. "/venv/bin/python"
124+
return ret
112125
end
113126
end
114-
require("dap-python").setup(path, opts)
127+
require("dap-python").setup(path(), opts)
115128
end,
116129
},
117130
},

0 commit comments

Comments
 (0)