Skip to content

Commit b51ad74

Browse files
sudo-teeCopilot
andcommitted
Update lua/opencode/config.lua
Co-authored-by: Copilot <[email protected]>
1 parent dd6dba0 commit b51ad74

29 files changed

Lines changed: 751 additions & 237 deletions

lua/opencode/config.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ M.defaults = {
260260
enabled = false,
261261
capture_streamed_events = false,
262262
show_ids = true,
263-
highlight_changed_lines = true,
263+
highlight_changed_lines = false,
264264
highlight_changed_lines_timeout_ms = 120,
265265
quick_chat = {
266266
keep_session = false,

lua/opencode/id.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,3 @@ function M.get_prefixes()
142142
end
143143

144144
return M
145-

lua/opencode/ui/dialog.lua

Lines changed: 65 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -281,15 +281,22 @@ function Dialog:format_options(output, options)
281281
label = label .. ' - ' .. option.description
282282
end
283283

284-
local line_idx = output:get_line_count()
285284
local is_selected = self._selected_index == i
286285
local line_text = is_selected and string.format(' %d. %s ', i, label) or string.format(' %d. %s', i, label)
287286

288-
output:add_line(line_text)
287+
-- Output uses 0-based indexing for extmarks. The correct target for
288+
-- extmarks is the previous line count (0-based) because add_line will
289+
-- append a new line and increase the 1-based line count. Capture the
290+
-- current count first and then add the line so we can use that 0-based
291+
-- index for extmarks.
292+
-- add_line returns a 1-based line index; Output extmarks use 0-based
293+
-- keys, so subtract 1 to get the correct extmark key.
294+
local added_idx = output:add_line(line_text)
289295

290296
if is_selected then
291-
output:add_extmark(line_idx, { line_hl_group = 'OpencodeDialogOptionHover' } --[[@as OutputExtmark]])
292-
output:add_extmark(line_idx, {
297+
local extmark_idx = added_idx - 1
298+
output:add_extmark(extmark_idx, { line_hl_group = 'OpencodeDialogOptionHover' } --[[@as OutputExtmark]])
299+
output:add_extmark(extmark_idx, {
293300
start_col = 2,
294301
virt_text = { { '', 'OpencodeDialogOptionHover' } },
295302
virt_text_pos = 'overlay',
@@ -313,11 +320,16 @@ function Dialog:_setup_keymaps()
313320
if keymaps.up then
314321
for _, key in ipairs(keymaps.up) do
315322
if key and key ~= '' then
316-
vim.keymap.set('n', key, function()
317-
self:navigate(-1)
318-
end, vim.tbl_extend('force', keymap_opts, {
319-
desc = 'Dialog: navigate up',
320-
}))
323+
vim.keymap.set(
324+
'n',
325+
key,
326+
function()
327+
self:navigate(-1)
328+
end,
329+
vim.tbl_extend('force', keymap_opts, {
330+
desc = 'Dialog: navigate up',
331+
})
332+
)
321333
table.insert(self._keymaps, key)
322334
end
323335
end
@@ -326,31 +338,46 @@ function Dialog:_setup_keymaps()
326338
if keymaps.down then
327339
for _, key in ipairs(keymaps.down) do
328340
if key and key ~= '' then
329-
vim.keymap.set('n', key, function()
330-
self:navigate(1)
331-
end, vim.tbl_extend('force', keymap_opts, {
332-
desc = 'Dialog: navigate down',
333-
}))
341+
vim.keymap.set(
342+
'n',
343+
key,
344+
function()
345+
self:navigate(1)
346+
end,
347+
vim.tbl_extend('force', keymap_opts, {
348+
desc = 'Dialog: navigate down',
349+
})
350+
)
334351
table.insert(self._keymaps, key)
335352
end
336353
end
337354
end
338355

339356
if keymaps.select and keymaps.select ~= '' then
340-
vim.keymap.set('n', keymaps.select, function()
341-
self:select()
342-
end, vim.tbl_extend('force', keymap_opts, {
343-
desc = 'Dialog: select option',
344-
}))
357+
vim.keymap.set(
358+
'n',
359+
keymaps.select,
360+
function()
361+
self:select()
362+
end,
363+
vim.tbl_extend('force', keymap_opts, {
364+
desc = 'Dialog: select option',
365+
})
366+
)
345367
table.insert(self._keymaps, keymaps.select)
346368
end
347369

348370
if keymaps.dismiss and keymaps.dismiss ~= '' then
349-
vim.keymap.set('n', keymaps.dismiss, function()
350-
self:dismiss()
351-
end, vim.tbl_extend('force', keymap_opts, {
352-
desc = 'Dialog: dismiss',
353-
}))
371+
vim.keymap.set(
372+
'n',
373+
keymaps.dismiss,
374+
function()
375+
self:dismiss()
376+
end,
377+
vim.tbl_extend('force', keymap_opts, {
378+
desc = 'Dialog: dismiss',
379+
})
380+
)
354381
table.insert(self._keymaps, keymaps.dismiss)
355382
end
356383

@@ -359,15 +386,20 @@ function Dialog:_setup_keymaps()
359386
local number_keymap_opts = vim.tbl_extend('force', keymap_opts, { nowait = true })
360387
for i = 1, math.min(option_count, 9) do
361388
local key = tostring(i)
362-
vim.keymap.set('n', key, function()
363-
if not self._active or not self._config.check_focused() then
364-
return
365-
end
366-
self._selected_index = i
367-
self._config.on_select(i)
368-
end, vim.tbl_extend('force', number_keymap_opts, {
369-
desc = 'Dialog: select option ' .. key,
370-
}))
389+
vim.keymap.set(
390+
'n',
391+
key,
392+
function()
393+
if not self._active or not self._config.check_focused() then
394+
return
395+
end
396+
self._selected_index = i
397+
self._config.on_select(i)
398+
end,
399+
vim.tbl_extend('force', number_keymap_opts, {
400+
desc = 'Dialog: select option ' .. key,
401+
})
402+
)
371403
table.insert(self._keymaps, key)
372404
end
373405
end

lua/opencode/ui/formatter.lua

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,13 @@ function M.format_message_header(message)
173173
local display_name
174174
if role == 'assistant' then
175175
local mode = message.info.mode
176-
if mode and mode ~= '' then
177-
display_name = mode:upper()
178-
elseif state.current_mode and state.current_mode ~= '' then
179-
display_name = state.current_mode:upper()
180-
else
181-
display_name = 'ASSISTANT'
182-
end
176+
if mode and mode ~= '' then
177+
display_name = mode:upper()
178+
elseif state.current_mode and state.current_mode ~= '' then
179+
display_name = state.current_mode:upper()
180+
else
181+
display_name = 'ASSISTANT'
182+
end
183183
else
184184
display_name = role:upper()
185185
end
@@ -307,7 +307,10 @@ function M._format_selection_context(output, part)
307307
local has_selection = context_module.decode_json_context(previous_part.text or '', 'selection') ~= nil
308308
local has_cursor = context_module.decode_json_context(previous_part.text or '', 'cursor-data') ~= nil
309309
local diagnostics = context_module.decode_json_context(previous_part.text or '', 'diagnostics')
310-
local has_diagnostics = diagnostics and diagnostics.content and type(diagnostics.content) == 'table' and #diagnostics.content > 0
310+
local has_diagnostics = diagnostics
311+
and diagnostics.content
312+
and type(diagnostics.content) == 'table'
313+
and #diagnostics.content > 0
311314

312315
if has_selection or has_cursor or has_diagnostics then
313316
start_line = output:get_line_count()
@@ -548,6 +551,7 @@ function M.add_vertical_border(output, start_line, end_line, hl_group, win_col,
548551
virt_text_repeat_linebreak = true,
549552
line_hl_group = text_hl_group or nil,
550553
}
554+
551555
for line = start_line, end_line do
552556
output:add_extmark(line - 1, extmark_opts --[[@as OutputExtmark]])
553557
end

lua/opencode/ui/loading_animation.lua

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,28 @@ local function subscribe_session_status_event(manager)
8585
M._animation.status_event_manager = manager
8686
end
8787

88+
local function is_active_session_busy()
89+
local active_session = state.active_session
90+
local session_id = active_session and active_session.id
91+
if session_id and ((state.user_message_count or {})[session_id] or 0) > 0 then
92+
return true
93+
end
94+
95+
local ok, question_window = pcall(require, 'opencode.ui.question_window')
96+
if ok and question_window.has_question and question_window.belongs_to_active_session then
97+
local current_question = question_window._current_question
98+
if question_window.has_question() and question_window.belongs_to_active_session(current_question) then
99+
return true
100+
end
101+
end
102+
103+
if M._animation.status_data and M._animation.status_data.type ~= 'idle' then
104+
return true
105+
end
106+
107+
return state.jobs.is_running()
108+
end
109+
88110
function M.on_session_status(properties)
89111
if not properties or type(properties) ~= 'table' then
90112
return
@@ -104,6 +126,27 @@ local function on_active_session_change(_, new_session, old_session)
104126
local old_id = old_session and old_session.id
105127
if new_id ~= old_id then
106128
M._animation.status_data = nil
129+
if is_active_session_busy() then
130+
M.start(state.windows)
131+
else
132+
M.stop()
133+
end
134+
end
135+
end
136+
137+
local function on_user_message_count_change()
138+
if not state.windows then
139+
return
140+
end
141+
142+
if is_active_session_busy() then
143+
if not M.is_running() then
144+
M.start(state.windows)
145+
else
146+
M.render(state.windows)
147+
end
148+
else
149+
M.stop()
107150
end
108151
end
109152

@@ -138,7 +181,7 @@ M.render = vim.schedule_wrap(function(windows)
138181
return false
139182
end
140183

141-
if not state.jobs.is_running() then
184+
if not is_active_session_busy() then
142185
M.stop()
143186
return false
144187
end
@@ -168,7 +211,7 @@ function M._start_animation_timer(windows)
168211
on_tick = function()
169212
M._animation.current_frame = M._next_frame()
170213
M.render(state.windows)
171-
if state.jobs.is_running() then
214+
if is_active_session_busy() then
172215
return true
173216
else
174217
M.stop()
@@ -214,22 +257,34 @@ local function on_running_change(_, new_value)
214257
return
215258
end
216259

217-
if not M.is_running() and new_value and new_value > 0 then
218-
M.start(state.windows)
260+
if (new_value and new_value > 0) or is_active_session_busy() then
261+
if not M.is_running() then
262+
M.start(state.windows)
263+
else
264+
M.render(state.windows)
265+
end
219266
else
220267
M.stop()
221268
end
222269
end
223270

224271
function M.setup()
225272
state.store.subscribe('job_count', on_running_change)
273+
state.store.subscribe('user_message_count', on_user_message_count_change)
226274
state.store.subscribe('active_session', on_active_session_change)
227275
state.store.subscribe('event_manager', on_event_manager_change)
228276
subscribe_session_status_event(state.event_manager)
277+
278+
if is_active_session_busy() then
279+
M.start(state.windows)
280+
else
281+
M.stop()
282+
end
229283
end
230284

231285
function M.teardown()
232286
state.store.unsubscribe('job_count', on_running_change)
287+
state.store.unsubscribe('user_message_count', on_user_message_count_change)
233288
state.store.unsubscribe('active_session', on_active_session_change)
234289
state.store.unsubscribe('event_manager', on_event_manager_change)
235290
unsubscribe_session_status_event(M._animation.status_event_manager)

lua/opencode/ui/output_window.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ function M.setup(windows)
181181
)
182182
window_options.set_window_option('wrap', true, windows.output_win, { save_original = true })
183183
window_options.set_window_option('linebreak', true, windows.output_win, { save_original = true })
184+
window_options.set_window_option('cursorline', false, windows.output_win, { save_original = true })
184185
window_options.set_window_option('number', false, windows.output_win, { save_original = true })
185186
window_options.set_window_option('relativenumber', false, windows.output_win, { save_original = true })
186187
window_options.set_buffer_option('modifiable', false, windows.output_buf)

lua/opencode/ui/permission_window.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ function M.format_display(output)
174174
title = icons.get('warning') .. ' Permission Required' .. progress,
175175
title_hl = 'OpencodePermissionTitle',
176176
border_hl = 'OpencodePermissionBorder',
177+
extend_border_to_trailing_blank = true,
177178
content = render_content and nil or content,
178179
render_content = render_content,
179180
options = options,

0 commit comments

Comments
 (0)