diff --git a/lua/custom/plugins/debug.lua b/lua/custom/plugins/debug.lua index 0075c4df..e2fdbc0d 100644 --- a/lua/custom/plugins/debug.lua +++ b/lua/custom/plugins/debug.lua @@ -68,36 +68,7 @@ return { name = 'Launch C/C++ (lldb-dap)', type = 'lldb', request = 'launch', - program = function() - local pickers = require 'telescope.pickers' - local finders = require 'telescope.finders' - local conf = require('telescope.config').values - local entry_maker = function(entry) - return { - value = entry, - display = entry, - ordinal = entry, - } - end - - local co = coroutine.running() - pickers - .new({}, { - prompt_title = 'Select binary', - finder = finders.new_oneshot_job { 'fd', '--type=f', '', 'build/debug', 'build/release' }, - sorter = conf.generic_sorter {}, - attach_mappings = function(_, map) - map('i', '', function(bufnr) - local entry = require('telescope.actions.state').get_selected_entry() - require('telescope.actions').close(bufnr) - coroutine.resume(co, entry.value) - end) - return true - end, - }) - :find() - return coroutine.yield() - end, + program = require('custom.utils').pick_executable, cwd = '${workspaceFolder}', stopOnEntry = false, args = {}, diff --git a/lua/custom/utils.lua b/lua/custom/utils.lua new file mode 100644 index 00000000..1f206215 --- /dev/null +++ b/lua/custom/utils.lua @@ -0,0 +1,46 @@ +return { + pick_executable = function() + local pickers = require 'telescope.pickers' + local finders = require 'telescope.finders' + local conf = require('telescope.config').values + + local entry_maker = function(entry) + return { + value = entry, + display = entry, + ordinal = entry, + } + end + + local co = coroutine.running() + pickers + .new({}, { + prompt_title = 'Select binary', + finder = finders.new_oneshot_job { + 'fd', + '--type', + 'f', + '--exec-batch', + 'test', + '-x', + '{}', + ';', + 'echo', + '{}', + '', + 'build/', + }, + sorter = conf.generic_sorter {}, + attach_mappings = function(_, map) + map('i', '', function(bufnr) + local entry = require('telescope.actions.state').get_selected_entry() + require('telescope.actions').close(bufnr) + coroutine.resume(co, entry.value) + end) + return true + end, + }) + :find() + return coroutine.yield() + end, +}