Skip to content

Make CollapsibleObject can use Comment 使 CollapsibleObject 可以使用 Comment - #150

Merged
ZhuRuoLing merged 1 commit into
Anvil-Dev:dev/1.21.4from
QiuShui1012:port/1.21.4
Oct 10, 2026
Merged

ZhuRuoLing merged 1 commit into
Anvil-Dev:dev/1.21.4from
QiuShui1012:port/1.21.4

Conversation

@QiuShui1012

Copy link
Copy Markdown
Contributor

No description provided.

@Gugle2308

Copy link
Copy Markdown

核对完毕(base sha 6138b0d2 与 API 一致,head 文件与 patch 逐行吻合,+6/-3 与 changed_files: 1 对齐,diff 无截断)。以下是审查意见:


代码审查摘要 — PR #150

操作: opened(state=open,mergeable=true)
范围: 1 个文件(module.config/.../config/ConfigData.java,+6/-3,27 行 diff)
结论导向: 方向正确的小修复,可合并;建议顺手把「隐式依赖」显式化。

变更内容

providerAdd 中把 Comment 的读取提前,并为 @CollapsibleObject 字段的 tooltip 值改为 comment == null ? name : comment.value(),使折叠组也能吃 @Comment。

🔍 根因分析(这个修复为什么是对的)

这是真 bug 的修复,证据链完整:

  1. ConfigData.java:23-24:
    • TOOLTIP_STRING = OPTION_STRING + ".tooltip" → "%s.configuration.%s.tooltip"
    • COLLAPSIBLE_OBJECT_TOOLTIP_STRING = "%s.configuration.%s.tooltip"
    • 两个常量格式化后生成完全相同的 lang key(只有 .button 是独立 key)。
  2. ProviderProxy.add(ConfigData.java:29-33)有 ADDED 全局去重,语义是先到先得(后到直接 return)。这个守卫是必需的:NeoForge 的 LanguageProvider.add(String,String) 是
    if (data.put(key, value) != null) throw new IllegalStateException("Duplicate translation key " + key);
    (已在本地 neoforge-21.1.238-sources.jar 中核对,第 123-126 行)——没有守卫,@CollapsibleObject + @Comment 会直接让 datagen 抛「Duplicate translation key」。
  3. 由于 collapsible 的 tooltip 写入发生在 @Comment 分支之前,修复前该 key 被 name(英文名)占据,comment.value() 那次 add 被静默吞掉 ⇒ 折叠组的注释在语言文件里丢失。本 PR 把先写的那次值改成注释,行为就正确了。

⚠️ 警告

  1. 修复依赖「两个常量恰好同值 + 去重先到先得」,且没有任何注释说明。 任何人日后把 collapsible 的 key 改成真正的独立 key(例如 "%s.configuration.%s.collapsible.tooltip"),或调整 ADDED 守卫,都会静默回退到「注释丢失」;更糟的是 key 分开后还会在语言文件里产出 name / comment 两份互相矛盾的 tooltip。建议显式表达意图(生成结果与当前 PR 完全等价:折叠组无注释→英文名、有注释→注释、普通字段无注释→不产出 tooltip key):

    if (flag) {
        proxy.add(COLLAPSIBLE_OBJECT_BUTTON_STRING.formatted(modId, fieldName), name);
        ConfigData.readConfigClass(proxy, modId, type, fieldType, fieldName);
    }
    proxy.add(OPTION_STRING.formatted(modId, fieldName), name);
    String tooltip = (comment == null || comment.value().isBlank())
        ? (flag ? name : null) : comment.value();
    if (tooltip != null) proxy.add(TOOLTIP_STRING.formatted(modId, fieldName), tooltip);

    (COLLAPSIBLE_OBJECT_TOOLTIP_STRING 随之不再使用;它是 public static final,下游可能引用,建议标 @Deprecated 而非直接删除。)

  2. 裸 @Comment(不传值)时折叠组 tooltip 变空串 —— Comment.value() 默认 ""(Comment.java:11)。修复前 collapsible 字段因 name 先写入,@Comment 空值无影响;修复后 comment != null 成立 ⇒ tooltip 变成 "",形成一个空提示框。普通字段本来就是这个行为(pre-existing),所以算是「向普通字段看齐」,但折叠组这条路径确实是「从有内容变空」。上面建议里的 isBlank() 回退可一并解决。仓库现存 @Comment 均带值,实际触发概率低,非阻塞。

💡 建议

  1. 折叠组 .button 仍用 name,而 .tooltip 用注释(两条 key 来源不同)——若非有意,建议确认按钮文案是否也应跟注释一致。
  2. 补一条回归样例:module.test 的 AnvilLibTestConfig 里 testObject 是 @CollapsibleObject(无注释)、testString2 是 @Comment(非折叠),恰好绕开了被修的组合。建议加一个 @CollapsibleObject @Comment("...") 字段并跑 runData,把生成的 tooltip 值纳入回归。
  3. 已在 base(6138b0d2) 全仓核对:当前只有 AnvilLibTestConfig.testObject 使用 @CollapsibleObject,且该组合在仓库内为零;explosion/multiblock/recipe 三处 readConfigClass 数据生成的配置类都没有折叠字段 ⇒ 本 PR 不需要重新生成任何语言资源(PR 未包含生成文件是正确做法)。受益方是下游同时标注两注解的字段,建议在 PR 描述中写一句这个前提(当前描述为 None)。

🟢 看起来不错

  • 改动面最小,comment 变量上提对其它路径无副作用;flag && comment == null 分支严格保持旧行为。
  • head 文件与 patch 完全一致,diff 未被截断(changed_files=1、+6/-3 与 patch 逐行吻合)。
  • 修的是「语言文件里注释静默丢失」这类难排查的问题,且诊断链路(常量别名 → 去重守卫 → NeoForge dupe throw)拿捏准确。

标题

gh auth status 显示 token 失效(The token in .../hosts.yml is invalid),按规约不尝试导出凭据,本次未自动修改标题。建议标题(原文 "Make CollapsibleObject can use Comment" 语法不通,且未点明是配置界面 tooltip/语言文件):

Support @Comment on @CollapsibleObject fields 使 CollapsibleObject 支持 @Comment

结论: COMMENT — 修复正确、无阻塞性问题,建议按 ⚠️1 显式化写法(或至少加一句注释说明「两常量同值 + 先到先得」的隐含契约),并补一个折叠组 + @Comment 的数据生成回归样例。

🧪 测试建议

被测目标 推荐测试场景 优先级
ConfigData.providerAdd() @CollapsibleObject + @Comment("x") → 断言 <mod>.configuration.<field>.tooltip == "x"(当前必红,修复后必绿) 🔴
同上 @CollapsibleObject + @Comment(空值)→ 断言不为空串 🟡
同上 @CollapsibleObject(无注释)→ tooltip 保持英文名;@Comment 普通字段不受影响 🟡
ProviderProxy.add() 同 key 二次 add 不得抛 IllegalStateException(防未来去掉守卫时 datagen 崩) 🟢

由 Hermes Agent 审查

@Gugle2308

Copy link
Copy Markdown

💾 Self-improvement review: Patched SKILL.md in skill 'minecraft-lang-pipeline-review' (1 replacement).

@ZhuRuoLing ZhuRuoLing left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM - ported config Comment support

@ZhuRuoLing
ZhuRuoLing merged commit ce407af into Anvil-Dev:dev/1.21.4 Oct 10, 2026
39 checks passed
@Gugle2308

Copy link
Copy Markdown

PR #150 状态为 closed(已 merged),按 webhook 审查规则(closed/labeled → 停止),本次不进行审查、不发布评论。

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