Skip to content

Instantly share code, notes, and snippets.

@juster-0
Created December 20, 2023 22:40
Show Gist options
  • Save juster-0/4a139921548e15492ce09cb406b8a1a8 to your computer and use it in GitHub Desktop.
Save juster-0/4a139921548e15492ce09cb406b8a1a8 to your computer and use it in GitHub Desktop.
Using Telescope filepicker to select debug file for DAP in NEOVIM
local user_fn = require("user_fn")
vim.keymap.set("n", "<leader>df", user_fn.dap_continue_telescope,
{ desc="[DAP] Launch DAP using Telescope filepicker" })
local M = {}
local dap = require("dap")
local actions = require('telescope.actions')
local action_state = require('telescope.actions.state')
-- The first configuration entry in dap.configurations.<filetype>
-- should be request = "launch"
local function dap_continue_telescope_filepicker(prompt_bufnr, map)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
local selection = action_state.get_selected_entry()
local filepath = selection.cwd..'/'..selection[1]
local filetype = vim.bo.filetype
-- Use the first configuration item and current buffer
-- filetype to get basic configuration for dap launch
local conf = vim.deepcopy(dap.configurations[filetype][1])
conf.program = filepath
dap.run(conf)
return selection[1]
end)
return true
end
function M.dap_continue_telescope()
local opts = {
attach_mappings = dap_continue_telescope_filepicker
}
require("telescope.builtin").find_files(opts)
end
return M
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment