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