dap.lua 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. local M = {}
  2. M.config = function()
  3. lvim.builtin.dap = {
  4. active = false,
  5. on_config_done = nil,
  6. breakpoint = {
  7. text = lvim.icons.ui.Bug,
  8. texthl = "DiagnosticSignError",
  9. linehl = "",
  10. numhl = "",
  11. },
  12. breakpoint_rejected = {
  13. text = lvim.icons.ui.Bug,
  14. texthl = "DiagnosticSignError",
  15. linehl = "",
  16. numhl = "",
  17. },
  18. stopped = {
  19. text = lvim.icons.ui.BoldArrowRight,
  20. texthl = "DiagnosticSignWarn",
  21. linehl = "Visual",
  22. numhl = "DiagnosticSignWarn",
  23. },
  24. ui = {
  25. auto_open = true,
  26. },
  27. }
  28. end
  29. M.setup = function()
  30. local dap = require "dap"
  31. if lvim.use_icons then
  32. vim.fn.sign_define("DapBreakpoint", lvim.builtin.dap.breakpoint)
  33. vim.fn.sign_define("DapBreakpointRejected", lvim.builtin.dap.breakpoint_rejected)
  34. vim.fn.sign_define("DapStopped", lvim.builtin.dap.stopped)
  35. end
  36. lvim.builtin.which_key.mappings["d"] = {
  37. name = "Debug",
  38. t = { "<cmd>lua require'dap'.toggle_breakpoint()<cr>", "Toggle Breakpoint" },
  39. b = { "<cmd>lua require'dap'.step_back()<cr>", "Step Back" },
  40. c = { "<cmd>lua require'dap'.continue()<cr>", "Continue" },
  41. C = { "<cmd>lua require'dap'.run_to_cursor()<cr>", "Run To Cursor" },
  42. d = { "<cmd>lua require'dap'.disconnect()<cr>", "Disconnect" },
  43. g = { "<cmd>lua require'dap'.session()<cr>", "Get Session" },
  44. i = { "<cmd>lua require'dap'.step_into()<cr>", "Step Into" },
  45. o = { "<cmd>lua require'dap'.step_over()<cr>", "Step Over" },
  46. u = { "<cmd>lua require'dap'.step_out()<cr>", "Step Out" },
  47. p = { "<cmd>lua require'dap'.pause()<cr>", "Pause" },
  48. r = { "<cmd>lua require'dap'.repl.toggle()<cr>", "Toggle Repl" },
  49. s = { "<cmd>lua require'dap'.continue()<cr>", "Start" },
  50. q = { "<cmd>lua require'dap'.close()<cr>", "Quit" },
  51. U = { "<cmd>lua require'dapui'.toggle()<cr>", "Toggle UI" },
  52. }
  53. if lvim.builtin.dap.on_config_done then
  54. lvim.builtin.dap.on_config_done(dap)
  55. end
  56. end
  57. M.setup_ui = function()
  58. local dap = require "dap"
  59. local dapui = require "dapui"
  60. dapui.setup {
  61. expand_lines = true,
  62. icons = { expanded = "", collapsed = "", circular = "" },
  63. mappings = {
  64. -- Use a table to apply multiple mappings
  65. expand = { "<CR>", "<2-LeftMouse>" },
  66. open = "o",
  67. remove = "d",
  68. edit = "e",
  69. repl = "r",
  70. toggle = "t",
  71. },
  72. layouts = {
  73. {
  74. elements = {
  75. { id = "scopes", size = 0.33 },
  76. { id = "breakpoints", size = 0.17 },
  77. { id = "stacks", size = 0.25 },
  78. { id = "watches", size = 0.25 },
  79. },
  80. size = 0.33,
  81. position = "right",
  82. },
  83. {
  84. elements = {
  85. { id = "repl", size = 0.45 },
  86. { id = "console", size = 0.55 },
  87. },
  88. size = 0.27,
  89. position = "bottom",
  90. },
  91. },
  92. floating = {
  93. max_height = 0.9,
  94. max_width = 0.5, -- Floats will be treated as percentage of your screen.
  95. border = vim.g.border_chars, -- Border style. Can be 'single', 'double' or 'rounded'
  96. mappings = {
  97. close = { "q", "<Esc>" },
  98. },
  99. },
  100. }
  101. if lvim.builtin.dap.ui.auto_open then
  102. dap.listeners.after.event_initialized["dapui_config"] = function()
  103. dapui.open()
  104. end
  105. -- dap.listeners.before.event_terminated["dapui_config"] = function()
  106. -- dapui.close()
  107. -- end
  108. -- dap.listeners.before.event_exited["dapui_config"] = function()
  109. -- dapui.close()
  110. -- end
  111. end
  112. end
  113. return M