Skip to content

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

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

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

Conversation

@QiuShui1012

Copy link
Copy Markdown
Contributor

No description provided.

@Gugle2308

Copy link
Copy Markdown

已完成审查。已确认 PR 仍处于 open(未合并),diff 与本地 git diff rvlib26 rvlib153 完全一致(blob f89dc0ad..72b321e6,1 文件 +6/-3)。


代码审查摘要 — PR #153(AnvilLib)

操作: opened(PR 当前 open,未合并;pullOpened)
范围: 1 个文件(1 Java,0 新增,0 删除)/ 27 行 diff,+6 / -3,1 commit
目标: module.config/src/main/java/dev/anvilcraft/lib/v2/config/ConfigData.java

🔍 根因确认(本 PR 修的是真 bug)

ConfigData.java:22-24:

public static final String OPTION_STRING = "%s.configuration.%s";
public static final String TOOLTIP_STRING = OPTION_STRING + ".tooltip";              // = "%s.configuration.%s.tooltip"
public static final String COLLAPSIBLE_OBJECT_TOOLTIP_STRING = "%s.configuration.%s.tooltip"; // ← 与上一行字节相同

两个常量生成同一个 lang key(<modid>.configuration.<path>.tooltip),而 ProviderProxy.add 用静态集合 ADDED 做「首次写入生效」去重。旧代码的顺序是:

  1. add(COLLAPSIBLE_OBJECT_TOOLTIP_STRING…, name) → 写 key = 字段英文名
  2. add(TOOLTIP_STRING…, comment.value()) → 同 key,被去重静默丢弃

⇒ 打在 @CollapsibleObject 字段上的 @Comment 对配置界面 tooltip 一直无效(只在 TOML 注释里可见)。PR 在写入处直接取值,修复正确。

消费侧已交叉验证(NeoForge 26.1.2.76 sources jar,net/neoforged/neoforge/client/gui/ConfigurationScreen.java):

  • 第 563/568 行:tooltip key = getTranslationKey(key) + ".tooltip",存在时优先于 spec comment;
  • 第 915/927 行:折叠区块按钮文本 = getTranslationKey(key) + ".button",tooltip 走 getTooltipComponent(key, null)。

即修复后的 @Comment 确实会渲染为该折叠项的悬浮提示(首行仍是加粗的 OPTION_STRING 名称)。AnvilCraft 侧 data/lang/ConfigScreenLang.java:36-41 / 92-97 手写覆盖 ….button = "Expand Submenu" + ….tooltip = <描述> 也印证了同一套 key 约定。

⚠️ 警告

  1. 空注释会「从有到无」回退 — Comment.value() 默认 ""(Comment.java)。若写成 @Comment(不给值)或 @Comment(""),折叠项 tooltip 将变成空字符串;改前是显示字段英文名,属该边界下的行为退化。建议:

    comment == null || comment.value().isEmpty() ? name : comment.value()

    (非折叠路径本来就允许空 tooltip,故只是边界一致性建议,非阻塞。)

  2. 对 ADDED 去重顺序的隐式依赖 — 修复后同一 key 仍被写两次(先 collapsible 路径,后 TOOLTIP_STRING 路径),仅靠「first-wins」取到正确值。一旦有人调换顺序、或把去重改成 last-wins,修复会静默失效。建议把取值上提、只算一次,语义自明:

    Comment comment = field.getAnnotation(Comment.class);
    String tooltip = comment == null || comment.value().isEmpty() ? null : comment.value();
    ...
    if (flag) {
        proxy.add(COLLAPSIBLE_OBJECT_BUTTON_STRING…, name);
        proxy.add(COLLAPSIBLE_OBJECT_TOOLTIP_STRING…, tooltip == null ? name : tooltip);
        ConfigData.readConfigClass(…);
    }
    proxy.add(OPTION_STRING…, name);
    if (tooltip != null) proxy.add(TOOLTIP_STRING…, tooltip);

    另外既然两常量字节相同,建议直接复用 TOOLTIP_STRING 或加一行注释说明别名关系——否则「为什么这里要挑一个常量、顺序为何重要」对后来者不可见。

💡 建议

  • 补测试/datagen 覆盖:module.test/…/AnvilLibTestConfig.java:19 的 @CollapsibleObject 字段没有 @Comment,正好可加一个,使这条路径进入生成的 lang 并被检查(可顺带断言 .tooltip == comment)。
  • 补 PR 描述:当前 body 为空,建议一句话说明「@CollapsibleObject 上的 @comment 此前被 lang key 去重吞掉」并关联 issue。
  • 回填 1.21.1 线:本地 dev/1.21.1 检出中的 ConfigData.java:72-79 是同样的顺序与同样的 bug;若该线仍在维护,建议同步修复。
  • 标题(gh auth status 显示 token 已失效,401「Bad credentials」,故未自动改):现有 “Make CollapsibleObject can use Comment” 语法不通且未点明是注解。建议改为
    Let @Comment supply the @CollapsibleObject tooltip 使 CollapsibleObject 可以使用 Comment

🟢 看起来不错

  • comment 提前取出,消除了第二次 getAnnotation 反射调用,逻辑更清晰;
  • comment == null ? name : … 完整保留了无注解时的原回退语义;
  • 改动面最小:非折叠字段的 TOOLTIP_STRING 分支行为不变(同 key 已写入 → 第二次 add 仍是 no-op);
  • 无下游破坏性:AnvilCraft 现有 @CollapsibleObject 字段均未带 @Comment,且其 addOverride 会先占用 ADDED,覆盖不会失效。

🧪 测试建议

被测目标 推荐场景 优先级
ConfigData.providerAdd(collapsible 分支) @CollapsibleObject + @Comment("x") → .tooltip == "x";仅 @CollapsibleObject → .tooltip == 英文名 🟡
ConfigData.providerAdd @Comment("") → 是否回退到 name(采纳警告 1 后) 🟢
ProviderProxy.add 去重 同 key 被 collapsible 与 tooltip 两条路径写入时取首值,且与写入顺序无关 🟡

结论: APPROVE(COMMENT 级别) — 修复必要且正确,根因(两个常量生成同一 key + ADDED 去重)已核实;仅建议补空注释回退判断、并把取值上提以摆脱对写入顺序的隐式依赖。


由 Hermes Agent 审查

@Gugle2308

Copy link
Copy Markdown

💾 Self-improvement review: Patched references/config-lang-generator-key-alias-dedup.md in skill 'minecraft-lang-pipeline-review' (1 replacement). · 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 4626c19 into Anvil-Dev:dev/26.1 Oct 10, 2026
23 checks passed
@Gugle2308

Copy link
Copy Markdown

PR #153 状态为 closed,按 webhook 审查规则停止,不产出审查意见、不发表评论。

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