neovim conf based on kickstart.nvim
1-- debug.lua
2--
3-- Shows how to use the DAP plugin to debug your code.
4--
5-- Primarily focused on configuring the debugger for Go, but can
6-- be extended to other languages as well. That's why it's called
7-- kickstart.nvim and not kitchen-sink.nvim ;)
8
9---@module 'lazy'
10---@type LazySpec
11return {
12 -- NOTE: Yes, you can install new plugins here!
13 'mfussenegger/nvim-dap',
14 -- NOTE: And you can specify dependencies as well
15 dependencies = {
16 -- Creates a beautiful debugger UI
17 'rcarriga/nvim-dap-ui',
18
19 -- Required dependency for nvim-dap-ui
20 'nvim-neotest/nvim-nio',
21
22 -- Installs the debug adapters for you
23 'mason-org/mason.nvim',
24 'jay-babu/mason-nvim-dap.nvim',
25
26 -- Add your own debuggers here
27 'leoluz/nvim-dap-go',
28 },
29 keys = {
30 -- Basic debugging keymaps, feel free to change to your liking!
31 { '<F5>', function() require('dap').continue() end, desc = 'Debug: Start/Continue' },
32 { '<F1>', function() require('dap').step_into() end, desc = 'Debug: Step Into' },
33 { '<F2>', function() require('dap').step_over() end, desc = 'Debug: Step Over' },
34 { '<F3>', function() require('dap').step_out() end, desc = 'Debug: Step Out' },
35 { '<leader>b', function() require('dap').toggle_breakpoint() end, desc = 'Debug: Toggle Breakpoint' },
36 { '<leader>B', function() require('dap').set_breakpoint(vim.fn.input 'Breakpoint condition: ') end, desc = 'Debug: Set Breakpoint' },
37 -- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception.
38 { '<F7>', function() require('dapui').toggle() end, desc = 'Debug: See last session result.' },
39 },
40 config = function()
41 local dap = require 'dap'
42 local dapui = require 'dapui'
43
44 require('mason-nvim-dap').setup {
45 -- Makes a best effort to setup the various debuggers with
46 -- reasonable debug configurations
47 automatic_installation = true,
48
49 -- You can provide additional configuration to the handlers,
50 -- see mason-nvim-dap README for more information
51 handlers = {},
52
53 -- You'll need to check that you have the required things installed
54 -- online, please don't ask me how to install them :)
55 ensure_installed = {
56 -- Update this to ensure that you have the debuggers for the langs you want
57 'delve',
58 },
59 }
60
61 -- Dap UI setup
62 -- For more information, see |:help nvim-dap-ui|
63 ---@diagnostic disable-next-line: missing-fields
64 dapui.setup {
65 -- Set icons to characters that are more likely to work in every terminal.
66 -- Feel free to remove or use ones that you like more! :)
67 -- Don't feel like these are good choices.
68 icons = { expanded = '▾', collapsed = '▸', current_frame = '*' },
69 ---@diagnostic disable-next-line: missing-fields
70 controls = {
71 icons = {
72 pause = '⏸',
73 play = '▶',
74 step_into = '⏎',
75 step_over = '⏭',
76 step_out = '⏮',
77 step_back = 'b',
78 run_last = '▶▶',
79 terminate = '⏹',
80 disconnect = '⏏',
81 },
82 },
83 }
84
85 -- Change breakpoint icons
86 -- vim.api.nvim_set_hl(0, 'DapBreak', { fg = '#e51400' })
87 -- vim.api.nvim_set_hl(0, 'DapStop', { fg = '#ffcc00' })
88 -- local breakpoint_icons = vim.g.have_nerd_font
89 -- and { Breakpoint = '', BreakpointCondition = '', BreakpointRejected = '', LogPoint = '', Stopped = '' }
90 -- or { Breakpoint = '●', BreakpointCondition = '⊜', BreakpointRejected = '⊘', LogPoint = '◆', Stopped = '⭔' }
91 -- for type, icon in pairs(breakpoint_icons) do
92 -- local tp = 'Dap' .. type
93 -- local hl = (type == 'Stopped') and 'DapStop' or 'DapBreak'
94 -- vim.fn.sign_define(tp, { text = icon, texthl = hl, numhl = hl })
95 -- end
96
97 dap.listeners.after.event_initialized['dapui_config'] = dapui.open
98 dap.listeners.before.event_terminated['dapui_config'] = dapui.close
99 dap.listeners.before.event_exited['dapui_config'] = dapui.close
100
101 -- Install golang specific config
102 require('dap-go').setup {
103 delve = {
104 -- On Windows delve must be run attached or it crashes.
105 -- See https://github.com/leoluz/nvim-dap-go/blob/main/README.md#configuring
106 detached = vim.fn.has 'win32' == 0,
107 },
108 }
109 end,
110}