dap.lua 3.8 KB

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