fix refactor pt 4
This commit is contained in:
parent
a7e384d20c
commit
3a76cd484c
|
@ -55,6 +55,7 @@ return {
|
||||||
},
|
},
|
||||||
config = function()
|
config = function()
|
||||||
local dap = require 'dap'
|
local dap = require 'dap'
|
||||||
|
local pick_executable = require('custom.utils').pick_executable
|
||||||
|
|
||||||
-- Configure the LLDB DAP adapter for C/C++
|
-- Configure the LLDB DAP adapter for C/C++
|
||||||
-- Assumes 'lldb-dap' executable is in PATH (from pkgs.llvmPackages_XX.lldb)
|
-- Assumes 'lldb-dap' executable is in PATH (from pkgs.llvmPackages_XX.lldb)
|
||||||
|
@ -69,11 +70,10 @@ return {
|
||||||
type = 'lldb',
|
type = 'lldb',
|
||||||
request = 'launch',
|
request = 'launch',
|
||||||
program = function()
|
program = function()
|
||||||
local utils = require 'custom.utils'
|
return coroutine.create(function()
|
||||||
local cwd = vim.fn.getcwd()
|
local executable = pick_executable(ivim.fn.getcwd() .. '/build')
|
||||||
local co = utils.pick_executable 'build'
|
coroutine.yield(executable)
|
||||||
local ok, result = coroutine.resume(co)
|
end)
|
||||||
return ok and result or nil
|
|
||||||
end,
|
end,
|
||||||
cwd = '${workspaceFolder}',
|
cwd = '${workspaceFolder}',
|
||||||
stopOnEntry = false,
|
stopOnEntry = false,
|
||||||
|
|
|
@ -1,46 +1,49 @@
|
||||||
return {
|
return {
|
||||||
pick_executable = function(start_dir)
|
pick_executable = function(start_dir)
|
||||||
local scan = require 'plenary.scandir'
|
local function is_executable(path)
|
||||||
local Path = require 'plenary.path'
|
return vim.fn.filereadable(path) == 1 and vim.fn.executable(path) == 1
|
||||||
local results = {}
|
end
|
||||||
|
|
||||||
-- Recursively scan for files
|
local function collect_executables(dir)
|
||||||
scan.scan_dir(start_dir, {
|
local files = vim.fn.globpath(dir, '**', true, true)
|
||||||
hidden = true,
|
local binaries = {}
|
||||||
depth = 3,
|
for _, path in ipairs(files) do
|
||||||
add_dirs = false,
|
if is_executable(path) then
|
||||||
on_insert = function(file)
|
table.insert(binaries, path)
|
||||||
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
|
||||||
end,
|
end
|
||||||
})
|
return binaries
|
||||||
|
end
|
||||||
|
|
||||||
local pickers = require 'telescope.pickers'
|
local co = coroutine.running()
|
||||||
local finders = require 'telescope.finders'
|
if not co then
|
||||||
local conf = require('telescope.config').values
|
error 'pick_executable must be called from a coroutine'
|
||||||
local actions = require 'telescope.actions'
|
end
|
||||||
local action_state = require 'telescope.actions.state'
|
|
||||||
|
|
||||||
return coroutine.create(function(coro)
|
local executables = collect_executables(start_dir)
|
||||||
pickers
|
if #executables == 0 then
|
||||||
.new({}, {
|
vim.notify('No executables found in ' .. start_dir, vim.log.levels.WARN)
|
||||||
prompt_title = 'Select Executable',
|
return
|
||||||
finder = finders.new_table {
|
end
|
||||||
results = results,
|
|
||||||
},
|
require('telescope.pickers')
|
||||||
sorter = conf.generic_sorter {},
|
.new({}, {
|
||||||
attach_mappings = function(_, map)
|
prompt_title = 'Select Executable',
|
||||||
actions.select_default:replace(function(prompt_bufnr)
|
finder = require('telescope.finders').new_table {
|
||||||
local selection = action_state.get_selected_entry()
|
results = executables,
|
||||||
actions.close(prompt_bufnr)
|
},
|
||||||
coroutine.resume(coro, selection[1])
|
sorter = require('telescope.config').values.generic_sorter {},
|
||||||
end)
|
attach_mappings = function(_, map)
|
||||||
return true
|
map('i', '<CR>', function(prompt_bufnr)
|
||||||
end,
|
local entry = require('telescope.actions.state').get_selected_entry()
|
||||||
})
|
require('telescope.actions').close(prompt_bufnr)
|
||||||
:find()
|
coroutine.resume(co, entry.value)
|
||||||
end)
|
end)
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
:find()
|
||||||
|
|
||||||
|
return coroutine.yield()
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue