From 3999f9e6639eba12708689b6bb58353da198210a Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 12 Mar 2023 21:19:25 +0200 Subject: Add plugin dap mappings --- lua/user/keys.lua | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'lua/user') diff --git a/lua/user/keys.lua b/lua/user/keys.lua index 689ff13..77edfa8 100644 --- a/lua/user/keys.lua +++ b/lua/user/keys.lua @@ -331,6 +331,45 @@ map("n", "q", function() end end, { desc = "Toggle quickfix window" }) +-- Dap (debugging) +local dap_ok, dap = pcall(require, "dap") +local dap_ui_ok, ui = pcall(require, "dapui") + +if not (dap_ok and dap_ui_ok) then + require("notify")("nvim-dap or dap-ui not installed!", "warning") -- nvim-notify is a separate plugin, I recommend it too! + return +end + +vim.fn.sign_define('DapBreakpoint', { text = '🐞' }) + +-- Start debugging session +vim.keymap.set("n", "ds", function() + dap.continue() + ui.toggle({}) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("=", false, true, true), "n", false) -- Spaces buffers evenly +end) + +-- Set breakpoints, get variable values, step into/out of functions, etc. +map("n", "dl", require("dap.ui.widgets").hover) +map("n", "dc", dap.continue) +map("n", "db", dap.toggle_breakpoint) +map("n", "dn", dap.step_over) +map("n", "di", dap.step_into) +map("n", "do", dap.step_out) +map("n", "dC", function() + dap.clear_breakpoints() + require("notify")("Breakpoints cleared", "warn") +end) + +-- Close debugger and clear breakpoints +map("n", "de", function() + dap.clear_breakpoints() + ui.toggle({}) + dap.terminate() + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("=", false, true, true), "n", false) + require("notify")("Debugger session ended", "warn") +end) + -- Dashboard map("n", "db", "Dashboard") -- cgit v1.2.3