Created
December 20, 2023 22:40
-
-
Save juster-0/4a139921548e15492ce09cb406b8a1a8 to your computer and use it in GitHub Desktop.
Using Telescope filepicker to select debug file for DAP in NEOVIM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local user_fn = require("user_fn") | |
vim.keymap.set("n", "<leader>df", user_fn.dap_continue_telescope, | |
{ desc="[DAP] Launch DAP using Telescope filepicker" }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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