fix: rust adapter shows cargo errors, falls back to prompt instead of nil
This commit is contained in:
1 file changed
+17
-12
@@ -3,33 +3,39 @@ local loader = require("tiny-debugger.adapters.init")
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local function find_rust_binary()
|
local function find_rust_binary()
|
||||||
-- build and capture artifact paths
|
|
||||||
vim.notify("cargo build ...", vim.log.levels.INFO)
|
vim.notify("cargo build ...", vim.log.levels.INFO)
|
||||||
local output = vim.fn.system("cargo build --message-format=json 2>/dev/null")
|
local output = vim.fn.system("cargo build --message-format=json")
|
||||||
if vim.v.shell_error ~= 0 then
|
if vim.v.shell_error ~= 0 then
|
||||||
vim.notify("cargo build failed", vim.log.levels.ERROR)
|
-- extract the human-readable error lines (non-json)
|
||||||
return nil
|
local errors = {}
|
||||||
|
for line in output:gmatch("[^\n]+") do
|
||||||
|
if not line:match("^{") then errors[#errors + 1] = line end
|
||||||
|
end
|
||||||
|
vim.notify("cargo build failed:\n" .. table.concat(errors, "\n"), vim.log.levels.ERROR)
|
||||||
|
return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/target/debug/", "file")
|
||||||
end
|
end
|
||||||
|
|
||||||
local executables = {}
|
local executables = {}
|
||||||
for line in output:gmatch("[^\n]+") do
|
for line in output:gmatch("[^\n]+") do
|
||||||
local ok, msg = pcall(vim.json.decode, line)
|
local ok, msg = pcall(vim.json.decode, line)
|
||||||
if ok and msg.reason == "compiler-artifact" and msg.executable then
|
if ok and msg.reason == "compiler-artifact" and msg.executable then
|
||||||
table.insert(executables, msg.executable)
|
executables[#executables + 1] = msg.executable
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if #executables == 1 then
|
if #executables == 1 then
|
||||||
return executables[1]
|
return executables[1]
|
||||||
elseif #executables > 1 then
|
elseif #executables > 1 then
|
||||||
local choice = vim.fn.inputlist(
|
local items = { "Select executable:" }
|
||||||
vim.list_extend({ "Select executable:" },
|
for i, e in ipairs(executables) do
|
||||||
vim.tbl_map(function(e) return " " .. vim.fn.fnamemodify(e, ":t") end, executables))
|
items[i + 1] = i .. ". " .. vim.fn.fnamemodify(e, ":t")
|
||||||
)
|
end
|
||||||
return choice > 0 and executables[choice] or nil
|
local choice = vim.fn.inputlist(items)
|
||||||
|
if choice > 0 and choice <= #executables then
|
||||||
|
return executables[choice]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- fallback: prompt
|
|
||||||
return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/target/debug/", "file")
|
return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/target/debug/", "file")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -46,7 +52,6 @@ function M.register(dap)
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
-- register adapter once
|
|
||||||
if not dap.adapters.codelldb then
|
if not dap.adapters.codelldb then
|
||||||
dap.adapters.codelldb = adapter
|
dap.adapters.codelldb = adapter
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in new issue
Block a user