Skip to content

Commit c524a46

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 c524a46

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

lua/astrocommunity/pack/python/init.lua

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,18 @@ 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"
110-
else
111-
path = path .. "/venv/bin/python"
104+
local path = vim.fn.exepath "debugpy-adapter"
105+
if path == "" then path = vim.fn.exepath "python" end
106+
local ok, mason_registry = pcall(require, "mason-registry")
107+
if ok then
108+
local debugpy = mason_registry.get_package "debugpy"
109+
if debugpy:is_installed() then
110+
path = vim.fn.expand "$MASON/packages/debugpy"
111+
if vim.fn.has "win32" == 1 then
112+
path = path .. "/venv/Scripts/python"
113+
else
114+
path = path .. "/venv/bin/python"
115+
end
112116
end
113117
end
114118
require("dap-python").setup(path, opts)

0 commit comments

Comments
 (0)