debug.lua 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. config = function()
  24. local dap = require 'dap'
  25. local dapui = require 'dapui'
  26. require('mason-nvim-dap').setup {
  27. -- Makes a best effort to setup the various debuggers with
  28. -- reasonable debug configurations
  29. automatic_setup = true,
  30. -- You can provide additional configuration to the handlers,
  31. -- see mason-nvim-dap README for more information
  32. handlers = {},
  33. -- You'll need to check that you have the required things installed
  34. -- online, please don't ask me how to install them :)
  35. ensure_installed = {
  36. -- Update this to ensure that you have the debuggers for the langs you want
  37. 'delve',
  38. },
  39. }
  40. -- Basic debugging keymaps, feel free to change to your liking!
  41. vim.keymap.set('n', '<F5>', dap.continue, { desc = 'Debug: Start/Continue' })
  42. vim.keymap.set('n', '<F1>', dap.step_into, { desc = 'Debug: Step Into' })
  43. vim.keymap.set('n', '<F2>', dap.step_over, { desc = 'Debug: Step Over' })
  44. vim.keymap.set('n', '<F3>', dap.step_out, { desc = 'Debug: Step Out' })
  45. vim.keymap.set('n', '<leader>b', dap.toggle_breakpoint, { desc = 'Debug: Toggle Breakpoint' })
  46. vim.keymap.set('n', '<leader>B', function()
  47. dap.set_breakpoint(vim.fn.input 'Breakpoint condition: ')
  48. end, { desc = 'Debug: Set Breakpoint' })
  49. -- Dap UI setup
  50. -- For more information, see |:help nvim-dap-ui|
  51. dapui.setup {
  52. -- Set icons to characters that are more likely to work in every terminal.
  53. -- Feel free to remove or use ones that you like more! :)
  54. -- Don't feel like these are good choices.
  55. icons = { expanded = '▾', collapsed = '▸', current_frame = '*' },
  56. controls = {
  57. icons = {
  58. pause = '⏸',
  59. play = '▶',
  60. step_into = '⏎',
  61. step_over = '⏭',
  62. step_out = '⏮',
  63. step_back = 'b',
  64. run_last = '▶▶',
  65. terminate = '⏹',
  66. disconnect = '⏏',
  67. },
  68. },
  69. }
  70. -- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception.
  71. vim.keymap.set('n', '<F7>', dapui.toggle, { desc = 'Debug: See last session result.' })
  72. dap.listeners.after.event_initialized['dapui_config'] = dapui.open
  73. dap.listeners.before.event_terminated['dapui_config'] = dapui.close
  74. dap.listeners.before.event_exited['dapui_config'] = dapui.close
  75. -- Install golang specific config
  76. require('dap-go').setup()
  77. end,
  78. }