Skip to content

Commit 2a42ed7

Browse files
committed
refactor: streaming_renderer, session_formatter
Renamed them: streaming_renderer -> renderer session_formatter -> formatter
1 parent 30f5233 commit 2a42ed7

File tree

13 files changed

+44
-44
lines changed

13 files changed

+44
-44
lines changed

lua/opencode/api.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ function M.undo()
583583
state.active_session.revert = response.revert
584584
vim.schedule(function()
585585
vim.notify('Last message undone successfully', vim.log.levels.INFO)
586-
require('opencode.ui.streaming_renderer').reset_and_render()
586+
require('opencode.ui.renderer').reset_and_render()
587587
end)
588588
end)
589589
:catch(function(err)
@@ -606,7 +606,7 @@ function M.redo()
606606
state.active_session.revert = response.revert
607607
vim.schedule(function()
608608
vim.notify('Last message rerterted successfully', vim.log.levels.INFO)
609-
require('opencode.ui.streaming_renderer').reset_and_render()
609+
require('opencode.ui.renderer').reset_and_render()
610610
end)
611611
end)
612612
:catch(function(err)

lua/opencode/ui/contextual_actions.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function M.setup_contextual_actions()
2626
callback = function()
2727
vim.schedule(function()
2828
local line_num = vim.api.nvim_win_get_cursor(0)[1]
29-
local actions = require('opencode.ui.session_formatter').output:get_actions_for_line(line_num)
29+
local actions = require('opencode.ui.formatter').output:get_actions_for_line(line_num)
3030
last_line_num = line_num
3131

3232
vim.api.nvim_buf_clear_namespace(state.windows.output_buf, ns_id, 0, -1)

lua/opencode/ui/debug_helper.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ function M.open_json_file(data)
2121
end
2222

2323
function M.debug_output()
24-
local session_formatter = require('opencode.ui.session_formatter')
24+
local session_formatter = require('opencode.ui.formatter')
2525
M.open_json_file(session_formatter:get_lines())
2626
end
2727

2828
function M.debug_message()
29-
local session_formatter = require('opencode.ui.session_formatter')
29+
local session_formatter = require('opencode.ui.formatter')
3030
local current_line = vim.api.nvim_win_get_cursor(state.windows.output_win)[1]
3131
local metadata = session_formatter.get_message_at_line(current_line) or {}
3232
M.open_json_file(metadata.message)

lua/opencode/ui/navigation.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
local M = {}
22

33
local state = require('opencode.state')
4-
local session_formatter = require('opencode.ui.session_formatter')
4+
local formatter = require('opencode.ui.formatter')
55

66
local function re_focus()
77
vim.cmd('normal! zt')
@@ -12,11 +12,11 @@ function M.goto_next_message()
1212
local windows = state.windows
1313
local win = windows.output_win
1414
local buf = windows.output_buf
15-
local all_metadata = session_formatter.output:get_all_metadata()
15+
local all_metadata = formatter.output:get_all_metadata()
1616

1717
local current_line = vim.api.nvim_win_get_cursor(win)[1]
1818
local line_count = vim.api.nvim_buf_line_count(buf)
19-
local current = session_formatter.get_message_at_line(current_line)
19+
local current = formatter.get_message_at_line(current_line)
2020
local current_idx = current and current.msg_idx or 0
2121

2222
for i = current_line, line_count do
@@ -33,10 +33,10 @@ function M.goto_prev_message()
3333
require('opencode.ui.ui').focus_output()
3434
local windows = state.windows
3535
local win = windows.output_win
36-
local all_metadata = session_formatter.output:get_all_metadata()
36+
local all_metadata = formatter.output:get_all_metadata()
3737

3838
local current_line = vim.api.nvim_win_get_cursor(win)[1]
39-
local current = session_formatter.get_message_at_line(current_line)
39+
local current = formatter.get_message_at_line(current_line)
4040
local current_idx = current and current.msg_idx or 0
4141

4242
for i = current_line - 1, 1, -1 do

lua/opencode/ui/output_renderer.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
local M = {}
22

33
local state = require('opencode.state')
4-
local formatter = require('opencode.ui.session_formatter')
4+
local formatter = require('opencode.ui.formatter')
55
local loading_animation = require('opencode.ui.loading_animation')
66
local output_window = require('opencode.ui.output_window')
77
local util = require('opencode.util')
@@ -11,6 +11,8 @@ M._subscriptions = {}
1111
M._ns_id = vim.api.nvim_create_namespace('opencode_output')
1212
M._debounce_ms = 50
1313

14+
-- FIXME: this file should eventually be removed
15+
1416
function M.render_markdown()
1517
if vim.fn.exists(':RenderMarkdown') > 0 then
1618
vim.cmd(':RenderMarkdown')
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ function M.reset()
1212
M._part_cache = {}
1313
M._prev_line_count = 0
1414

15-
-- FIXME: this prolly isn't the right place for state.messages to be
16-
-- cleared. It would probably be better to have streaming_renderer
17-
-- subscribe to state changes and if state.messages is cleared, it
18-
-- should clear it's state too
1915
state.messages = {}
2016
state.last_user_message = nil
2117
end
@@ -203,7 +199,7 @@ end
203199
---@param msg_idx integer Message index
204200
---@return {line_start: integer, line_end: integer}? Range where header was written
205201
function M._write_message_header(message, msg_idx)
206-
local formatter = require('opencode.ui.session_formatter')
202+
local formatter = require('opencode.ui.formatter')
207203
local header_data = formatter.format_message_header_isolated(message, msg_idx)
208204
local line_range = M._write_formatted_data(header_data)
209205
return line_range
@@ -400,7 +396,7 @@ function M.on_part_updated(event)
400396
}
401397
end
402398

403-
local formatter = require('opencode.ui.session_formatter')
399+
local formatter = require('opencode.ui.formatter')
404400
local ok, formatted = pcall(formatter.format_part_isolated, part, {
405401
msg_idx = msg_idx,
406402
part_idx = part_idx,
@@ -503,6 +499,8 @@ end
503499
function M.on_session_compacted(event)
504500
vim.notify('on_session_compacted')
505501
-- TODO: render a note that the session was compacted
502+
-- FIXME: did we need unset state.last_sent_context because the
503+
-- session was compacted?
506504
end
507505

508506
---Reset and re-render the whole session via output_renderer
@@ -523,7 +521,7 @@ function M.on_session_error(event)
523521
local error_data = event.properties.error
524522
local error_message = error_data.data and error_data.data.message or vim.inspect(error_data)
525523

526-
local formatter = require('opencode.ui.session_formatter')
524+
local formatter = require('opencode.ui.formatter')
527525
local formatted = formatter.format_error_callout(error_message)
528526

529527
M._write_formatted_data(formatted)
@@ -628,7 +626,7 @@ function M._rerender_part(part_id)
628626
return
629627
end
630628

631-
local formatter = require('opencode.ui.session_formatter')
629+
local formatter = require('opencode.ui.formatter')
632630
local message_with_parts = vim.tbl_extend('force', msg_wrapper.info, { parts = msg_wrapper.parts })
633631
local ok, formatted = pcall(formatter.format_part_isolated, part, {
634632
msg_idx = msg_idx,

lua/opencode/ui/ui.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ local M = {}
22
local config = require('opencode.config')
33
local state = require('opencode.state')
44
local output_renderer = require('opencode.ui.output_renderer')
5-
local streaming_renderer = require('opencode.ui.streaming_renderer')
5+
local renderer = require('opencode.ui.renderer')
66
local output_window = require('opencode.ui.output_window')
77
local input_window = require('opencode.ui.input_window')
88
local footer = require('opencode.ui.footer')
@@ -37,7 +37,7 @@ function M.close_windows(windows)
3737

3838
topbar.close()
3939
output_renderer.teardown()
40-
streaming_renderer.teardown()
40+
renderer.teardown()
4141

4242
pcall(vim.api.nvim_del_augroup_by_name, 'OpencodeResize')
4343
pcall(vim.api.nvim_del_augroup_by_name, 'OpencodeWindows')
@@ -119,7 +119,7 @@ function M.create_windows()
119119
topbar.setup()
120120

121121
output_renderer.setup_subscriptions(windows)
122-
streaming_renderer.setup_subscriptions(windows)
122+
renderer.setup_subscriptions(windows)
123123

124124
autocmds.setup_autocmds(windows)
125125
autocmds.setup_resize_handler(windows)
@@ -189,7 +189,7 @@ end
189189

190190
function M.clear_output()
191191
output_renderer.stop()
192-
streaming_renderer.reset()
192+
renderer.reset()
193193
output_window.clear()
194194
footer.clear()
195195
topbar.render()

tests/helpers.lua

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ function M.load_test_data(filename)
113113
end
114114

115115
function M.get_session_from_events(events)
116-
-- streaming_renderer needs a valid session id
116+
-- renderer needs a valid session id
117117
for _, event in ipairs(events) do
118118
-- find the session id in a message or part event
119119
local properties = event.properties
@@ -128,21 +128,21 @@ function M.get_session_from_events(events)
128128
end
129129

130130
function M.replay_event(event)
131-
local streaming_renderer = require('opencode.ui.streaming_renderer')
131+
local renderer = require('opencode.ui.renderer')
132132
if event.type == 'message.updated' then
133-
streaming_renderer.on_message_updated(event)
133+
renderer.on_message_updated(event)
134134
elseif event.type == 'message.part.updated' then
135-
streaming_renderer.on_part_updated(event)
135+
renderer.on_part_updated(event)
136136
elseif event.type == 'message.removed' then
137-
streaming_renderer.on_message_removed(event)
137+
renderer.on_message_removed(event)
138138
elseif event.type == 'message.part.removed' then
139-
streaming_renderer.on_part_removed(event)
139+
renderer.on_part_removed(event)
140140
elseif event.type == 'session.compacted' then
141-
streaming_renderer.on_session_compacted()
141+
renderer.on_session_compacted()
142142
elseif event.type == 'permission.updated' then
143-
streaming_renderer.on_permission_updated(event)
143+
renderer.on_permission_updated(event)
144144
elseif event.type == 'permission.replied' then
145-
streaming_renderer.on_permission_replied(event)
145+
renderer.on_permission_replied(event)
146146
end
147147
end
148148

tests/manual/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Replay captured event data to visually test the streaming renderer.
1515
Or manually:
1616

1717
```bash
18-
nvim -u tests/manual/init_replay.lua -c "lua require('tests.manual.streaming_renderer_replay').start()"
18+
nvim -u tests/manual/init_replay.lua -c "lua require('tests.manual.renderer_replay').start()"
1919
```
2020

2121
### Available Commands

0 commit comments

Comments
 (0)