|
94 | 94 | function M._render_full_session_data(session_data) |
95 | 95 | M.reset() |
96 | 96 |
|
97 | | - state.messages = session_data |
98 | | - M._message_map:hydrate(state.messages) |
| 97 | + for i, msg in ipairs(session_data) do |
| 98 | + -- output:add_lines(M.separator) |
| 99 | + -- state.current_message = msg |
| 100 | + |
| 101 | + if state.active_session.revert and state.active_session.revert.messageID == msg.info.id then |
| 102 | + ---@type {messages: number, tool_calls: number, files: table<string, {additions: number, deletions: number}>} |
| 103 | + local revert_stats = M._calculate_revert_stats(state.messages, i, state.active_session.revert) |
| 104 | + local output = require('opencode.ui.output'):new() |
| 105 | + formatter._format_revert_message(output, revert_stats) |
| 106 | + M.write_output(output) |
| 107 | + |
| 108 | + -- FIXME: how does reverting work? why is it breaking out of the message reading loop? |
| 109 | + break |
| 110 | + end |
99 | 111 |
|
100 | | - M._update_stats_from_messages(state.messages) |
| 112 | + -- only pass in the info so, the parts will be processed as part of the loop |
| 113 | + -- TODO: remove part processing code in formatter |
| 114 | + M.on_message_updated({ info = msg.info }) |
101 | 115 |
|
102 | | - local output_data = formatter._format_messages(state.active_session) |
| 116 | + for j, part in ipairs(msg.parts or {}) do |
| 117 | + M.on_part_updated({ part = part }) |
| 118 | + end |
103 | 119 |
|
104 | | - -- FIXME: I think this should be setting state.last_user_message |
105 | | - -- Maybe it'd be better to move iterating over messages to renderer |
| 120 | + -- FIXME: not sure how this error rendering code works when streaming |
| 121 | + -- if msg.info.error and msg.info.error ~= '' then |
| 122 | + -- vim.notify('calling _format_error') |
| 123 | + -- M._format_error(output, msg.info) |
| 124 | + -- end |
| 125 | + end |
106 | 126 |
|
107 | | - M.write_output(output_data) |
108 | 127 | M._scroll_to_bottom() |
109 | 128 | end |
110 | 129 |
|
@@ -373,20 +392,23 @@ function M.on_message_updated(properties) |
373 | 392 |
|
374 | 393 | if found_idx then |
375 | 394 | state.messages[found_idx].info = message.info |
376 | | - M._update_stats_from_message(message) |
377 | 395 | else |
378 | 396 | table.insert(state.messages, message) |
379 | 397 | found_idx = #state.messages |
380 | 398 | M._message_map:add_message(message.info.id, found_idx) |
381 | 399 |
|
382 | | - M._update_stats_from_message(message) |
| 400 | + local header_data = formatter.format_message_header_single(message, found_idx) |
| 401 | + M._write_formatted_data(header_data) |
| 402 | + |
| 403 | + state.current_message = message |
383 | 404 |
|
384 | | - M._write_message_header(message, found_idx) |
385 | 405 | if message.info.role == 'user' then |
386 | 406 | state.last_user_message = message |
387 | 407 | end |
388 | 408 | end |
389 | 409 |
|
| 410 | + M._update_stats_from_message(message) |
| 411 | + |
390 | 412 | M._scroll_to_bottom() |
391 | 413 | end |
392 | 414 |
|
|
0 commit comments