do vim.pack.add { 'https://github.com/mfussenegger/nvim-dap', 'https://github.com/rcarriga/nvim-dap-ui', 'https://github.com/nvim-neotest/nvim-nio', 'https://github.com/mason-org/mason.nvim', 'https://github.com/jay-babu/mason-nvim-dap.nvim', -- 'https://github.com/leoluz/nvim-dap-go', } safe_require('dap', false, function(dap) -- Basic debugging keymaps, feel free to change to your liking! vim.keymap.set('n', '', function() dap.continue() end, { desc = 'Debug: Start/Continue' }) vim.keymap.set('n', '', function() dap.step_into() end, { desc = 'Debug: Step Into' }) vim.keymap.set('n', '', function() dap.step_over() end, { desc = 'Debug: Step Over' }) vim.keymap.set('n', '', function() dap.step_out() end, { desc = 'Debug: Step Out' }) vim.keymap.set('n', 'b', function() dap.toggle_breakpoint() end, { desc = 'Debug: Toggle Breakpoint' }) vim.keymap.set('n', 'B', function() dap.set_breakpoint(vim.fn.input 'Breakpoint condition: ') end, { desc = 'Debug: Set Breakpoint' }) dap.adapters.gdb = { type = 'executable', command = 'gdb', args = { '--interpreter=dap', '--eval-command', 'set print pretty on' }, } dap.configurations.c = { { name = 'Launch', type = 'gdb', request = 'launch', program = function() return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') end, args = {}, -- provide arguments if needed cwd = '${workspaceFolder}', stopAtBeginningOfMainSubprogram = false, }, { name = 'Select and attach to process', type = 'gdb', request = 'attach', program = function() return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') end, pid = function() local name = vim.fn.input 'Executable name (filter): ' return require('dap.utils').pick_process { filter = name } end, cwd = '${workspaceFolder}', }, { name = 'Attach to gdbserver :1234', type = 'gdb', request = 'attach', target = 'localhost:1234', program = function() return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') end, cwd = '${workspaceFolder}', }, } safe_require('dapui', { -- Dap UI setup -- For more information, see |:help nvim-dap-ui| ---@diagnostic disable-next-line: missing-fields -- Set icons to characters that are more likely to work in every terminal. -- Feel free to remove or use ones that you like more! :) -- Don't feel like these are good choices. 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 = '⏏', }, }, }, function(dapui) -- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception. vim.keymap.set('n', '', function() dapui.toggle() end, { desc = 'Debug: See last session result.' }) 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 end) end) safe_require('mason-nvim-dap', { -- Makes a best effort to setup the various debuggers with -- reasonable debug configurations automatic_installation = true, -- You can provide additional configuration to the handlers, -- see mason-nvim-dap README for more information handlers = {}, -- You'll need to check that you have the required things installed -- online, please don't ask me how to install them :) -- Debuggers only make sense with the development profile enabled ensure_installed = vim.g.load_development and { 'python', 'kotlin' } or {}, }) -- Change breakpoint icons -- vim.api.nvim_set_hl(0, 'DapBreak', { fg = '#e51400' }) -- vim.api.nvim_set_hl(0, 'DapStop', { fg = '#ffcc00' }) -- local breakpoint_icons = vim.g.have_nerd_font -- and { Breakpoint = '', BreakpointCondition = '', BreakpointRejected = '', LogPoint = '', Stopped = '' } -- or { Breakpoint = '●', BreakpointCondition = '⊜', BreakpointRejected = '⊘', LogPoint = '◆', Stopped = '⭔' } -- for type, icon in pairs(breakpoint_icons) do -- local tp = 'Dap' .. type -- local hl = (type == 'Stopped') and 'DapStop' or 'DapBreak' -- vim.fn.sign_define(tp, { text = icon, texthl = hl, numhl = hl }) -- end -- Install golang specific config -- require('dap-go').setup { -- delve = { -- -- On Windows delve must be run attached or it crashes. -- -- See https://github.com/leoluz/nvim-dap-go/blob/main/README.md#configuring -- detached = vim.fn.has 'win32' == 0, -- }, -- } -- vim.pack.add { gh 'mfussenegger/nvim-dap' } -- safe_require('dap', false, function(dap) -- dap.adapters.gdb = { -- type = 'executable', -- command = 'gdb', -- args = { '--interpreter=dap', '--eval-command', 'set print pretty on' }, -- } -- dap.configurations.c = { -- { -- name = 'Launch', -- type = 'gdb', -- request = 'launch', -- program = function() return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') end, -- args = {}, -- provide arguments if needed -- cwd = '${workspaceFolder}', -- stopAtBeginningOfMainSubprogram = false, -- }, -- { -- name = 'Select and attach to process', -- type = 'gdb', -- request = 'attach', -- program = function() return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') end, -- pid = function() -- local name = vim.fn.input 'Executable name (filter): ' -- return require('dap.utils').pick_process { filter = name } -- end, -- cwd = '${workspaceFolder}', -- }, -- { -- name = 'Attach to gdbserver :1234', -- type = 'gdb', -- request = 'attach', -- target = 'localhost:1234', -- program = function() return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') end, -- cwd = '${workspaceFolder}', -- }, -- } -- end) end