exe picker more robust

This commit is contained in:
dlond 2025-05-26 00:46:10 +12:00
parent d06e7b8f2d
commit d2da11491d
2 changed files with 21 additions and 9 deletions

View File

@ -55,7 +55,6 @@ return {
},
config = function()
local dap = require 'dap'
local pick_executable = require('custom.utils').pick_executable
-- Configure the LLDB DAP adapter for C/C++
-- Assumes 'lldb-dap' executable is in PATH (from pkgs.llvmPackages_XX.lldb)
@ -69,12 +68,14 @@ return {
name = 'Launch C/C++ (lldb-dap)',
type = 'lldb',
request = 'launch',
program = function()
return coroutine.create(function()
local executable = pick_executable(vim.fn.getcwd() .. '/build')
coroutine.yield(executable)
end)
end,
program = coroutine.wrap(function()
local exe = require('custom.utils').pick_executable(vim.fn.getcwd() .. '/build')
if not exe then
vim.notify('Debug session cancelled: executable not selected', vim.log.levels.INFO)
return nil
end
return exe
end),
cwd = '${workspaceFolder}',
stopOnEntry = false,
args = {},

View File

@ -27,6 +27,9 @@ local function pick_executable(start_dir)
return
end
local actions = require 'telescope.actions'
local action_state = require 'telescope.actions.state'
require('telescope.pickers')
.new({}, {
prompt_title = 'Select Executable',
@ -36,10 +39,18 @@ local function pick_executable(start_dir)
sorter = require('telescope.config').values.generic_sorter {},
attach_mappings = function(_, map)
map('i', '<CR>', function(prompt_bufnr)
local entry = require('telescope.actions.state').get_selected_entry()
require('telescope.actions').close(prompt_bufnr)
local entry = action_state.get_selected_entry()
actions.close(prompt_bufnr)
coroutine.resume(co, entry.value)
end)
map('i', '<Esc>', function(prompt_bufnr)
actions.close(prompt_bufnr)
coroutine.resume(co, nil)
end)
map('n', 'q', function(prompt_bufnr)
actions.close(prompt_bufnr)
coroutine.resume(co, nil)
end)
return true
end,
})