Skip to content

Commit 0d102c0

Browse files
Danilo Verde RibeiroDanilo Verde Ribeiro
authored andcommitted
fix(hanging_close): clear all windows was hangin neovim
1 parent 1f8da59 commit 0d102c0

2 files changed

Lines changed: 43 additions & 28 deletions

File tree

lua/opencode/context.lua

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,14 +1449,6 @@ local function setup_cache_invalidation()
14491449
context_cache.clear('recent_buffers_' .. bufnr)
14501450
end,
14511451
})
1452-
1453-
-- Clear all caches on VimLeavePre for cleanup
1454-
vim.api.nvim_create_autocmd('VimLeavePre', {
1455-
group = group,
1456-
callback = function()
1457-
context_cache.clear()
1458-
end,
1459-
})
14601452
end
14611453

14621454
-- Initialize cache invalidation

lua/opencode/ui/autocmds.lua

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local output_window = require('opencode.ui.output_window')
33
local IdleDetector = require('opencode.idle')
44
local M = {}
55

6+
---@type IdleDetector|nil
67
local idle_detector = nil
78

89
function M.setup_autocmds(windows)
@@ -18,33 +19,55 @@ function M.setup_autocmds(windows)
1819
callback = function(opts)
1920
local closed_win = tonumber(opts.match)
2021
if vim.tbl_contains(wins, closed_win) then
21-
vim.schedule(function()
22-
require('opencode.ui.ui').close_windows(windows)
23-
end)
22+
-- Guard against git commit workflows that manage their own buffers/windows
23+
for _, win in ipairs(vim.api.nvim_list_wins()) do
24+
if vim.api.nvim_win_is_valid(win) then
25+
local buf = vim.api.nvim_win_get_buf(win)
26+
local ft = vim.api.nvim_get_option_value('filetype', { buf = buf })
27+
if ft == 'gitcommit' or ft == 'NeogitCommitMessage' then
28+
return
29+
end
30+
end
31+
end
32+
-- Immediate protected close without schedule to avoid race conditions
33+
pcall(require('opencode.ui.ui').close_windows, windows)
2434
end
2535
end,
2636
})
2737

2838
-- Setup idle detection for automatic context updates
29-
if idle_detector then
30-
idle_detector:stop()
31-
end
32-
33-
local config = require('opencode.config')
34-
local threshold = config.get('context').idle_threshold or 10000
35-
36-
idle_detector = IdleDetector.new({
37-
threshold = threshold,
39+
-- if idle_detector ~= nil then
40+
-- idle_detector:stop()
41+
-- end
42+
--
43+
-- local config = require('opencode.config')
44+
-- local threshold = config.get('context').idle_threshold or 10000
45+
--
46+
-- idle_detector = IdleDetector.new({
47+
-- threshold = threshold,
48+
-- callback = function()
49+
-- -- Update context only if user is not focused on opencode window
50+
-- if not require('opencode.ui.ui').is_opencode_focused() then
51+
-- local ft = vim.api.nvim_get_option_value('filetype', { buf = 0 })
52+
-- if ft == 'gitcommit' or ft == 'NeogitCommitMessage' then
53+
-- return
54+
-- end
55+
-- require('opencode.context').load()
56+
-- require('opencode.state').last_code_win_before_opencode = vim.api.nvim_get_current_win()
57+
-- end
58+
-- end,
59+
-- })
60+
--
61+
-- idle_detector:start()
62+
63+
-- Defensive cleanup on exit in case window close didn't trigger
64+
vim.api.nvim_create_autocmd('VimLeavePre', {
65+
group = group,
66+
once = true,
3867
callback = function()
39-
-- Update context only if user is not focused on opencode window
40-
if not require('opencode.ui.ui').is_opencode_focused() then
41-
require('opencode.context').load()
42-
require('opencode.state').last_code_win_before_opencode = vim.api.nvim_get_current_win()
43-
end
68+
M.cleanup()
4469
end,
4570
})
46-
47-
idle_detector:start()
4871
end
4972

5073
function M.setup_resize_handler(windows)
@@ -79,7 +102,7 @@ function M.setup_resize_handler(windows)
79102
end
80103

81104
function M.cleanup()
82-
if idle_detector then
105+
if idle_detector ~= nil then
83106
idle_detector:stop()
84107
idle_detector = nil
85108
end

0 commit comments

Comments
 (0)