From d2da11491d334c4bf52ca4c39350925b9cf32538 Mon Sep 17 00:00:00 2001 From: dlond Date: Mon, 26 May 2025 00:46:10 +1200 Subject: [PATCH] exe picker more robust --- lua/custom/plugins/debug.lua | 15 ++++++++------- lua/custom/utils.lua | 15 +++++++++++++-- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/lua/custom/plugins/debug.lua b/lua/custom/plugins/debug.lua index 6d26796f..61066d1d 100644 --- a/lua/custom/plugins/debug.lua +++ b/lua/custom/plugins/debug.lua @@ -55,7 +55,6 @@ return { }, config = function() local dap = require 'dap' - local pick_executable = require('custom.utils').pick_executable -- Configure the LLDB DAP adapter for C/C++ -- Assumes 'lldb-dap' executable is in PATH (from pkgs.llvmPackages_XX.lldb) @@ -69,12 +68,14 @@ return { name = 'Launch C/C++ (lldb-dap)', type = 'lldb', request = 'launch', - program = function() - return coroutine.create(function() - local executable = pick_executable(vim.fn.getcwd() .. '/build') - coroutine.yield(executable) - end) - end, + program = coroutine.wrap(function() + local exe = require('custom.utils').pick_executable(vim.fn.getcwd() .. '/build') + if not exe then + vim.notify('Debug session cancelled: executable not selected', vim.log.levels.INFO) + return nil + end + return exe + end), cwd = '${workspaceFolder}', stopOnEntry = false, args = {}, diff --git a/lua/custom/utils.lua b/lua/custom/utils.lua index ca866b78..68dba294 100644 --- a/lua/custom/utils.lua +++ b/lua/custom/utils.lua @@ -27,6 +27,9 @@ local function pick_executable(start_dir) return end + local actions = require 'telescope.actions' + local action_state = require 'telescope.actions.state' + require('telescope.pickers') .new({}, { prompt_title = 'Select Executable', @@ -36,10 +39,18 @@ local function pick_executable(start_dir) sorter = require('telescope.config').values.generic_sorter {}, attach_mappings = function(_, map) map('i', '', function(prompt_bufnr) - local entry = require('telescope.actions.state').get_selected_entry() - require('telescope.actions').close(prompt_bufnr) + local entry = action_state.get_selected_entry() + actions.close(prompt_bufnr) coroutine.resume(co, entry.value) end) + map('i', '', function(prompt_bufnr) + actions.close(prompt_bufnr) + coroutine.resume(co, nil) + end) + map('n', 'q', function(prompt_bufnr) + actions.close(prompt_bufnr) + coroutine.resume(co, nil) + end) return true end, })