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)', name = 'Launch C/C++ (lldb-dap)',
type = 'lldb', type = 'lldb',
request = 'launch', 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}', cwd = '${workspaceFolder}',
stopOnEntry = false, stopOnEntry = false,
args = {}, args = {},

View File

@ -1,46 +1,46 @@
return { 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 pickers = require 'telescope.pickers'
local finders = require 'telescope.finders' local finders = require 'telescope.finders'
local conf = require('telescope.config').values local conf = require('telescope.config').values
local actions = require 'telescope.actions'
local action_state = require 'telescope.actions.state'
local entry_maker = function(entry) return coroutine.create(function(coro)
return {
value = entry,
display = entry,
ordinal = entry,
}
end
local co = coroutine.running()
pickers pickers
.new({}, { .new({}, {
prompt_title = 'Select binary', prompt_title = 'Select Executable',
finder = finders.new_oneshot_job { finder = finders.new_table {
'fd', results = results,
'--type',
'f',
'--exec-batch',
'test',
'-x',
'{}',
';',
'echo',
'{}',
'',
'build/',
}, },
sorter = conf.generic_sorter {}, sorter = conf.generic_sorter {},
attach_mappings = function(_, map) attach_mappings = function(_, map)
map('i', '<CR>', function(bufnr) actions.select_default:replace(function(prompt_bufnr)
local entry = require('telescope.actions.state').get_selected_entry() local selection = action_state.get_selected_entry()
require('telescope.actions').close(bufnr) actions.close(prompt_bufnr)
coroutine.resume(co, entry.value) coroutine.resume(coro, selection[1])
end) end)
return true return true
end, end,
}) })
:find() :find()
return coroutine.yield() end)
end, end,
} }