Skip to content

feat: ReservedProperty protocol for plugin→frontend coordination#1143

Merged
LEOYoon-Tsaw merged 6 commits into
rime:masterfrom
wyjrichhh:feat/reserved-property-protocol
Jun 22, 2026
Merged

feat: ReservedProperty protocol for plugin→frontend coordination#1143
LEOYoon-Tsaw merged 6 commits into
rime:masterfrom
wyjrichhh:feat/reserved-property-protocol

Conversation

@wyjrichhh

Copy link
Copy Markdown
Contributor

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
Contributor 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

@LEOYoon-Tsaw

Copy link
Copy Markdown
Member

I made some changes according to my review comments. @wyjrichhh @lotem Any objections?

@lotem

lotem commented Jun 22, 2026

Copy link
Copy Markdown
Member

@wyjrichhh

Copy link
Copy Markdown
Contributor Author

No objections, thanks!

@LEOYoon-Tsaw LEOYoon-Tsaw merged commit e972397 into rime:master Jun 22, 2026
1 check passed
wyjrichhh added a commit to wyjrichhh/librime-ai-predict that referenced this pull request Jun 22, 2026
前端保留 property key 协议 (#1124) 已通过 rime/squirrel#1143 合并进
上游鼠须管 master,不再需要 fork。同步修正文档与协议细节:

- README: fork 叙事改为「上游 master (含 #1143,未发版)」;协议
  插件无关;补 payload 格式表 (_refresh_ui query string、
  _comment_highlight 裸索引列表、_comment_warning 未发出);补
  ContextBuilder 跳过 raw 类型的说明与刷新语义。
- frontend_protocol.h: _comment_highlight 编码注释改为前端归一化
  到中性 value 字段;说明保留但未声明的 _comment_warning。
- context_builder.cc: 标点过滤改 Unicode range 匹配(覆盖整块 CJK/
  fullwidth/general 标点,修复 )等泄漏);新增 IsPinyinPrompt 拒绝
  非拼音段(裸标点/ASCII 符号/大写缩写)。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@LEOYoon-Tsaw

Copy link
Copy Markdown
Member

如果仍然想改LOG_DIR的話再提一個PR吧,這個改動比較大,很多教程都要改,急不得

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.

4 participants