101101
102102local function fetch_session ()
103103 local session = state .active_session
104- if not state . active_session or not session or session == ' ' then
104+ if not session or not session or session == ' ' then
105105 return Promise .new ():resolve (nil )
106106 end
107107
120120function M ._render_full_session_data (session_data )
121121 M .reset ()
122122
123+ if not state .active_session then
124+ return
125+ end
126+
123127 local revert_index = nil
124128
125129 -- local event_manager = state.event_manager
174178--- Auto-scroll to bottom if user was already at bottom
175179--- Respects cursor position if user has scrolled up
176180function M .scroll_to_bottom ()
181+ if not state .windows or not state .windows .output_buf or not state .windows .output_win then
182+ return
183+ end
184+
177185 local ok , line_count = pcall (vim .api .nvim_buf_line_count , state .windows .output_buf )
178186 if not ok then
179187 return
@@ -185,6 +193,8 @@ function M.scroll_to_bottom()
185193 local is_focused = vim .api .nvim_get_current_win () == state .windows .output_win
186194
187195 local prev_line_count = M ._prev_line_count or 0
196+
197+ --- @cast line_count integer
188198 M ._prev_line_count = line_count
189199
190200 local was_at_bottom = (botline >= prev_line_count ) or prev_line_count == 0
392402--- @param message { info : MessageInfo } Event properties
393403--- @param revert_index ? integer Revert index in session , if applicable
394404function M .on_message_updated (message , revert_index )
405+ if not state .active_session or not state .messages then
406+ return
407+ end
408+
395409 local msg = message --[[ @as OpencodeMessage]]
396- if not msg or not msg .info or not msg .info .id or not msg .info .sessionID or not state . active_session then
410+ if not msg or not msg .info or not msg .info .id or not msg .info .sessionID then
397411 return
398412 end
399413
555569--- Removes message and all its parts from buffer
556570--- @param properties { sessionID : string , messageID : string } Event properties
557571function M .on_message_removed (properties )
558- if not properties then
572+ if not properties or not state . messages then
559573 return
560574 end
561575
648662
649663--- Event handler for permission.replied events
650664--- Re-renders part after permission is resolved
651- --- @param properties { sessionID : string , permissionID : string , response : string } Event properties
665+ --- @param properties { sessionID : string , permissionID : string , response : string }|{} Event properties
652666function M .on_permission_replied (properties )
653667 if not properties then
654668 return
@@ -665,7 +679,7 @@ function M.on_permission_replied(properties)
665679 end
666680end
667681
668- function M .on_file_edited (properties )
682+ function M .on_file_edited (_ )
669683 vim .cmd (' checktime' )
670684end
671685
0 commit comments