Skip to content

Commit aebd461

Browse files
committed
adjust
1 parent 2168145 commit aebd461

3 files changed

Lines changed: 48 additions & 105 deletions

File tree

lua/opencode/ui/renderer.lua

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ local RenderState = require('opencode.ui.render_state')
99
local M = {
1010
_prev_line_count = 0,
1111
_render_state = RenderState.new(),
12-
_full_render_in_flight = nil,
13-
_full_render_pending_opts = nil,
1412
_last_part_formatted = {
1513
part_id = nil,
1614
formatted_data = nil --[[@as Output|nil]],
@@ -41,7 +39,6 @@ end, config.ui.output.rendering.markdown_debounce_ms or 250)
4139
function M.reset()
4240
M._prev_line_count = 0
4341
M._render_state:reset()
44-
M._full_render_pending_opts = nil
4542
M._last_part_formatted = { part_id = nil, formatted_data = nil }
4643

4744
output_window.clear()
@@ -125,50 +122,17 @@ local function fetch_session()
125122
return require('opencode.session').get_messages(session)
126123
end
127124

128-
---@param opts? {force_scroll?: boolean}
125+
---Request all of the session data from the opencode server and render it
129126
---@return Promise<OpencodeMessage[]>
130-
function M.render_full_session(opts)
131-
opts = opts or {}
132-
127+
function M.render_full_session()
133128
if not output_window.mounted() or not state.api_client then
134129
return Promise.new():resolve(nil)
135130
end
136131

137-
if M._full_render_in_flight then
138-
M._full_render_pending_opts = M._full_render_pending_opts or {}
139-
M._full_render_pending_opts.force_scroll = M._full_render_pending_opts.force_scroll
140-
or (opts.force_scroll == true)
141-
return M._full_render_in_flight
142-
end
143-
144-
local render_promise = fetch_session():and_then(function(session_data)
145-
return M._render_full_session_data(session_data, opts)
146-
end)
147-
148-
M._full_render_in_flight = render_promise
149-
150-
render_promise:finally(function()
151-
M._full_render_in_flight = nil
152-
153-
local pending_opts = M._full_render_pending_opts
154-
if pending_opts then
155-
M._full_render_pending_opts = nil
156-
vim.schedule(function()
157-
if output_window.mounted() and state.api_client then
158-
M.render_full_session(pending_opts)
159-
end
160-
end)
161-
end
162-
end)
163-
164-
return render_promise
132+
return fetch_session():and_then(M._render_full_session_data)
165133
end
166134

167-
---@param session_data table
168-
---@param opts? {force_scroll?: boolean}
169-
function M._render_full_session_data(session_data, opts)
170-
opts = opts or {}
171-
session_data = session_data or {}
135+
function M._render_full_session_data(session_data, prev_revert, revert)
172136
M.reset()
173137

174138
if not state.active_session or not state.messages then
@@ -200,7 +164,7 @@ function M._render_full_session_data(session_data, opts)
200164
if set_mode_from_messages then
201165
M._set_model_and_mode_from_messages()
202166
end
203-
M.scroll_to_bottom(opts.force_scroll == true)
167+
M.scroll_to_bottom(true)
204168

205169
if config.hooks and config.hooks.on_session_loaded then
206170
pcall(config.hooks.on_session_loaded, state.active_session)

tests/unit/cursor_tracking_spec.lua

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ describe('cursor persistence (state)', function()
3131
})
3232

3333
win = vim.api.nvim_open_win(buf, true, {
34-
relative = 'editor', width = 80, height = 10, row = 0, col = 0,
34+
relative = 'editor',
35+
width = 80,
36+
height = 10,
37+
row = 0,
38+
col = 0,
3539
})
3640

3741
state.windows = { output_win = win, output_buf = buf }
@@ -162,7 +166,11 @@ describe('cursor persistence (state)', function()
162166
local buf = vim.api.nvim_create_buf(false, true)
163167
vim.api.nvim_buf_set_lines(buf, 0, -1, false, { 'line1', 'line2', 'line3' })
164168
local win = vim.api.nvim_open_win(buf, true, {
165-
relative = 'editor', width = 40, height = 10, row = 0, col = 0,
169+
relative = 'editor',
170+
width = 40,
171+
height = 10,
172+
row = 0,
173+
col = 0,
166174
})
167175
vim.api.nvim_win_set_cursor(win, { 2, 3 })
168176

@@ -190,7 +198,11 @@ describe('output_window.is_at_bottom', function()
190198
vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
191199

192200
win = vim.api.nvim_open_win(buf, true, {
193-
relative = 'editor', width = 80, height = 10, row = 0, col = 0,
201+
relative = 'editor',
202+
width = 80,
203+
height = 10,
204+
row = 0,
205+
col = 0,
194206
})
195207

196208
state.windows = { output_win = win, output_buf = buf }
@@ -241,7 +253,11 @@ describe('output_window.is_at_bottom', function()
241253
it('returns true for empty buffer', function()
242254
local empty_buf = vim.api.nvim_create_buf(false, true)
243255
local empty_win = vim.api.nvim_open_win(empty_buf, true, {
244-
relative = 'editor', width = 40, height = 5, row = 0, col = 0,
256+
relative = 'editor',
257+
width = 40,
258+
height = 5,
259+
row = 0,
260+
col = 0,
245261
})
246262
state.windows = { output_win = empty_win, output_buf = empty_buf }
247263

@@ -255,10 +271,13 @@ describe('output_window.is_at_bottom', function()
255271
vim.api.nvim_win_set_cursor(win, { 50, 0 })
256272
assert.is_true(output_window.is_at_bottom(win))
257273

274+
-- Scroll viewport up via winrestview, cursor stays at line 50
258275
pcall(vim.api.nvim_win_call, win, function()
259276
vim.fn.winrestview({ topline = 1 })
260277
end)
261278

279+
-- Cursor is still at 50, so is_at_bottom should still be true
280+
-- This is the key behavioral difference from viewport-based check
262281
assert.is_true(output_window.is_at_bottom(win))
263282
end)
264283
end)
@@ -278,7 +297,11 @@ describe('renderer.scroll_to_bottom', function()
278297
vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
279298

280299
win = vim.api.nvim_open_win(buf, true, {
281-
relative = 'editor', width = 80, height = 10, row = 0, col = 0,
300+
relative = 'editor',
301+
width = 80,
302+
height = 10,
303+
row = 0,
304+
col = 0,
282305
})
283306

284307
state.windows = { output_win = win, output_buf = buf }
@@ -327,10 +350,18 @@ describe('ui.focus_input', function()
327350
vim.api.nvim_buf_set_lines(output_buf, 0, -1, false, { 'output' })
328351

329352
output_win = vim.api.nvim_open_win(output_buf, true, {
330-
relative = 'editor', width = 40, height = 5, row = 0, col = 0,
353+
relative = 'editor',
354+
width = 40,
355+
height = 5,
356+
row = 0,
357+
col = 0,
331358
})
332359
input_win = vim.api.nvim_open_win(input_buf, true, {
333-
relative = 'editor', width = 40, height = 5, row = 6, col = 0,
360+
relative = 'editor',
361+
width = 40,
362+
height = 5,
363+
row = 6,
364+
col = 0,
334365
})
335366

336367
state.windows = {
@@ -373,7 +404,11 @@ describe('renderer._add_message_to_buffer scrolling', function()
373404
vim.api.nvim_buf_set_lines(buf, 0, -1, false, { 'existing line' })
374405

375406
win = vim.api.nvim_open_win(buf, true, {
376-
relative = 'editor', width = 80, height = 10, row = 0, col = 0,
407+
relative = 'editor',
408+
width = 80,
409+
height = 10,
410+
row = 0,
411+
col = 0,
377412
})
378413

379414
state.windows = { output_win = win, output_buf = buf }

tests/unit/renderer_spec.lua

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)