feat: rust adapter auto-builds via cargo and finds binary
This commit is contained in:
1 file changed
+51
-2
@@ -2,6 +2,37 @@ local loader = require("tiny-debugger.adapters.init")
|
||||
|
||||
local M = {}
|
||||
|
||||
local function find_rust_binary()
|
||||
-- build and capture artifact paths
|
||||
vim.notify("cargo build ...", vim.log.levels.INFO)
|
||||
local output = vim.fn.system("cargo build --message-format=json 2>/dev/null")
|
||||
if vim.v.shell_error ~= 0 then
|
||||
vim.notify("cargo build failed", vim.log.levels.ERROR)
|
||||
return nil
|
||||
end
|
||||
|
||||
local executables = {}
|
||||
for line in output:gmatch("[^\n]+") do
|
||||
local ok, msg = pcall(vim.json.decode, line)
|
||||
if ok and msg.reason == "compiler-artifact" and msg.executable then
|
||||
table.insert(executables, msg.executable)
|
||||
end
|
||||
end
|
||||
|
||||
if #executables == 1 then
|
||||
return executables[1]
|
||||
elseif #executables > 1 then
|
||||
local choice = vim.fn.inputlist(
|
||||
vim.list_extend({ "Select executable:" },
|
||||
vim.tbl_map(function(e) return " " .. vim.fn.fnamemodify(e, ":t") end, executables))
|
||||
)
|
||||
return choice > 0 and executables[choice] or nil
|
||||
end
|
||||
|
||||
-- fallback: prompt
|
||||
return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/target/debug/", "file")
|
||||
end
|
||||
|
||||
function M.register(dap)
|
||||
local codelldb = loader.find_executable({ "codelldb" })
|
||||
if not codelldb then return end
|
||||
@@ -15,7 +46,13 @@ function M.register(dap)
|
||||
},
|
||||
}
|
||||
|
||||
local configurations = {
|
||||
-- register adapter once
|
||||
if not dap.adapters.codelldb then
|
||||
dap.adapters.codelldb = adapter
|
||||
end
|
||||
|
||||
-- C/C++/Swift: prompt for executable path
|
||||
local prompt_config = {
|
||||
{
|
||||
type = "codelldb",
|
||||
request = "launch",
|
||||
@@ -26,8 +63,20 @@ function M.register(dap)
|
||||
cwd = "${workspaceFolder}",
|
||||
},
|
||||
}
|
||||
for _, ft in ipairs({ "c", "cpp", "swift" }) do
|
||||
dap.configurations[ft] = dap.configurations[ft] or prompt_config
|
||||
end
|
||||
|
||||
loader.register(dap, "codelldb", adapter, configurations, { "c", "cpp", "rust", "swift" })
|
||||
-- Rust: cargo build + auto-find binary
|
||||
dap.configurations.rust = dap.configurations.rust or {
|
||||
{
|
||||
type = "codelldb",
|
||||
request = "launch",
|
||||
name = "Cargo build & launch",
|
||||
program = find_rust_binary,
|
||||
cwd = "${workspaceFolder}",
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in new issue
Block a user