adapters: python (with venv detection) and go (delve)

This commit is contained in:
swaits committed 2026-04-11 16:41:31 -06:00
1 parent 3a65abba0c
commit e2b4d6fbfa
13 files changed
+199

No files matched your search

+1
View File
@@ -0,0 +1 @@
return {}
+1
View File
@@ -0,0 +1 @@
return {}
+32
View File
@@ -0,0 +1,32 @@
local loader = require("tiny-debugger.adapters.init")
local M = {}
function M.register(dap)
local dlv = loader.find_executable({ "dlv" })
if not dlv then return end
loader.register(dap, "delve", {
type = "server",
port = "${port}",
executable = {
command = dlv,
args = { "dap", "-l", "127.0.0.1:${port}" },
},
}, {
{
type = "delve",
request = "launch",
name = "Launch file",
program = "${file}",
},
{
type = "delve",
request = "launch",
name = "Launch package",
program = "./${relativeFileDirname}",
},
}, { "go" })
end
return M
+63
View File
@@ -0,0 +1,63 @@
local config = require("tiny-debugger.config")
local M = {}
local mason_bin = vim.fn.stdpath("data") .. "/mason/bin/"
function M.find_executable(names)
for _, name in ipairs(names) do
-- check PATH
if vim.fn.executable(name) == 1 then
return name
end
-- check mason
local mason_path = mason_bin .. name
if vim.fn.executable(mason_path) == 1 then
return mason_path
end
end
return nil
end
function M.register(dap, name, adapter, configurations, filetypes)
-- don't override user-configured adapters
if dap.adapters[name] then return end
dap.adapters[name] = adapter
for _, ft in ipairs(filetypes) do
if not dap.configurations[ft] then
dap.configurations[ft] = configurations
end
end
end
function M.setup()
if not config.opts.builtin_adapters then return end
local dap = require("dap")
-- load built-in adapter modules
local adapters = {
"python", "go", "c", "javascript", "cs", "java", "kotlin", "php", "ruby", "lua",
}
for _, name in ipairs(adapters) do
local ok, adapter_mod = pcall(require, "tiny-debugger.adapters." .. name)
if ok and adapter_mod.register then
adapter_mod.register(dap)
end
end
-- apply user adapter overrides
for name, adapter_config in pairs(config.opts.adapters) do
if adapter_config.adapter then
dap.adapters[name] = adapter_config.adapter
end
if adapter_config.configurations then
dap.configurations[name] = adapter_config.configurations
end
end
end
return M
+1
View File
@@ -0,0 +1 @@
return {}
@@ -0,0 +1 @@
return {}
+1
View File
@@ -0,0 +1 @@
return {}
+1
View File
@@ -0,0 +1 @@
return {}
+1
View File
@@ -0,0 +1 @@
return {}
+52
View File
@@ -0,0 +1,52 @@
local loader = require("tiny-debugger.adapters.init")
local M = {}
local function find_python()
-- check active virtualenv
local venv = vim.env.VIRTUAL_ENV
if venv then
local path = venv .. "/bin/python"
if vim.fn.executable(path) == 1 then return path end
end
-- check conda
local conda = vim.env.CONDA_PREFIX
if conda then
local path = conda .. "/bin/python"
if vim.fn.executable(path) == 1 then return path end
end
-- probe common venv directories relative to cwd
local cwd = vim.fn.getcwd()
for _, dir in ipairs({ ".venv", "venv", "env", ".env" }) do
local path = cwd .. "/" .. dir .. "/bin/python"
if vim.fn.executable(path) == 1 then return path end
end
-- fallback to system python
if vim.fn.executable("python3") == 1 then return "python3" end
if vim.fn.executable("python") == 1 then return "python" end
return nil
end
function M.register(dap)
local python = find_python()
if not python then return end
loader.register(dap, "debugpy", {
type = "executable",
command = python,
args = { "-m", "debugpy.adapter" },
}, {
{
type = "debugpy",
request = "launch",
name = "Launch file",
program = "${file}",
pythonPath = function() return find_python() end,
},
}, { "python" })
end
return M
+1
View File
@@ -0,0 +1 @@
return {}
+2
View File
@@ -1,12 +1,14 @@
local config = require("tiny-debugger.config")
local mode = require("tiny-debugger.mode")
local breakpoints = require("tiny-debugger.breakpoints")
local adapters = require("tiny-debugger.adapters")
local M = {}
function M.setup(opts)
config.merge(opts)
breakpoints.setup()
adapters.setup()
end
function M.toggle()
+42
View File
@@ -0,0 +1,42 @@
-- tests for adapter loader and path resolution
local loader = require("tiny-debugger.adapters.init")
local function assert_eq(a, b, msg)
if a ~= b then
error(string.format("FAIL: %s — expected %s, got %s", msg, vim.inspect(b), vim.inspect(a)))
end
end
-- test 1: find_executable returns nil for non-existent binaries
assert_eq(loader.find_executable({ "totally-fake-binary-xyz" }), nil, "non-existent binary returns nil")
-- test 2: find_executable finds common system binaries
local found = loader.find_executable({ "sh" })
assert_eq(found ~= nil, true, "find_executable finds sh")
-- test 3: python adapter module loads and has register function
local py = require("tiny-debugger.adapters.python")
assert_eq(type(py.register), "function", "python adapter has register()")
-- test 4: go adapter module loads and has register function
local go = require("tiny-debugger.adapters.go")
assert_eq(type(go.register), "function", "go adapter has register()")
-- test 5: register doesn't override existing adapter
local dap = require("dap")
dap.adapters.test_adapter = { type = "executable", command = "test" }
loader.register(dap, "test_adapter", { type = "executable", command = "new" }, {}, {})
assert_eq(dap.adapters.test_adapter.command, "test", "register doesn't override existing")
dap.adapters.test_adapter = nil
-- test 6: register sets adapter and configs for new adapter
loader.register(dap, "test_new", { type = "executable", command = "test" }, {
{ type = "test_new", request = "launch", name = "test" },
}, { "testlang" })
assert_eq(dap.adapters.test_new.command, "test", "new adapter registered")
assert_eq(#dap.configurations.testlang, 1, "configs registered for filetype")
-- cleanup
dap.adapters.test_new = nil
dap.configurations.testlang = nil
print("ALL ADAPTER TESTS PASSED")