mfussenegger / nvim-dap

Debug Adapter Protocol client implementation for Neovim
GNU General Public License v3.0
5.1k stars 179 forks source link

Add picker for executables/files #1130

Closed cryptomilk closed 1 month ago

cryptomilk commented 6 months ago

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 commented 2 months ago

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 commented 2 months ago

image

cryptomilk commented 1 month ago

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,
}
mfussenegger commented 1 month ago

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