From 595e76ed2fd1a946f94bff9a989f89f640a2ba29 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Fri, 5 May 2023 15:31:55 +0200 Subject: [PATCH] feat: option to autostart debugger UI --- modules/debugger/nvim-dap/config.nix | 39 ++++++++++++++++++-------- modules/debugger/nvim-dap/nvim-dap.nix | 5 ++++ 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/modules/debugger/nvim-dap/config.nix b/modules/debugger/nvim-dap/config.nix index 60d8a92..cf18897 100644 --- a/modules/debugger/nvim-dap/config.nix +++ b/modules/debugger/nvim-dap/config.nix @@ -7,17 +7,32 @@ with lib; with builtins; let cfg = config.vim.debugger.nvim-dap; in { - config = mkIf cfg.enable { - vim.startPlugins = - [ - "nvim-dap" - ] - ++ optionals cfg.ui.enable [ - "nvim-dap-ui" - ]; + config = mkMerge [ + (mkIf cfg.enable { + vim.startPlugins = ["nvim-dap"]; - vim.luaConfigRC.nvim-dap-ui = nvim.dag.entryAnywhere '' - require("dapui").setup() - ''; - }; + vim.luaConfigRC.nvim-dap = + nvim.dag.entryAnywhere '' + ''; + }) + (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() + '' + + optionalString cfg.ui.autoStart '' + dap.listeners.after.event_initialized["dapui_config"] = function() + dapui.open() + end + dap.listeners.before.event_terminated["dapui_config"] = function() + dapui.close() + end + dap.listeners.before.event_exited["dapui_config"] = function() + dapui.close() + end + ''); + }) + ]; } diff --git a/modules/debugger/nvim-dap/nvim-dap.nix b/modules/debugger/nvim-dap/nvim-dap.nix index 14eb359..1a9f2fe 100644 --- a/modules/debugger/nvim-dap/nvim-dap.nix +++ b/modules/debugger/nvim-dap/nvim-dap.nix @@ -5,6 +5,11 @@ with lib; { ui = { enable = mkEnableOption "Enable UI extension for nvim-dap"; + autoStart = mkOption { + type = types.bool; + default = true; + description = "Automatically Opens and Closes DAP-UI upon starting/closing a debugging session"; + }; }; }; }