refactor: cleanup and split formatters in multiple modules#310
Merged
refactor: cleanup and split formatters in multiple modules#310
Conversation
Extract each tool formatter into dedicated files and centralize shared helpers to keep formatter.lua smaller and easier to maintain.
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the UI formatter to move tool-specific formatting and shared formatting helpers into dedicated modules, updating tests and golden replay fixtures accordingly.
Changes:
- Introduces
opencode.ui.formatter.utils(shared helpers like action lines, code fences, diffs, revert stats). - Extracts tool renderers into
opencode.ui.formatter.tools.*and updatesformatter.luato delegate tool formatting via a registry. - Updates unit tests and renderer replay
.expected.jsonfixtures to match the new formatting output.
Reviewed changes
Copilot reviewed 22 out of 23 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/formatter_spec.lua | Adds coverage for task child-session tool summary fallback; updates diff formatting test to use formatter utils. |
| tests/data/shifting-and-multiple-perms.expected.json | Updates golden output fixture for renderer replay after formatter refactor. |
| tests/data/redo-once.expected.json | Updates golden output fixture for renderer replay after formatter refactor. |
| tests/data/redo-all.expected.json | Updates golden output fixture for renderer replay after formatter refactor. |
| tests/data/markdown-codefence.expected.json | Updates golden output fixture for renderer replay after formatter refactor. |
| tests/data/diff.expected.json | Updates golden output fixture for renderer replay after formatter refactor. |
| tests/data/apply-patch.expected.json | Updates golden output fixture for renderer replay after formatter refactor. |
| lua/opencode/ui/permission_window.lua | Switches diff rendering to opencode.ui.formatter.utils.format_diff. |
| lua/opencode/ui/formatter/utils.lua | New shared formatting utilities (actions, code fences, diffs, revert stats). |
| lua/opencode/ui/formatter/tools/webfetch.lua | New webfetch tool formatter module. |
| lua/opencode/ui/formatter/tools/tool.lua | New generic/fallback tool formatter module. |
| lua/opencode/ui/formatter/tools/todowrite.lua | New todowrite tool formatter module. |
| lua/opencode/ui/formatter/tools/task.lua | New task tool formatter module (includes child-session activity rendering). |
| lua/opencode/ui/formatter/tools/question.lua | New question tool formatter module. |
| lua/opencode/ui/formatter/tools/list.lua | New list tool formatter module. |
| lua/opencode/ui/formatter/tools/init.lua | New tool formatter registry. |
| lua/opencode/ui/formatter/tools/grep.lua | New grep tool formatter module. |
| lua/opencode/ui/formatter/tools/glob.lua | New glob tool formatter module. |
| lua/opencode/ui/formatter/tools/file.lua | New file tool formatter module (read/edit/write). |
| lua/opencode/ui/formatter/tools/bash.lua | New bash tool formatter module. |
| lua/opencode/ui/formatter/tools/apply_patch.lua | New apply_patch tool formatter module. |
| lua/opencode/ui/formatter.lua | Delegates tool formatting to the registry and moves shared helpers into formatter.utils. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 22 out of 23 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
7dc718b to
f0dadf1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.