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