Skip to content

Commit 96858d4

Browse files
committed
chore(types): fix some typings and formatting
1 parent a604965 commit 96858d4

File tree

5 files changed

+23
-19
lines changed

5 files changed

+23
-19
lines changed

lua/opencode/core.lua

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ function M.send_message(prompt, opts)
163163
end
164164

165165
local received_message_count = vim.deepcopy(state.user_message_count)
166-
received_message_count[response.info.sessionID] = (received_message_count[response.info.sessionID] ~= nil) and (received_message_count[response.info.sessionID] - 1) or 0
166+
received_message_count[response.info.sessionID] = (received_message_count[response.info.sessionID] ~= nil)
167+
and (received_message_count[response.info.sessionID] - 1)
168+
or 0
167169
state.user_message_count = received_message_count
168170

169171
M.after_run(prompt)
@@ -379,23 +381,25 @@ end
379381

380382
function M._on_user_message_count_change(_, new, old)
381383
if config.hooks and config.hooks.on_done_thinking then
382-
local all_sessions = session.get_all_workspace_sessions() or {}
383-
local done_sessions = vim.tbl_filter(function(s)
384-
local msg_count = new[s.id] or 0
385-
local old_msg_count = (old and old[s.id]) or 0
386-
return msg_count == 0 and old_msg_count > 0
387-
end, all_sessions)
388-
389-
for _, done_session in ipairs(done_sessions) do
390-
pcall(config.hooks.on_done_thinking, done_session)
391-
end
384+
local all_sessions = session.get_all_workspace_sessions() or {}
385+
local done_sessions = vim.tbl_filter(function(s)
386+
local msg_count = new[s.id] or 0
387+
local old_msg_count = (old and old[s.id]) or 0
388+
return msg_count == 0 and old_msg_count > 0
389+
end, all_sessions)
390+
391+
for _, done_session in ipairs(done_sessions) do
392+
pcall(config.hooks.on_done_thinking, done_session)
393+
end
392394
end
393395
end
394396

395397
function M._on_current_permission_change(_, new, old)
396398
local permission_requested = old == nil and new ~= nil
397399
if config.hooks and config.hooks.on_permission_requested and permission_requested then
398-
local local_session = session.get_by_id(state.active_session.id) or {}
400+
local local_session = (state.active_session and state.active_session.id)
401+
and session.get_by_id(state.active_session.id)
402+
or {}
399403
pcall(config.hooks.on_permission_requested, local_session)
400404
end
401405
end

lua/opencode/promise.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function Promise:and_then(callback)
8484
return
8585
end
8686

87-
if type(result) == 'table' and result.and_then then
87+
if Promise.is_promise(result) then
8888
result
8989
:and_then(function(val)
9090
new_promise:resolve(val)
@@ -125,8 +125,7 @@ function Promise:catch(error_callback)
125125
return
126126
end
127127

128-
-- If error callback returns a Promise, chain it
129-
if type(result) == 'table' and result.and_then then
128+
if Promise.is_promise(result) then
130129
result
131130
:and_then(function(val)
132131
new_promise:resolve(val)
@@ -194,6 +193,9 @@ function Promise:is_rejected()
194193
return self._resolved and self._error ~= nil
195194
end
196195

196+
---@generic T
197+
---@param obj T
198+
---@return_cast obj Promise<T>
197199
function Promise.is_promise(obj)
198200
return type(obj) == 'table' and type(obj.and_then) == 'function' and type(obj.catch) == 'function'
199201
end
@@ -203,7 +205,6 @@ end
203205
---@return Promise<T>
204206
function Promise.wrap(obj)
205207
if Promise.is_promise(obj) then
206-
---@cast obj Promise<T>
207208
return obj
208209
else
209210
return Promise.new():resolve(obj)

lua/opencode/session.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ function M.get_last_workspace_session()
115115
return session.parentID == nil --- we don't want child sessions
116116
end, sessions)
117117

118-
-- read the first messages to ensure they have the right path
119-
120118
return main_sessions[1]
121119
end
122120

lua/opencode/types.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
---@field position 'right'|'left' # Position of the UI (default: 'right')
112112
---@field input_position 'bottom'|'top' # Position of the input window (default: 'bottom')
113113
---@field window_width number
114+
---@field zoom_width number
114115
---@field input_height number
115116
---@field picker_width number|nil # Default width for all pickers (nil uses current window width)
116117
---@field display_model boolean

lua/opencode/ui/ui.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ end
245245

246246
function M.toggle_zoom()
247247
local windows = state.windows
248-
if not windows or not state.windows.output_win or not state.windows.input_win then
248+
if not windows or not windows.output_win or not windows.input_win then
249249
return
250250
end
251251

0 commit comments

Comments
 (0)