dap.lua 3.6 KB

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