debug.lua 4.4 KB

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