debug.lua 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 = function(_, keys)
  24. local dap = require 'dap'
  25. local dapui = require 'dapui'
  26. return {
  27. -- Basic debugging keymaps, feel free to change to your liking!
  28. { '<F5>', dap.continue, desc = 'Debug: Start/Continue' },
  29. { '<F1>', dap.step_into, desc = 'Debug: Step Into' },
  30. { '<F2>', dap.step_over, desc = 'Debug: Step Over' },
  31. { '<F3>', dap.step_out, desc = 'Debug: Step Out' },
  32. { '<leader>b', dap.toggle_breakpoint, desc = 'Debug: Toggle Breakpoint' },
  33. {
  34. '<leader>B',
  35. function()
  36. dap.set_breakpoint(vim.fn.input 'Breakpoint condition: ')
  37. end,
  38. desc = 'Debug: Set Breakpoint',
  39. },
  40. -- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception.
  41. { '<F7>', dapui.toggle, desc = 'Debug: See last session result.' },
  42. unpack(keys),
  43. }
  44. end,
  45. config = function()
  46. local dap = require 'dap'
  47. local dapui = require 'dapui'
  48. require('mason-nvim-dap').setup {
  49. -- Makes a best effort to setup the various debuggers with
  50. -- reasonable debug configurations
  51. automatic_installation = true,
  52. -- You can provide additional configuration to the handlers,
  53. -- see mason-nvim-dap README for more information
  54. handlers = {},
  55. -- You'll need to check that you have the required things installed
  56. -- online, please don't ask me how to install them :)
  57. ensure_installed = {
  58. -- Update this to ensure that you have the debuggers for the langs you want
  59. 'delve',
  60. },
  61. }
  62. -- Dap UI setup
  63. -- For more information, see |:help nvim-dap-ui|
  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. controls = {
  70. icons = {
  71. pause = '⏸',
  72. play = '▶',
  73. step_into = '⏎',
  74. step_over = '⏭',
  75. step_out = '⏮',
  76. step_back = 'b',
  77. run_last = '▶▶',
  78. terminate = '⏹',
  79. disconnect = '⏏',
  80. },
  81. },
  82. }
  83. -- Change breakpoint icons
  84. -- vim.api.nvim_set_hl(0, 'DapBreak', { fg = '#e51400' })
  85. -- vim.api.nvim_set_hl(0, 'DapStop', { fg = '#ffcc00' })
  86. -- local breakpoint_icons = vim.g.have_nerd_font
  87. -- and { Breakpoint = '', BreakpointCondition = '', BreakpointRejected = '', LogPoint = '', Stopped = '' }
  88. -- or { Breakpoint = '●', BreakpointCondition = '⊜', BreakpointRejected = '⊘', LogPoint = '◆', Stopped = '⭔' }
  89. -- for type, icon in pairs(breakpoint_icons) do
  90. -- local tp = 'Dap' .. type
  91. -- local hl = (type == 'Stopped') and 'DapStop' or 'DapBreak'
  92. -- vim.fn.sign_define(tp, { text = icon, texthl = hl, numhl = hl })
  93. -- end
  94. dap.listeners.after.event_initialized['dapui_config'] = dapui.open
  95. dap.listeners.before.event_terminated['dapui_config'] = dapui.close
  96. dap.listeners.before.event_exited['dapui_config'] = dapui.close
  97. -- Install golang specific config
  98. require('dap-go').setup {
  99. delve = {
  100. -- On Windows delve must be run attached or it crashes.
  101. -- See https://github.com/leoluz/nvim-dap-go/blob/main/README.md#configuring
  102. detached = vim.fn.has 'win32' == 0,
  103. },
  104. }
  105. end,
  106. }