Skip to content

refactor(bridge): encapsulate DocumentState fields behind constructor and accessors - #317

Merged
bug-ops merged 1 commit into
mainfrom
feat/issue-304/documentstate-has-all-public
Aug 5, 2026
Merged

refactor(bridge): encapsulate DocumentState fields behind constructor and accessors#317
bug-ops merged 1 commit into
mainfrom
feat/issue-304/documentstate-has-all-public

Conversation

@bug-ops

@bug-ops bug-ops commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • DocumentState (crates/mcpls-core/src/bridge/state.rs) previously exposed all six fields as pub with no constructor, letting any caller inside bridge::state violate its documented invariants (monotonic version, disk provenance, per-server synced tracking) by writing fields directly.
  • Fields are now private. A constructor and internal mutators (apply_local_edit, commit_reload, set_disk, mark_synced, forget_server) enforce those invariants; read access goes through #[must_use] getters (uri(), language_id(), version(), content(), synced_version()).
  • No public disk() getter — would leak the crate-internal DiskSync type.
  • Pure encapsulation refactor: no behavior change. DocumentTracker's only constructor takes ResourceLimits, which is not re-exported outside bridge::state, so DocumentState/DocumentTracker were already unreachable from outside the crate before this change — the CHANGELOG entry reflects that this is an internal improvement, not an externally-breaking API change.

Test plan

  • cargo +nightly fmt --all -- --check
  • cargo clippy --all-targets --all-features --workspace -- -D warnings
  • cargo nextest run --workspace --all-features --lib --bins (642/642 passed)
  • RUSTFLAGS="-D warnings" RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc --no-deps --workspace
  • Existing test assertions migrated to exercise the new getters directly, so the accessor contract is validated rather than only the private fields

Closes #304

… and accessors

DocumentState previously exposed all six fields as pub with no
constructor, letting any caller inside bridge::state violate the
documented invariants (monotonic version, disk provenance, per-server
synced tracking) by writing fields directly. Fields are now private;
a constructor and internal mutators (apply_local_edit, commit_reload,
set_disk, mark_synced, forget_server) enforce those invariants, and
read access goes through must_use getters.

Closes #304
@github-actions github-actions Bot added documentation Improvements or additions to documentation rust Rust code changes mcpls-core mcpls-core crate changes labels Aug 5, 2026
@bug-ops
bug-ops enabled auto-merge (squash) August 5, 2026 01:32
@bug-ops
bug-ops merged commit 8d78711 into main Aug 5, 2026
28 checks passed
@bug-ops
bug-ops deleted the feat/issue-304/documentstate-has-all-public branch August 5, 2026 01:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation mcpls-core mcpls-core crate changes rust Rust code changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DocumentState has all-public fields and no constructor despite documented cross-field invariants

1 participant