nvim-dap icon indicating copy to clipboard operation
nvim-dap copied to clipboard

Add picker for executables/files

Open cryptomilk opened this issue 2 years ago • 2 comments

Problem Statement

You provide a nice picker to select a process to get the pid. It would be great to have the same available to select programs/executables to debug.

I'm currently using:

        program = function()
            local path = vim.fn.input({
                prompt = 'Path to executable: ',
                default = vim.fn.getcwd() .. '/',
                completion = 'file',
            })

            return (path and path ~= '') and path or dap.ABORT
        end,
        args = function()
            local args_str = vim.fn.input({
                prompt = 'Arguments: ',
            })
            return vim.split(args_str, ' +')
        end,

Possible Solutions

It would be nice if you would have a picker searching for executables in the directory.

    program = require('dap.utils').pick_file({ executables_only = true })

It could also be used maybe with a filter:

    program = require('dap.utils').pick_file({ filter = '*.py' })

Considered Alternatives

No response

cryptomilk avatar Jan 07 '24 10:01 cryptomilk

I have a first implementation here: https://git.cryptomilk.org/users/asn/dotfiles.git/tree/dot_config/nvim/lua/plugins/dap/c.lua#n51

cryptomilk avatar Apr 07 '24 06:04 cryptomilk

image

cryptomilk avatar Apr 07 '24 06:04 cryptomilk

I just noticed that you removed the search_path option. The Samba project has a lot of files (~50k), I don't really want to search for executables in the whole source tree, I only want to search for them in the build directory. That's why I added an option to specify it.

local cwd = vim.fn.getcwd()
local is_samba = cwd:find('samba')

local path = nil
if is_samba then
    path = cwd .. '/bin'
end

opts {
  path = path,
}

cryptomilk avatar May 23 '24 07:05 cryptomilk

Created https://github.com/mfussenegger/nvim-dap/pull/1218

mfussenegger avatar May 23 '24 08:05 mfussenegger