From 8dc460c0aae0b88960c4088bcfb5e75deb0a0f44 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Sun, 12 Apr 2026 15:14:29 -0600 Subject: [PATCH] fix: forward-declare source_window so ensure_dapui can see it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit source_window was defined around line 880 but referenced in the before.event_stopped listener inside ensure_dapui (around line 730). Lua closures only capture upvalues that existed as locals BEFORE the closure was created — source_window fell back to a global lookup which resolved to nil, breaking every attempt to start a debug session. Forward-declare `local source_window` at the top of the file and assign (rather than declare) the implementation later. Both ensure_dapui's listener and the later call sites now refer to the same upvalue. Co-Authored-By: Claude Opus 4.6 (1M context) --- lua/turbo-debug/mode.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lua/turbo-debug/mode.lua b/lua/turbo-debug/mode.lua index f7e2793..816a14c 100644 --- a/lua/turbo-debug/mode.lua +++ b/lua/turbo-debug/mode.lua @@ -7,6 +7,11 @@ local active = false local active_win = nil local saved_winbar = nil +-- Forward declaration so listeners registered in ensure_dapui (which is +-- defined earlier in the file than source_window) can still reference it +-- as an upvalue rather than a nil global. +local source_window + -- two floating chrome bars (both independent of lualine): -- sbar = status bar pinned at the TOP of the editor. -- Row 0: turbo-debug · {dap status} · DEBUG · STATE @@ -870,7 +875,8 @@ end -- current buffer's filetype to pick a launch configuration, so when the user -- presses `c` while focused in a dapui pane (filetype=dapui_scopes, etc.), -- we need to temporarily borrow a source window's context. -local function source_window() +-- NOTE: assigned (not declared) — forward-declared at top of file. +source_window = function() -- prefer the current window if it's a source local cur = vim.api.nvim_get_current_win() local function is_source(w)