Skip to content

feat: ReservedProperty protocol for plugin→frontend coordination#1143

Open
wyjrichhh wants to merge 3 commits into
rime:masterfrom
wyjrichhh:feat/reserved-property-protocol
Open

feat: ReservedProperty protocol for plugin→frontend coordination#1143
wyjrichhh wants to merge 3 commits into
rime:masterfrom
wyjrichhh:feat/reserved-property-protocol

Conversation

@wyjrichhh

Copy link
Copy Markdown

Summary

Introduces a ReservedProperty protocol so a librime plugin can coordinate
with the Squirrel frontend over the existing property message channel,
using reserved keys with a leading underscore (e.g. _refresh_ui). Unknown
reserved keys are silently ignored, so the wire format is backward-compatible.

The motivating use case (per #1124) is letting a plugin drive
semantic comment styling (accent / warning colors) on specific candidate
indices, and trigger a UI refresh without a keystroke.

Changes

  • sources/ReservedProperty.swift (new) — defines ReservedPropertyKey,
    ReservedPropertyValue (URL-query-style parsing of the value payload), and
    index-set decoding. This is the documented wire format and reserved-key table.
  • SquirrelApplicationDelegate.swift — routes property messages whose value
    starts with _ to the active input controller as reserved properties.
  • SquirrelInputController.swift — adds handleReservedProperty(...) and a
    state-type reserved-property cache. rimeUpdate gains a
    clearReservedComments flag (default true) so reserved-comment indices set
    by the previous Compose() are dropped on ordinary state-changing updates and
    preserved only for the _refresh_ui-driven render.
  • SquirrelPanel.swift / SquirrelTheme.swift — apply per-index semantic
    comment colors (accentCommentTextColor, warningCommentTextColor).

Testing

  • Local Xcode build (note: my environment currently fails to build due to
    missing cangjie5*.dict.yaml resources and a CoreSimulator version mismatch,
    both unrelated to this change — CI build is the reliable signal here).

Introduce ReservedProperty to track and preserve reserved comments
across Rime updates, and avoid clearing them on caret/selection-only
updates.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment thread sources/ReservedProperty.swift Outdated
// │ the active InputController via handleReservedProperty│
// └──────────────────────────────────────────────────────────────┘
//
// The leading-underscore namespace marks the key as part of this

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Keys with leading-underscore are "transient options/properties":
https://github.com/rime/librime/blob/d71168e9e8c8392ed219dca011dbc76b80727d6c/src/rime/context.cc#L313

Their lifetime are bound to the active input schema in the context.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks — corrected. The header now states that leading-underscore keys are librime transient properties whose lifetime is bound to the active input schema in the context (and cleared on schema change), and frames this protocol as reserving a subset of that namespace rather than inventing it. Fixed in b983b60.

Comment thread sources/ReservedProperty.swift Outdated
WYJRichhhhh and others added 2 commits June 17, 2026 12:09
- Document leading-underscore keys as librime transient properties whose
  lifetime is bound to the active input schema (per @lotem, context.cc).
- Rename the bare-value shorthand field from `indices` to the neutral
  `value` so non-index keys can reuse the same scalar shorthand.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Rename short local bindings flagged by swiftlint and reposition a
cyclomatic_complexity disable comment so it sits directly above the
function declaration:

- ReservedProperty.swift: n -> index
- SquirrelApplicationDelegate.swift: eq -> eqIndex
- SquirrelInputController.swift: move disable directive to the decl

No behavioural change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@wyjrichhh wyjrichhh requested a review from lotem June 17, 2026 05:43

@lotem lotem left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks.
LGTM

@lotem lotem requested review from LEOYoon-Tsaw and lotem and removed request for lotem June 17, 2026 06:38
@wyjrichhh wyjrichhh requested a review from lotem June 17, 2026 07:31

@lotem lotem left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

看過了呢。LGTM

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.

3 participants