Skip to content

refactor(state): improve use of state helpers#330

Merged
sudo-tee merged 8 commits intomainfrom
feat/state-management-refine
Mar 18, 2026
Merged

refactor(state): improve use of state helpers#330
sudo-tee merged 8 commits intomainfrom
feat/state-management-refine

Conversation

@sudo-tee
Copy link
Owner

No description provided.

Copy link
Contributor

Copilot AI left a comment

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 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() and state.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.

sudo-tee and others added 5 commits March 18, 2026 14:22
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>
@sudo-tee sudo-tee merged commit 918a732 into main Mar 18, 2026
10 checks passed
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