From a5b0da62c11dfb923a820fc9c1a77bce136c8ea2 Mon Sep 17 00:00:00 2001 From: dlond Date: Mon, 26 May 2025 01:29:35 +1200 Subject: [PATCH] broke the tele picker, fix pt 2 --- lua/custom/plugins/debug.lua | 3 +- lua/custom/utils.lua | 80 +++++++++++++++--------------------- 2 files changed, 35 insertions(+), 48 deletions(-) diff --git a/lua/custom/plugins/debug.lua b/lua/custom/plugins/debug.lua index 8a3080de..8b790461 100644 --- a/lua/custom/plugins/debug.lua +++ b/lua/custom/plugins/debug.lua @@ -55,7 +55,6 @@ return { }, config = function() local dap = require 'dap' - local utils = require 'custom.utils' -- Configure the LLDB DAP adapter for C/C++ -- Assumes 'lldb-dap' executable is in PATH (from pkgs.llvmPackages_XX.lldb) @@ -71,7 +70,7 @@ return { type = 'lldb', request = 'launch', program = function() - return utils.pick_executable_for_dap(vim.fn.getcwd() .. '/build') + return require('custom.utils').pick_executable(vim.fn.getcwd() .. '/build') end, cwd = '${workspaceFolder}', stopOnEntry = false, diff --git a/lua/custom/utils.lua b/lua/custom/utils.lua index 0ae2d965..751b9ce8 100644 --- a/lua/custom/utils.lua +++ b/lua/custom/utils.lua @@ -1,4 +1,4 @@ -local async = require 'plenary.async.util' +local async = require 'plenary.async' local pickers = require 'telescope.pickers' local finders = require 'telescope.finders' local sorters = require('telescope.config').values @@ -18,53 +18,41 @@ local function collect_executables(start_dir) return results end -local function pick_executable(start_dir, on_choice) - local executables = collect_executables(start_dir) - if #executables == 0 then - vim.notify('No executables found in ' .. start_dir, vim.log.levels.WARN) - on_choice(nil) - return - 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_result(entry.value) - end) - map('i', '', 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) +local function pick_executable(start_dir) + return async.wrap(function(start_dir, on_choice) + local executables = collect_executables(start_dir) + if #executables == 0 then + vim.notify('No executables found in ' .. start_dir, vim.log.levels.WARN) + on_choice(nil) + return 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', '', 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 return { - pick_executable_for_dap = pick_executable_for_dap, + pick_executable = pick_executable, }