refactor(state): improve use of state helpers#330
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors state mutations across the codebase to rely more consistently on state “domain” helpers and introduces batching/in-place mutation helpers in the state store to reduce direct state manipulation and consolidate multi-key updates.
Changes:
- Add
state.store.batch()andstate.store.mutate()and refactor existing mutations to use them (plus new unit tests). - Introduce higher-level state helpers (e.g.
ui.set_code_context,ui.mark_windows_hidden,renderer.reset,renderer.set_stats) and update call sites. - Harden the minimal test init by stubbing Treesitter via
pcall(require, 'vim.treesitter').
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/state_spec.lua | Adds coverage for batch() notification deferral and mutate() emitting behavior. |
| tests/minimal/init.lua | Changes Treesitter stubbing approach for tests. |
| lua/opencode/ui/ui.lua | Replaces direct window-state mutation with state.ui.* helpers. |
| lua/opencode/ui/renderer.lua | Consolidates renderer state reset and uses new helpers for permission updates and stats updates. |
| lua/opencode/ui/autocmds.lua | Uses state.ui.set_code_context() instead of two separate setters. |
| lua/opencode/state/ui.lua | Adds set_code_context() and mark_windows_hidden(); batches some multi-key resets. |
| lua/opencode/state/store.lua | Introduces batching + in-place mutation helpers; refactors set/append/remove accordingly. |
| lua/opencode/state/session.lua | Batches session activation/clear; adds message count increment and silent update helper. |
| lua/opencode/state/renderer.lua | Adds pending-permissions mutator helper, combined stats setter, and renderer reset. |
| lua/opencode/state/model.lua | Adds batched clear() and refactors mode->model override update. |
| lua/opencode/state/jobs.lua | Adds set_server_port() helper. |
| lua/opencode/state/init.lua | Minor type/comment tweak. |
| lua/opencode/state/context.lua | Adds update_current_context_config() helper. |
| lua/opencode/state.lua | Updates module type annotation. |
| lua/opencode/server_job.lua | Adjusts server port update logic during local spawn readiness. |
| lua/opencode/image_handler.lua | Removes redundant context_updated_at update after delegating to context module. |
| lua/opencode/core.lua | Uses new model clear helper and consolidated UI code-context setter. |
| lua/opencode/context.lua | Uses in-place config mutation helper; removes redundant context_updated_at updates. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.