fix: rust adapter uses vim.ui.select picker instead of inputlist
This commit is contained in:
1 file changed
+23
-21
@@ -2,17 +2,30 @@ local loader = require("tiny-debugger.adapters.init")
|
|||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local function find_rust_binary()
|
local function pick_executable(executables)
|
||||||
vim.notify("cargo build ...", vim.log.levels.INFO)
|
local co = coroutine.running()
|
||||||
|
if not co then
|
||||||
|
return executables[1]
|
||||||
|
end
|
||||||
|
vim.ui.select(executables, {
|
||||||
|
prompt = "Select executable",
|
||||||
|
format_item = function(path) return vim.fn.fnamemodify(path, ":t") end,
|
||||||
|
}, function(choice)
|
||||||
|
coroutine.resume(co, choice)
|
||||||
|
end)
|
||||||
|
return coroutine.yield()
|
||||||
|
end
|
||||||
|
|
||||||
|
local function cargo_build_and_pick()
|
||||||
|
vim.notify("cargo build ...")
|
||||||
local output = vim.fn.system("cargo build --message-format=json")
|
local output = vim.fn.system("cargo build --message-format=json")
|
||||||
if vim.v.shell_error ~= 0 then
|
if vim.v.shell_error ~= 0 then
|
||||||
-- extract the human-readable error lines (non-json)
|
|
||||||
local errors = {}
|
local errors = {}
|
||||||
for line in output:gmatch("[^\n]+") do
|
for line in output:gmatch("[^\n]+") do
|
||||||
if not line:match("^{") then errors[#errors + 1] = line end
|
if not line:match("^{") then errors[#errors + 1] = line end
|
||||||
end
|
end
|
||||||
vim.notify("cargo build failed:\n" .. table.concat(errors, "\n"), vim.log.levels.ERROR)
|
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")
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local executables = {}
|
local executables = {}
|
||||||
@@ -23,20 +36,9 @@ local function find_rust_binary()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if #executables == 1 then
|
if #executables == 0 then return nil end
|
||||||
return executables[1]
|
if #executables == 1 then return executables[1] end
|
||||||
elseif #executables > 1 then
|
return pick_executable(executables)
|
||||||
local items = { "Select executable:" }
|
|
||||||
for i, e in ipairs(executables) do
|
|
||||||
items[i + 1] = i .. ". " .. vim.fn.fnamemodify(e, ":t")
|
|
||||||
end
|
|
||||||
local choice = vim.fn.inputlist(items)
|
|
||||||
if choice > 0 and choice <= #executables then
|
|
||||||
return executables[choice]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/target/debug/", "file")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.register(dap)
|
function M.register(dap)
|
||||||
@@ -56,7 +58,7 @@ function M.register(dap)
|
|||||||
dap.adapters.codelldb = adapter
|
dap.adapters.codelldb = adapter
|
||||||
end
|
end
|
||||||
|
|
||||||
-- C/C++/Swift: prompt for executable path
|
-- C/C++/Swift: pick from compiled executables in cwd
|
||||||
local prompt_config = {
|
local prompt_config = {
|
||||||
{
|
{
|
||||||
type = "codelldb",
|
type = "codelldb",
|
||||||
@@ -72,13 +74,13 @@ function M.register(dap)
|
|||||||
dap.configurations[ft] = dap.configurations[ft] or prompt_config
|
dap.configurations[ft] = dap.configurations[ft] or prompt_config
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Rust: cargo build + auto-find binary
|
-- Rust: cargo build + picker
|
||||||
dap.configurations.rust = dap.configurations.rust or {
|
dap.configurations.rust = dap.configurations.rust or {
|
||||||
{
|
{
|
||||||
type = "codelldb",
|
type = "codelldb",
|
||||||
request = "launch",
|
request = "launch",
|
||||||
name = "Cargo build & launch",
|
name = "Cargo build & launch",
|
||||||
program = find_rust_binary,
|
program = cargo_build_and_pick,
|
||||||
cwd = "${workspaceFolder}",
|
cwd = "${workspaceFolder}",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user