From fe9da14d85235cea756696fc17414d15efb848a0 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Mon, 12 Jun 2023 02:59:34 +0200 Subject: [PATCH] feat: add mapping options for nvim-dap --- modules/debugger/nvim-dap/config.nix | 49 ++++++++++++++------------ modules/debugger/nvim-dap/nvim-dap.nix | 22 ++++++++++++ 2 files changed, 49 insertions(+), 22 deletions(-) diff --git a/modules/debugger/nvim-dap/config.nix b/modules/debugger/nvim-dap/config.nix index 805955a..35610a8 100644 --- a/modules/debugger/nvim-dap/config.nix +++ b/modules/debugger/nvim-dap/config.nix @@ -6,6 +6,11 @@ with lib; with builtins; let cfg = config.vim.debugger.nvim-dap; + self = import ./nvim-dap.nix { + inherit lib; + }; + mappingDefinitions = self.options.vim.debugger.nvim-dap.mappings; + mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions; in { config = mkMerge [ (mkIf cfg.enable { @@ -16,37 +21,36 @@ in { # TODO customizable keymaps nvim-dap = nvim.dag.entryAnywhere '' local dap = require("dap") - local opts = { noremap = true, silent = true } - - vim.keymap.set("n", "d.", "lua require'dap'.run_last()", opts) - vim.keymap.set("n", "dR", "lua require'dap'.restart()", opts) - vim.keymap.set("n", "dq", "lua require'dap'.terminate()", opts) - vim.keymap.set("n", "db", "lua require'dap'.toggle_breakpoint()", opts) - vim.keymap.set("n", "dc", "lua require'dap'.continue()", opts) - vim.keymap.set("n", "dl", "lua require'dap'.set_breakpoint(nil, nil, vim.fn.input('Log point message: '))", opts) - vim.keymap.set("n", "dgb", "lua require'dap'.continue()", opts) - vim.keymap.set("n", "dgc", "lua require'dap'.run_to_cursor()", opts) - vim.keymap.set("n", "dgi", "lua require'dap'.step_into()", opts) - vim.keymap.set("n", "dgo", "lua require'dap'.step_out()", opts) - vim.keymap.set("n", "dgI", "lua require'dap'.down()", opts) - vim.keymap.set("n", "dgO", "lua require'dap'.up()", opts) - vim.keymap.set("n", "dgj", "lua require'dap'.step_over()", opts) - vim.keymap.set("n", "dgk", "lua require'dap'.step_back()", opts) - vim.keymap.set("n", "dr", "lua require'dap'.repl.toggle()", opts) - vim.keymap.set("n", "dh", "lua require'dap.ui.widgets'.hover()", opts) - ''; } // mapAttrs (_: v: (nvim.dag.entryAfter ["nvim-dap"] v)) cfg.sources; + + vim.maps.normal = mkMerge [ + (mkSetLuaBinding mappings.continue "require('dap').continue") + (mkSetLuaBinding mappings.restart "require('dap').restart") + (mkSetLuaBinding mappings.terminate "require('dap').terminate") + (mkSetLuaBinding mappings.runLast "require('dap').run_last") + + (mkSetLuaBinding mappings.toggleRepl "require('dap').repl.toggle") + (mkSetLuaBinding mappings.hover "require('dap.ui.widgets').hover") + (mkSetLuaBinding mappings.toggleBreakpoint "require('dap').toggle_breakpoint") + + (mkSetLuaBinding mappings.runToCursor "require('dap').run_to_cursor") + (mkSetLuaBinding mappings.stepInto "require('dap').step_into") + (mkSetLuaBinding mappings.stepOut "require('dap').step_out") + (mkSetLuaBinding mappings.stepOver "require('dap').step_over") + (mkSetLuaBinding mappings.stepBack "require('dap').step_back") + + (mkSetLuaBinding mappings.goUp "require('dap').up") + (mkSetLuaBinding mappings.goDown "require('dap').down") + ]; }) (mkIf (cfg.enable && cfg.ui.enable) { vim.startPlugins = ["nvim-dap-ui"]; vim.luaConfigRC.nvim-dap-ui = nvim.dag.entryAfter ["nvim-dap"] ('' local dapui = require("dapui") - require("dapui").setup() - vim.keymap.set("n", "du", "lua require'dapui'.toggle()", opts) - vim.keymap.set({ "n", "v" }, "dd", "lua require'dapui'.eval()", opts) + dapui.setup() '' + optionalString cfg.ui.autoStart '' dap.listeners.after.event_initialized["dapui_config"] = function() @@ -59,6 +63,7 @@ in { dapui.close() end ''); + vim.maps.normal = mkSetLuaBinding mappings.toggleDapUI "require('dapui').toggle"; }) ]; } diff --git a/modules/debugger/nvim-dap/nvim-dap.nix b/modules/debugger/nvim-dap/nvim-dap.nix index 159f88e..b0fcb5e 100644 --- a/modules/debugger/nvim-dap/nvim-dap.nix +++ b/modules/debugger/nvim-dap/nvim-dap.nix @@ -17,5 +17,27 @@ with lib; { description = "List of debuggers to install"; type = with types; attrsOf string; }; + + mappings = { + continue = mkMappingOption "Contiue" "dc"; + restart = mkMappingOption "Restart" "dR"; + terminate = mkMappingOption "Terminate" "dq"; + runLast = mkMappingOption "Re-run Last Debug Session" "d."; + + toggleRepl = mkMappingOption "Toggle Repl" "dr"; + hover = mkMappingOption "Hover" "dh"; + toggleBreakpoint = mkMappingOption "Toggle breakpoint" "db"; + + runToCursor = mkMappingOption "Continue to the current cursor" "dgc"; + stepInto = mkMappingOption "Step into function" "dgi"; + stepOut = mkMappingOption "Step out of function" "dgo"; + stepOver = mkMappingOption "Next step" "dgj"; + stepBack = mkMappingOption "Step back" "dgk"; + + goUp = mkMappingOption "Go up stacktrace" "dvo"; + goDown = mkMappingOption "Go down stacktrace" "dvi"; + + toggleDapUI = mkMappingOption "Toggle DAP-UI" "du"; + }; }; }