fix refactor

This commit is contained in:
dlond 2025-05-25 23:44:51 +12:00
parent 6455565e79
commit 97ee0a6eca
2 changed files with 45 additions and 40 deletions

View File

@ -68,7 +68,12 @@ return {
name = 'Launch C/C++ (lldb-dap)',
type = 'lldb',
request = 'launch',
program = require('custom.utils').pick_executable,
program = function()
local utils = require 'custom.utils'
local co = utils.pick_executable '${workspaceFolder}/build'
local ok, result = coroutine.resume(co)
return ok and result or nil
end,
cwd = '${workspaceFolder}',
stopOnEntry = false,
args = {},

View File

@ -1,46 +1,46 @@
return {
pick_executable = function()
pick_executable = function(start_dir)
local scan = require 'plenary.scandir'
local Path = require 'plenary.path'
local results = {}
-- Recursively scan for files
scan.scan_dir(start_dir, {
hidden = true,
depth = 3,
add_dirs = false,
on_insert = function(file)
local file_type = vim.fn.system { 'file', '-b', file }
if file_type:match 'Mach%-O' or file_type:match 'ELF' then
table.insert(results, file)
end
end,
})
local pickers = require 'telescope.pickers'
local finders = require 'telescope.finders'
local conf = require('telescope.config').values
local actions = require 'telescope.actions'
local action_state = require 'telescope.actions.state'
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()
return coroutine.create(function(coro)
pickers
.new({}, {
prompt_title = 'Select Executable',
finder = finders.new_table {
results = results,
},
sorter = conf.generic_sorter {},
attach_mappings = function(_, map)
actions.select_default:replace(function(prompt_bufnr)
local selection = action_state.get_selected_entry()
actions.close(prompt_bufnr)
coroutine.resume(coro, selection[1])
end)
return true
end,
})
:find()
end)
end,
}