From 336490e550ef521f95b0ade32ecb3c44d58c195d Mon Sep 17 00:00:00 2001 From: Mitchell Hingley Date: Thu, 10 Sep 2026 11:27:21 -0400 Subject: [PATCH] fixing dap-ui dependencies/timing, added cdu for dap-ui toggle --- lua/config/keymaps.lua | 3 +++ lua/plugins/debugger.lua | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lua/config/keymaps.lua b/lua/config/keymaps.lua index 0c1151d..1aa9206 100644 --- a/lua/config/keymaps.lua +++ b/lua/config/keymaps.lua @@ -55,4 +55,7 @@ if status_ok then vim.keymap.set("n", "cdh", function() require("dap.ui.widgets").hover() end, { desc = "DAP: Hover Variable Value" }) + vim.keymap.set("n", "cdu", function() + require("dapui").toggle() + end, { desc = "Debug: Toggle UI" }) end diff --git a/lua/plugins/debugger.lua b/lua/plugins/debugger.lua index 9d5977b..a6f86f5 100644 --- a/lua/plugins/debugger.lua +++ b/lua/plugins/debugger.lua @@ -131,9 +131,18 @@ return { }) -- Automatically open/close DAP UI panels - 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 + -- Defer the open so nvim-dap-ui's async (nio) element buffers are ready. + -- Opening synchronously from inside the DAP event listener races buffer + -- creation and throws "layout.lua: Invalid buffer id: -1". + dap.listeners.after.event_initialized["dapui_config"] = function() + vim.schedule(function() dapui.open() end) + end + dap.listeners.before.event_terminated["dapui_config"] = function() + vim.schedule(function() dapui.close() end) + end + dap.listeners.before.event_exited["dapui_config"] = function() + vim.schedule(function() dapui.close() end) + end -- Step 2 & 3 configurations will go here... -- 1. Detect operating system