206 lines
5.0 KiB
Lua
206 lines
5.0 KiB
Lua
return {
|
|
'mfussenegger/nvim-dap',
|
|
version = false,
|
|
dependencies = {
|
|
{
|
|
'mfussenegger/nvim-dap-python',
|
|
version = false,
|
|
},
|
|
-- 'theHamsta/nvim-dap-virtual-text',
|
|
{
|
|
'rcarriga/nvim-dap-ui',
|
|
version = false,
|
|
dependencies = {
|
|
'nvim-neotest/nvim-nio',
|
|
},
|
|
},
|
|
{
|
|
'LiadOz/nvim-dap-repl-highlights',
|
|
version = false,
|
|
},
|
|
},
|
|
keys = {
|
|
{
|
|
'<F5>',
|
|
function()
|
|
require('dap').continue()
|
|
end,
|
|
desc = 'DAP start or continue',
|
|
},
|
|
{
|
|
'<S-F5>',
|
|
function()
|
|
require('dap').run_last()
|
|
end,
|
|
desc = 'DAP run last',
|
|
},
|
|
{
|
|
'<F6>',
|
|
function()
|
|
require('dap').run_last()
|
|
end,
|
|
desc = 'Run last',
|
|
},
|
|
{
|
|
'<F7>',
|
|
function()
|
|
require('dap').goto_()
|
|
end,
|
|
desc = 'DAP goto',
|
|
},
|
|
{
|
|
'<F8>',
|
|
function()
|
|
require('dap.ui.widgets').hover()
|
|
end,
|
|
desc = 'DAP Hover',
|
|
},
|
|
{
|
|
'<F9>',
|
|
function()
|
|
require('dap').toggle_breakpoint()
|
|
end,
|
|
desc = 'DAP breakpoint',
|
|
},
|
|
{
|
|
'<F10>',
|
|
function()
|
|
require('dap').step_over()
|
|
end,
|
|
desc = 'DAP step_over',
|
|
},
|
|
{
|
|
'<F11>',
|
|
function()
|
|
require('dap').step_into()
|
|
end,
|
|
desc = 'DAP step_into',
|
|
},
|
|
{
|
|
'<S-F11>',
|
|
function()
|
|
require('dap').step_out()
|
|
end,
|
|
desc = 'DAP step_out',
|
|
},
|
|
},
|
|
config = function()
|
|
local dap = require('dap')
|
|
vim.fn.sign_define('DapBreakpoint', { text = '🛑', texthl = '', linehl = '', numhl = '' })
|
|
|
|
-- make sure we can exit the terminal with esc
|
|
vim.api.nvim_create_autocmd({ 'TermOpen' }, {
|
|
pattern = { '*dap-terminal*' },
|
|
callback = function()
|
|
local opts = { noremap = true }
|
|
vim.api.nvim_buf_set_keymap(0, 't', '<esc>', [[<C-\><C-n>]], opts)
|
|
end,
|
|
})
|
|
|
|
require('dap.ext.vscode').json_decode = require('utils.json_workaround').decode_json
|
|
|
|
local masonpath = vim.fn.stdpath('data') .. '/mason'
|
|
|
|
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()
|
|
dap.listeners.before.attach.dapui_config = function()
|
|
dapui.open()
|
|
end
|
|
dap.listeners.before.launch.dapui_config = function()
|
|
dapui.open()
|
|
end
|
|
dap.listeners.before.event_terminated.dapui_config = function()
|
|
dapui.close()
|
|
end
|
|
dap.listeners.before.event_exited.dapui_config = function()
|
|
dapui.close()
|
|
end
|
|
|
|
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 = {
|
|
type = 'server',
|
|
port = '${port}',
|
|
executable = {
|
|
command = require('mason-core.path').bin_prefix('codelldb'),
|
|
args = { '--port', '${port}' },
|
|
|
|
-- On windows you may have to uncomment this:
|
|
detached = false,
|
|
},
|
|
}
|
|
|
|
dap.adapters.cppdbg = {
|
|
id = 'cppdbg',
|
|
type = 'executable',
|
|
command = masonpath .. '/bin/OpenDebugAD7',
|
|
}
|
|
|
|
dap.adapters.lldb = {
|
|
type = 'executable',
|
|
command = function()
|
|
if vim.loop.os_uname().sysname == 'Linux' then
|
|
return 'lldb-vscode'
|
|
else
|
|
return os.getenv('SCOOP') .. '/apps/llvm/current/bin/lldb-vscode.exe'
|
|
end
|
|
end,
|
|
name = 'lldb',
|
|
}
|
|
|
|
dap.configurations.cpp = {
|
|
{
|
|
name = 'Launch codelldb',
|
|
type = 'codelldb',
|
|
request = 'launch',
|
|
program = function()
|
|
return vim.fn.input({ 'Path to executable: ', vim.fn.getcwd() .. '/build_nvim/', 'file' })
|
|
end,
|
|
cwd = '${workspaceFolder}',
|
|
stopOnEntry = false,
|
|
},
|
|
{
|
|
name = 'Launch lldb',
|
|
type = 'lldb',
|
|
request = 'launch',
|
|
program = function()
|
|
return vim.fn.input({ 'Path to executable: ', vim.fn.getcwd() .. '/build_nvim', 'file' })
|
|
end,
|
|
cwd = '${workspaceFolder}',
|
|
stopOnEntry = false,
|
|
args = {},
|
|
|
|
-- 💀
|
|
-- if you change `runInTerminal` to true, you might need to change the yama/ptrace_scope setting:
|
|
--
|
|
-- echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
|
|
--
|
|
-- Otherwise you might get the following error:
|
|
--
|
|
-- Error on launch: Failed to attach to the target process
|
|
--
|
|
-- But you should be aware of the implications:
|
|
-- https://www.kernel.org/doc/html/latest/admin-guide/LSM/Yama.html
|
|
-- runInTerminal = false,
|
|
},
|
|
}
|
|
|
|
-- EXTENSIONS
|
|
|
|
require('nvim-dap-repl-highlights').setup()
|
|
-- require('nvim-dap-virtual-text').setup({})
|
|
end,
|
|
}
|