Skip to content

Commit 77045bd

Browse files
committed
chore: diagnostic cleanup
1 parent d5a51b5 commit 77045bd

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

lua/opencode/state.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
local config = require('opencode.config')
22

33
---@class OpencodeWindowState
4-
---@field input_win number|nil
5-
---@field output_win number|nil
6-
---@field footer_win number|nil
7-
---@field footer_buf number|nil
8-
---@field input_buf number|nil
9-
---@field output_buf number|nil
4+
---@field input_win integer|nil
5+
---@field output_win integer|nil
6+
---@field footer_win integer|nil
7+
---@field footer_buf integer|nil
8+
---@field input_buf integer|nil
9+
---@field output_buf integer|nil
1010

1111
---@class OpencodeState
1212
---@field windows OpencodeWindowState|nil

lua/opencode/ui/formatter.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ function M._format_tool(output, part)
555555
M._format_action(output, icons.get('tool') .. ' tool', tool)
556556
end
557557

558-
if part.state.status == 'error' then
558+
if part.state.status == 'error' and part.state.error then
559559
output:add_line('')
560560
M._format_callout(output, 'ERROR', part.state.error)
561561
---@diagnostic disable-next-line: undefined-field

lua/opencode/ui/output.lua

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
local state = require('opencode.state')
2-
local config = require('opencode.config')
31
local Output = {}
42
Output.__index = Output
53

64
---@class Output
7-
---@field lines table<number, string>
5+
---@field lines string[]
86
---@field extmarks table<number, OutputExtmark>
97
---@field actions OutputAction[]
108
---@field add_line fun(self: Output, line: string, fit?: boolean): number
@@ -31,9 +29,8 @@ end
3129

3230
---Add a new line
3331
---@param line string
34-
---@param fit? boolean Optional parameter to control line fitting
3532
---@return number index The index of the added line
36-
function Output:add_line(line, fit)
33+
function Output:add_line(line)
3734
table.insert(self.lines, line)
3835
return #self.lines
3936
end

lua/opencode/ui/renderer.lua

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ end
101101

102102
local 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

@@ -120,6 +120,10 @@ end
120120
function 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
@@ -174,6 +178,10 @@ end
174178
---Auto-scroll to bottom if user was already at bottom
175179
---Respects cursor position if user has scrolled up
176180
function 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
@@ -392,8 +402,12 @@ end
392402
---@param message {info: MessageInfo} Event properties
393403
---@param revert_index? integer Revert index in session, if applicable
394404
function 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

@@ -555,7 +569,7 @@ end
555569
---Removes message and all its parts from buffer
556570
---@param properties {sessionID: string, messageID: string} Event properties
557571
function M.on_message_removed(properties)
558-
if not properties then
572+
if not properties or not state.messages then
559573
return
560574
end
561575

@@ -648,7 +662,7 @@ end
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
652666
function M.on_permission_replied(properties)
653667
if not properties then
654668
return
@@ -665,7 +679,7 @@ function M.on_permission_replied(properties)
665679
end
666680
end
667681

668-
function M.on_file_edited(properties)
682+
function M.on_file_edited(_)
669683
vim.cmd('checktime')
670684
end
671685

0 commit comments

Comments
 (0)