hmors

.local/share/nvim/lazy/nvim-dap/lua/dap/init.lua

Jul 7th, 2025
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.09 KB | Source Code | 0 0
  1. local dap, dapui, hydra = require "dap", require "dapui", require "hydra"
  2.  
  3. -- Setup Telescope dap extension
  4. local ok_telescope, telescope = pcall(require, "telescope")
  5. if ok_telescope then
  6.     telescope.load_extension "dap"
  7. end
  8.  
  9. -- Setup cmp dap
  10. local ok_cmp, cmp = pcall(require, "cmp")
  11. if ok_cmp then
  12.     cmp.setup.filetype({ "dap-repl", "dapui_watches" }, {
  13.         sources = cmp.config.sources({
  14.             { name = "dap" },
  15.         }, {
  16.             { name = "buffer" },
  17.         }),
  18.     })
  19. end
  20.  
  21. -- Set Icons
  22. vim.api.nvim_call_function(
  23.  "sign_define",
  24.  { "DapBreakpoint", { linehl = "", text = "", texthl = "diffRemoved", numhl = "" } }
  25. )
  26.  
  27. vim.api.nvim_call_function(
  28.  "sign_define",
  29.  { "DapBreakpointCondition", { linehl = "", text = "", texthl = "diffRemoved", numhl = "" } }
  30. )
  31.  
  32. vim.api.nvim_call_function(
  33.  "sign_define",
  34.  { "DapLogPoint", { linehl = "", text = "", texthl = "diffRemoved", numhl = "" } }
  35. )
  36.  
  37. vim.api.nvim_call_function(
  38.  "sign_define",
  39.  { "DapStopped", { linehl = "GitSignsChangeVirtLn", text = "", texthl = "diffChanged", numhl = "" } }
  40. )
  41.  
  42. vim.api.nvim_call_function(
  43.  "sign_define",
  44.  { "DapBreakpointRejected", { linehl = "", text = "", texthl = "", numhl = "" } }
  45. )
  46.  
  47. -- Setup DAPUI
  48. dapui.setup({
  49.   icons = { collapsed = "", current_frame = "", expanded = "" },
  50.   layouts = {
  51.     {
  52.       elements = { "scopes", "watches", "stacks", "breakpoints" },
  53.       size = 80,
  54.       position = "left",
  55.     },
  56.     { elements = { "console", "repl" }, size = 0.25, position = "bottom" },
  57.   },
  58.   render = { indent = 2 },
  59. })
  60.  
  61.  
  62. -- Setup Virtual Text
  63. require("nvim-dap-virtual-text").setup {}
  64.  
  65. -- Added event for open DAUI
  66. dap.listeners.after.event_initialized['dapui_config'] = function()
  67.  dapui.open()
  68.  
  69. end
  70.  
  71. -- Menu
  72. local hint = [[
  73.  Nvim DAP
  74.  _d_: Start/Continue  _j_: StepOver _k_: StepOut _l_: StepInto ^
  75.  _bp_: Toggle Breakpoint  _bc_: Conditional Breakpoint ^
  76.  _?_: log point ^
  77.  _c_: Run To Cursor ^
  78.  _h_: Show information of the variable under the cursor ^
  79.  _x_: Stop Debbuging ^
  80.  ^^                                                      _<Esc>_
  81. ]]
  82.  
  83.  
  84. hydra {
  85.   name = "dap",
  86.   hint = hint,
  87.   mode = "n",
  88.   config = {
  89.     color = "blue",
  90.     invoke_on_body = true,
  91.     hint = {
  92.       border = "rounded",
  93.       position = "bottom",
  94.     },
  95.   },
  96.   body = "<leader>d",
  97.   heads = {
  98.     { "d", dap.continue },
  99.     { "bp", dap.toggle_breakpoint },
  100.     { "l", dap.step_into },
  101.     { "j", dap.step_over },
  102.     { "k", dap.step_out },
  103.     { "h", dapui.eval },
  104.     { "c", dap.run_to_cursor },
  105.     {
  106.       "bc",
  107.       function()
  108.         vim.ui.input({ prompt = "Condition: " }, function(condition)
  109.           dap.set_breakpoint(condition)
  110.         end)
  111.       end,
  112.     },
  113.     {
  114.       "?",
  115.       function()
  116.         vim.ui.input({ prompt = "Log: " }, function(log)
  117.           dap.set_breakpoint(nil, nil, log)
  118.         end)
  119.       end,
  120.     },
  121.     {
  122.       "x",
  123.       function()
  124.         dap.terminate()
  125.         dapui.close {}
  126.         dap.clear_breakpoints()
  127.       end,
  128.     },
  129.  
  130.     { "<Esc>", nil, { exit = true } },
  131.   },
  132. }
  133.  
Advertisement
Add Comment
Please, Sign In to add comment