cleanup dap
This commit is contained in:
parent
07487ff91a
commit
12d2dd05b5
@ -37,9 +37,9 @@ return {
|
||||
{
|
||||
'<F6>',
|
||||
function()
|
||||
loadConfigs()
|
||||
require('dap').run_last()
|
||||
end,
|
||||
desc = 'DAP configs',
|
||||
desc = 'Run last',
|
||||
},
|
||||
{
|
||||
'<F7>',
|
||||
@ -97,93 +97,15 @@ return {
|
||||
end,
|
||||
})
|
||||
|
||||
-- Hover with K
|
||||
local api = vim.api
|
||||
local keymap_restore = {}
|
||||
dap.listeners.after['event_initialized']['me'] = function()
|
||||
for _, buf in pairs(api.nvim_list_bufs()) do
|
||||
local keymaps = api.nvim_buf_get_keymap(buf, 'n')
|
||||
for _, keymap in pairs(keymaps) do
|
||||
if keymap.lhs == 'K' then
|
||||
table.insert(keymap_restore, keymap)
|
||||
api.nvim_buf_del_keymap(buf, 'n', 'K')
|
||||
end
|
||||
end
|
||||
end
|
||||
api.nvim_set_keymap('n', 'K', '<Cmd>lua require("dap.ui.widgets").hover()<CR>', { silent = true })
|
||||
end
|
||||
|
||||
dap.listeners.after['event_terminated']['me'] = function()
|
||||
for _, keymap in pairs(keymap_restore) do
|
||||
api.nvim_buf_set_keymap(keymap.buffer, keymap.mode, keymap.lhs, keymap.rhs, { silent = keymap.silent == 1 })
|
||||
end
|
||||
keymap_restore = {}
|
||||
end
|
||||
|
||||
require('dap.ext.vscode').json_decode = require('utils.json_workaround').decode_json
|
||||
|
||||
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()
|
||||
require('dap.ext.vscode').load_launchjs()
|
||||
-- Make sure we use the correct python env even for the configs from launch.json
|
||||
for _, config in pairs(dap.configurations.python) do
|
||||
config.pythonPath = pythonVenv.getPythonEnv()
|
||||
config.cwd = vim.fn.getcwd()
|
||||
end
|
||||
require('fzf-lua').dap_configurations()
|
||||
end
|
||||
|
||||
local masonpath = vim.fn.stdpath('data') .. '/mason'
|
||||
|
||||
-- PYTHON
|
||||
dap.adapters.python = {
|
||||
type = 'executable',
|
||||
command = 'python',
|
||||
args = { '-m', 'debugpy.adapter' },
|
||||
options = {
|
||||
detached = true,
|
||||
},
|
||||
}
|
||||
vim.keymap.set('x', '<leader>k', function()
|
||||
local lines = vim.fn.getregion(vim.fn.getpos('.'), vim.fn.getpos('v'), { type = vim.fn.mode() })
|
||||
-- dap.repl.open()
|
||||
dap.repl.execute(table.concat(lines, '\n'))
|
||||
end)
|
||||
|
||||
local dapui = require('dapui')
|
||||
dapui.setup()
|
||||
@ -200,28 +122,12 @@ return {
|
||||
dapui.close()
|
||||
end
|
||||
|
||||
dap.configurations.python = {
|
||||
{
|
||||
type = 'python',
|
||||
request = 'launch',
|
||||
name = 'Launch file with venv',
|
||||
justMyCode = false,
|
||||
program = '${file}',
|
||||
cwd = vim.fn.getcwd(),
|
||||
pythonPath = pythonVenv.getPythonEnv,
|
||||
},
|
||||
}
|
||||
|
||||
-- require('dap-python').setup('C:\\Users\\oli\\AppData\\Local\\nvim\\venv_debugpy\\Scripts\\python')
|
||||
-- table.insert(require('dap').configurations.python, {
|
||||
-- -- type = 'python',
|
||||
-- -- request = 'launch',
|
||||
-- -- name = 'My custom launch configuration',
|
||||
-- -- program = '${file}',
|
||||
-- justMyCode = false
|
||||
-- -- ... more options, see https://github.com/microsoft/debugpy/wiki/Debug-configuration-settings
|
||||
-- })
|
||||
-- require('dap-python').setup('C:/Users/oli/AppData/Local/nvim-data/mason/packages/debugpy/venv/Scripts/python.exe')
|
||||
local path = require('mason-registry').get_package('debugpy'):get_install_path()
|
||||
if vim.loop.os_uname().sysname:find('Windows') then
|
||||
require('dap-python').setup(path .. 'dap-python' .. 'python')
|
||||
else
|
||||
require('dap-python').setup(path .. '/venv/bin/python')
|
||||
end
|
||||
|
||||
-- CPP
|
||||
dap.adapters.codelldb = {
|
||||
@ -294,6 +200,6 @@ return {
|
||||
-- EXTENSIONS
|
||||
|
||||
require('nvim-dap-repl-highlights').setup()
|
||||
require('nvim-dap-virtual-text').setup({})
|
||||
-- require('nvim-dap-virtual-text').setup({})
|
||||
end,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user