refactored binary picker

This commit is contained in:
dlond 2025-05-25 23:31:39 +12:00
parent ab6af8750d
commit 6455565e79
2 changed files with 47 additions and 30 deletions

View File

@ -68,36 +68,7 @@ return {
name = 'Launch C/C++ (lldb-dap)', name = 'Launch C/C++ (lldb-dap)',
type = 'lldb', type = 'lldb',
request = 'launch', request = 'launch',
program = function() program = require('custom.utils').pick_executable,
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', '<CR>', 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,
cwd = '${workspaceFolder}', cwd = '${workspaceFolder}',
stopOnEntry = false, stopOnEntry = false,
args = {}, args = {},

46
lua/custom/utils.lua Normal file
View File

@ -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', '<CR>', 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,
}