broke the tele picker, fix pt 2

This commit is contained in:
dlond 2025-05-26 01:29:35 +12:00
parent 8a51315db4
commit a5b0da62c1
2 changed files with 35 additions and 48 deletions

View File

@ -55,7 +55,6 @@ return {
}, },
config = function() config = function()
local dap = require 'dap' local dap = require 'dap'
local utils = require 'custom.utils'
-- 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)
@ -71,7 +70,7 @@ return {
type = 'lldb', type = 'lldb',
request = 'launch', request = 'launch',
program = function() program = function()
return utils.pick_executable_for_dap(vim.fn.getcwd() .. '/build') return require('custom.utils').pick_executable(vim.fn.getcwd() .. '/build')
end, end,
cwd = '${workspaceFolder}', cwd = '${workspaceFolder}',
stopOnEntry = false, stopOnEntry = false,

View File

@ -1,4 +1,4 @@
local async = require 'plenary.async.util' local async = require 'plenary.async'
local pickers = require 'telescope.pickers' local pickers = require 'telescope.pickers'
local finders = require 'telescope.finders' local finders = require 'telescope.finders'
local sorters = require('telescope.config').values local sorters = require('telescope.config').values
@ -18,53 +18,41 @@ local function collect_executables(start_dir)
return results return results
end end
local function pick_executable(start_dir, on_choice) local function pick_executable(start_dir)
local executables = collect_executables(start_dir) return async.wrap(function(start_dir, on_choice)
if #executables == 0 then local executables = collect_executables(start_dir)
vim.notify('No executables found in ' .. start_dir, vim.log.levels.WARN) if #executables == 0 then
on_choice(nil) vim.notify('No executables found in ' .. start_dir, vim.log.levels.WARN)
return on_choice(nil)
end return
pickers
.new({}, {
prompt_title = 'Select Executable',
finder = finders.new_table { results = executables },
sorter = sorters.generic_sorter {},
attach_mappings = function(_, map)
actions.select_default:replace(function(prompt_bufnr)
local entry = action_state.get_selected_entry()
actions.close(prompt_bufnr)
on_result(entry.value)
end)
map('i', '<Esc>', function(buf)
actions.close(buf)
on_result(nil)
end)
map('n', 'q', function(buf)
actions.close(buf)
on_result(nil)
end)
return true
end,
})
:find()
end
local function pick_executable_for_dap(start_dir)
return async.void(function()
local co = coroutine.running()
pick_executable(start_dir, function(choice)
coroutine.resume(co, choice)
end)
local result = coroutine.yield()
if not result then
vim.notify('Debug launch cancelled', vim.log.levels.INFO)
end end
return result
end)() pickers
.new({}, {
prompt_title = 'Select Executable',
finder = finders.new_table { results = executables },
sorter = sorters.generic_sorter {},
attach_mappings = function(_, map)
actions.select_default:replace(function(prompt_bufnr)
local entry = action_state.get_selected_entry()
actions.close(prompt_bufnr)
on_choice(entry.value)
end)
map('i', '<Esc>', function(buf)
actions.close(buf)
on_choice(nil)
end)
map('n', 'q', function(buf)
actions.close(buf)
on_choice(nil)
end)
return true
end,
})
:find()
end, 2)(start_dir)
end end
return { return {
pick_executable_for_dap = pick_executable_for_dap, pick_executable = pick_executable,
} }