Skip to content

refactor(renderer): refactor renderer in multiple files - #338

Merged
sudo-tee merged 3 commits into
mainfrom
perf/rendering-improvements
Mar 22, 2026
Merged

refactor(renderer): refactor renderer in multiple files#338
sudo-tee merged 3 commits into
mainfrom
perf/rendering-improvements

Conversation

@sudo-tee

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the UI renderer into smaller modules (events/buffer/context) and updates RenderState’s indexing strategy, with corresponding test updates to use the new structure.

Changes:

  • Split renderer responsibilities into renderer.events, renderer.buffer, and a shared singleton renderer.ctx.
  • Replace RenderState’s per-line index with sorted range arrays and add a cached max-line optimization.
  • Add batch update support in output_window to reduce repeated modifiable toggling during multi-step buffer updates.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/unit/render_state_spec.lua Updates assertions for new range-based validity flags and adds coverage for early-return paths.
tests/unit/permission_integration_spec.lua Switches from renderer internals to renderer.events + renderer.ctx for integration-style behavior.
tests/unit/hooks_spec.lua Routes hook tests through renderer.events handlers.
tests/unit/cursor_tracking_spec.lua Updates scrolling tests to use ctx.prev_line_count and message update events.
tests/manual/renderer_replay.lua Reads actions from renderer.ctx.render_state instead of renderer internals.
tests/helpers.lua Captures actions via renderer.ctx.render_state.
lua/opencode/ui/renderer/events.lua New module containing renderer event handlers (message/part/session/permission/question/etc.).
lua/opencode/ui/renderer/ctx.lua New shared mutable renderer context (singleton via require cache).
lua/opencode/ui/renderer/buffer.lua New module encapsulating buffer writes, diff-optimized part replacement, and rerender helpers.
lua/opencode/ui/renderer.lua Becomes orchestrator: subscriptions, reset/teardown, full-session render, scrolling, and public accessors.
lua/opencode/ui/render_state.lua Replaces line index maps with sorted ranges + binary search; adds snapshot-id index + max-line caching.
lua/opencode/ui/question_window.lua Calls question rendering/clearing via renderer.events.
lua/opencode/ui/permission_window.lua Calls permissions rendering via renderer.events.
lua/opencode/ui/output_window.lua Adds begin_update/end_update batching and updates buffer validity checks.
lua/opencode/ui/debug_helper.lua Uses renderer.ctx.render_state for message lookup.
lua/opencode/state.lua Removes legacy wrapper module file (module now resolves via opencode/state/init.lua).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lua/opencode/ui/output_window.lua
Comment thread lua/opencode/ui/renderer/buffer.lua
Comment thread lua/opencode/ui/renderer/buffer.lua Outdated
Comment thread lua/opencode/ui/renderer/buffer.lua Outdated
Comment thread lua/opencode/ui/render_state.lua
@sudo-tee
sudo-tee merged commit 760b404 into main Mar 22, 2026
10 checks passed
disrupted pushed a commit to disrupted/opencode-native.nvim that referenced this pull request Jul 23, 2026
* refactor(renderer): refactor renderer in multiple files

* perf(ui): improve rendering performance and robustness

* fix: scrolling behavior not always at the end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants