Skip to content

Commit 4a4b6d0

Browse files
committed
fix(renderer): shift part lines
Lots going on here. First, I managed to get a session that delivered multiple permission requests at the same time. I still not sure why that happened. However, that code exposed a bug in the part line shifting code. The code was only shift parts that started after the new line end when it needed to look for parts up to the old line end for the part being replaced.
1 parent 709703d commit 4a4b6d0

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

lua/opencode/ui/renderer.lua

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ function M.reset()
2424

2525
state.messages = {}
2626
state.last_user_message = nil
27+
state.current_permission = nil
2728
end
2829

2930
---Set up all subscriptions, for both local and server events
@@ -328,6 +329,8 @@ function M._replace_part_in_buffer(part_id, formatted_data)
328329

329330
output_window.set_lines(new_lines, cached.line_start, cached.line_end + 1)
330331

332+
-- we need the old line_end to know where to start looking for parts to shift
333+
local old_line_end = cached.line_end
331334
cached.line_end = cached.line_start + new_line_count - 1
332335

333336
output_window.set_extmarks(formatted_data.extmarks, cached.line_start)
@@ -344,10 +347,7 @@ function M._replace_part_in_buffer(part_id, formatted_data)
344347
end
345348
end
346349

347-
local line_delta = new_line_count - old_line_count
348-
if line_delta ~= 0 then
349-
M._shift_parts_and_actions(cached.line_end + 1, line_delta)
350-
end
350+
M._shift_parts_and_actions(old_line_end + 1, new_line_count - old_line_count)
351351

352352
return true
353353
end
@@ -583,6 +583,19 @@ function M.on_permission_updated(properties)
583583
return
584584
end
585585

586+
local prev_permission = state.current_permission
587+
state.current_permission = nil
588+
589+
if prev_permission and prev_permission.id ~= permission.id then
590+
-- we got a permission request while we had an existing one?
591+
vim.notify('Two pending permissions? existing: ' .. prev_permission.id .. ' new: ' .. permission.id)
592+
-- rerender previous part to remove old permission
593+
local prev_perm_part_id = M._find_part_by_call_id(prev_permission.callID)
594+
if prev_perm_part_id then
595+
M._rerender_part(prev_perm_part_id)
596+
end
597+
end
598+
586599
state.current_permission = permission
587600

588601
local part_id = M._find_part_by_call_id(permission.callID)

0 commit comments

Comments
 (0)