debug.lua 3.1 KB

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