99 lines
3.2 KiB
Lua
99 lines
3.2 KiB
Lua
local function has_configuration(configurations, name, adapter)
|
|
for _, configuration in ipairs(configurations or {}) do
|
|
if configuration.name == name and configuration.type == adapter then return true end
|
|
end
|
|
|
|
return false
|
|
end
|
|
|
|
local function setup_cpp_dap(dap)
|
|
dap.adapters.codelldb = dap.adapters.codelldb or {
|
|
type = 'executable',
|
|
command = 'codelldb',
|
|
}
|
|
|
|
local launch_name = 'Launch current file (codelldb)'
|
|
local launch_configuration = {
|
|
name = launch_name,
|
|
type = 'codelldb',
|
|
request = 'launch',
|
|
program = function() return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') end,
|
|
cwd = '${workspaceFolder}',
|
|
stopOnEntry = false,
|
|
args = {},
|
|
}
|
|
|
|
for _, language in ipairs { 'c', 'cpp' } do
|
|
dap.configurations[language] = dap.configurations[language] or {}
|
|
|
|
if not has_configuration(dap.configurations[language], launch_name, 'codelldb') then
|
|
table.insert(dap.configurations[language], vim.deepcopy(launch_configuration))
|
|
end
|
|
end
|
|
end
|
|
|
|
---@module 'lazy'
|
|
---@type LazySpec
|
|
return {
|
|
'mfussenegger/nvim-dap',
|
|
dependencies = {
|
|
'rcarriga/nvim-dap-ui',
|
|
'nvim-neotest/nvim-nio',
|
|
'mason-org/mason.nvim',
|
|
'jay-babu/mason-nvim-dap.nvim',
|
|
'leoluz/nvim-dap-go',
|
|
},
|
|
keys = {
|
|
{ '<F5>', function() require('dap').continue() end, desc = 'Debug: Start/Continue' },
|
|
{ '<F1>', function() require('dap').step_into() end, desc = 'Debug: Step Into' },
|
|
{ '<F2>', function() require('dap').step_over() end, desc = 'Debug: Step Over' },
|
|
{ '<F3>', function() require('dap').step_out() end, desc = 'Debug: Step Out' },
|
|
{ '<leader>b', function() require('dap').toggle_breakpoint() end, desc = 'Debug: Toggle Breakpoint' },
|
|
{ '<leader>B', function() require('dap').set_breakpoint(vim.fn.input 'Breakpoint condition: ') end, desc = 'Debug: Set Breakpoint' },
|
|
-- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception.
|
|
{ '<F7>', function() require('dapui').toggle() end, desc = 'Debug: See last session result.' },
|
|
},
|
|
config = function()
|
|
local dap = require 'dap'
|
|
local dapui = require 'dapui'
|
|
local has_delve = vim.fn.executable 'dlv' == 1
|
|
|
|
require('mason-nvim-dap').setup {
|
|
automatic_installation = true,
|
|
handlers = {},
|
|
ensure_installed = { 'codelldb' },
|
|
}
|
|
|
|
---@diagnostic disable-next-line: missing-fields
|
|
dapui.setup {
|
|
icons = { expanded = '▾', collapsed = '▸', current_frame = '*' },
|
|
---@diagnostic disable-next-line: missing-fields
|
|
controls = {
|
|
icons = {
|
|
pause = '⏸',
|
|
play = '▶',
|
|
step_into = '⏎',
|
|
step_over = '⏭',
|
|
step_out = '⏮',
|
|
step_back = 'b',
|
|
run_last = '▶▶',
|
|
terminate = '⏹',
|
|
disconnect = '⏏',
|
|
},
|
|
},
|
|
}
|
|
|
|
dap.listeners.after.event_initialized['dapui_config'] = dapui.open
|
|
dap.listeners.before.event_terminated['dapui_config'] = dapui.close
|
|
dap.listeners.before.event_exited['dapui_config'] = dapui.close
|
|
|
|
if has_delve then require('dap-go').setup {
|
|
delve = {
|
|
detached = vim.fn.has 'win32' == 0,
|
|
},
|
|
} end
|
|
|
|
setup_cpp_dap(dap)
|
|
end,
|
|
}
|