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

View File

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