snacks picker for dap

This commit is contained in:
Oliver Hartmann 2025-03-31 21:25:50 +02:00
parent 6f56fa264c
commit 07487ff91a

View File

@ -123,7 +123,46 @@ return {
require('dap.ext.vscode').json_decode = require('utils.json_workaround').decode_json require('dap.ext.vscode').json_decode = require('utils.json_workaround').decode_json
local pythonVenv = require('utils.python_venv') local pythonVenv = require('utils.python_venv')
local snacks = require('snacks')
local dap = require('dap')
local function get_all_dap_configurations()
require('dap.ext.vscode').load_launchjs()
local configs = {}
for filetype, entries in pairs(dap.configurations or {}) do
for _, cfg in ipairs(entries) do
table.insert(configs, {
label = cfg.name or '[No name]',
desc = string.format('Type: %s | Filetype: %s', cfg.type, filetype),
config = cfg, -- store actual config separately
})
end
end
return configs
end
local function pick_dap_configuration()
local items = get_all_dap_configurations()
snacks.picker({
items = items,
prompt = 'DAP Configurations',
confirm = function(picker, item)
picker:close()
local config = item.config
if config then
dap.run(config)
else
vim.notify('Invalid DAP config', vim.log.levels.ERROR)
end
end,
})
end
-- Create a Neovim command for convenience
vim.api.nvim_create_user_command('PickDapConfig', pick_dap_configuration, {})
function loadConfigs() function loadConfigs()
require('dap.ext.vscode').load_launchjs() require('dap.ext.vscode').load_launchjs()
-- Make sure we use the correct python env even for the configs from launch.json -- Make sure we use the correct python env even for the configs from launch.json