@@ -62,74 +62,48 @@ function M._format_status_text(status)
6262end
6363
6464local function unsubscribe_session_status_event (manager )
65- -- No-op: disable session.status event subscription introduced recently.
66- -- Reverting session.status handling to avoid interfering with existing
67- -- behavior. This keeps the loading animation logic focused on job_count
68- -- and user_message_count as before.
69- return
65+ if manager and M ._animation .status_event_manager == manager then
66+ manager :unsubscribe (' session.status' , M .on_session_status )
67+ M ._animation .status_event_manager = nil
68+ end
7069end
7170
7271local function subscribe_session_status_event (manager )
73- -- No-op: do not subscribe to session.status events. See note in
74- -- unsubscribe_session_status_event for rationale.
75- return
76- end
77-
78- local function is_active_session_busy ()
79- local active_session = state .active_session
80- local session_id = active_session and active_session .id
81- if session_id and ((state .user_message_count or {})[session_id ] or 0 ) > 0 then
82- return true
72+ if not manager then
73+ return
8374 end
8475
85- local ok , question_window = pcall (require , ' opencode.ui.question_window' )
86- if ok and question_window .has_question and question_window .belongs_to_active_session then
87- local current_question = question_window ._current_question
88- if question_window .has_question () and question_window .belongs_to_active_session (current_question ) then
89- return true
90- end
76+ if M ._animation .status_event_manager and M ._animation .status_event_manager ~= manager then
77+ unsubscribe_session_status_event (M ._animation .status_event_manager )
9178 end
9279
93- if M ._animation .status_data and M . _animation . status_data . type ~= ' idle ' then
94- return true
80+ if M ._animation .status_event_manager == manager then
81+ return
9582 end
9683
97- return state .jobs .is_running ()
84+ manager :subscribe (' session.status' , M .on_session_status )
85+ M ._animation .status_event_manager = manager
9886end
9987
10088function M .on_session_status (properties )
101- -- Disabled: Ignore session.status updates to keep loading animation
102- -- behavior stable. Previously this updated status_data and triggered
103- -- a render which caused regressions in some environments.
104- return
89+ if not properties or type (properties ) ~= ' table' then
90+ return
91+ end
92+
93+ local active_session = state .active_session
94+ if active_session and active_session .id and properties .sessionID ~= active_session .id then
95+ return
96+ end
97+
98+ M ._animation .status_data = properties .status
99+ M .render (state .windows )
105100end
106101
107102local function on_active_session_change (_ , new_session , old_session )
108103 local new_id = new_session and new_session .id
109104 local old_id = old_session and old_session .id
110105 if new_id ~= old_id then
111106 M ._animation .status_data = nil
112- if is_active_session_busy () then
113- M .start (state .windows )
114- else
115- M .stop ()
116- end
117- end
118- end
119-
120- local function on_user_message_count_change ()
121- if not state .windows then
122- return
123- end
124-
125- if is_active_session_busy () then
126- if not M .is_running () then
127- M .start (state .windows )
128- else
129- M .render (state .windows )
130- end
131- else
132- M .stop ()
133107 end
134108end
135109
@@ -164,7 +138,7 @@ M.render = vim.schedule_wrap(function(windows)
164138 return false
165139 end
166140
167- if not is_active_session_busy () then
141+ if not state . jobs . is_running () then
168142 M .stop ()
169143 return false
170144 end
@@ -194,7 +168,7 @@ function M._start_animation_timer(windows)
194168 on_tick = function ()
195169 M ._animation .current_frame = M ._next_frame ()
196170 M .render (state .windows )
197- if is_active_session_busy () then
171+ if state . jobs . is_running () then
198172 return true
199173 else
200174 M .stop ()
@@ -240,32 +214,25 @@ local function on_running_change(_, new_value)
240214 return
241215 end
242216
243- if (new_value and new_value > 0 ) or is_active_session_busy () then
244- if not M .is_running () then
245- M .start (state .windows )
246- else
247- M .render (state .windows )
248- end
217+ if not M .is_running () and new_value and new_value > 0 then
218+ M .start (state .windows )
249219 else
250220 M .stop ()
251221 end
252222end
253223
254224function M .setup ()
255225 state .store .subscribe (' job_count' , on_running_change )
256- state .store .subscribe (' user_message_count' , on_user_message_count_change )
257226 state .store .subscribe (' active_session' , on_active_session_change )
258- if is_active_session_busy () then
259- M .start (state .windows )
260- else
261- M .stop ()
262- end
227+ state .store .subscribe (' event_manager' , on_event_manager_change )
228+ subscribe_session_status_event (state .event_manager )
263229end
264230
265231function M .teardown ()
266232 state .store .unsubscribe (' job_count' , on_running_change )
267- state .store .unsubscribe (' user_message_count' , on_user_message_count_change )
268233 state .store .unsubscribe (' active_session' , on_active_session_change )
234+ state .store .unsubscribe (' event_manager' , on_event_manager_change )
235+ unsubscribe_session_status_event (M ._animation .status_event_manager )
269236 M ._animation .status_data = nil
270237end
271238
0 commit comments