feat(config): 添加AI-First配置系统及源生成器#168
Merged
Merged
Conversation
- 实现YAML配置文件加载和JSON Schema校验功能 - 提供Source Generator自动生成配置类型和表包装类 - 添加VS Code插件支持配置浏览和表单编辑 - 支持跨表引用校验和开发期热重载功能 - 生成强类型的配置访问辅助方法和注册绑定 - 实现嵌套对象和对象数组的类型安全访问
|
|
Overall Grade |
Security Reliability Complexity Hygiene |
Code Review Summary
| Analyzer | Status | Updated (UTC) | Details |
|---|---|---|---|
| C# | Apr 3, 2026 2:04a.m. | Review ↗ | |
| Secrets | Apr 3, 2026 2:04a.m. | Review ↗ |
审阅者指南扩展基于 schema 的配置源代码生成器,为每个 schema 生成强类型的运行时注册和访问辅助方法;丰富 schema 模型以携带命名和路径元数据;将新的生成输出接入测试和文档,并为生成的绑定添加快照覆盖。 生成的配置注册与访问辅助方法的时序图sequenceDiagram
actor Developer
participant YamlConfigLoader
participant MonsterConfigBindings
participant ConfigRegistry
participant IConfigRegistry
participant MonsterTable
Developer->>YamlConfigLoader: new YamlConfigLoader("config-root")
Developer->>YamlConfigLoader: RegisterMonsterTable()
activate YamlConfigLoader
YamlConfigLoader->>MonsterConfigBindings: extension RegisterMonsterTable(loader, comparer)
activate MonsterConfigBindings
MonsterConfigBindings->>YamlConfigLoader: RegisterTable<int, MonsterConfig>(
MonsterConfigBindings-->>YamlConfigLoader: returns loader
deactivate MonsterConfigBindings
YamlConfigLoader-->>Developer: loader
deactivate YamlConfigLoader
Developer->>YamlConfigLoader: LoadAsync(ConfigRegistry)
YamlConfigLoader->>ConfigRegistry: register table using TableName,
YamlConfigLoader-->>Developer: completed
Developer->>ConfigRegistry: GetMonsterTable()
activate ConfigRegistry
ConfigRegistry->>MonsterConfigBindings: extension GetMonsterTable(registry)
activate MonsterConfigBindings
MonsterConfigBindings->>IConfigRegistry: GetTable<int, MonsterConfig>(TableName)
activate IConfigRegistry
IConfigRegistry-->>MonsterConfigBindings: IConfigTable<int, MonsterConfig>
deactivate IConfigRegistry
MonsterConfigBindings->>MonsterTable: new MonsterTable(innerTable)
activate MonsterTable
MonsterTable-->>MonsterConfigBindings: instance
deactivate MonsterTable
MonsterConfigBindings-->>ConfigRegistry: MonsterTable
deactivate MonsterConfigBindings
ConfigRegistry-->>Developer: MonsterTable
deactivate ConfigRegistry
Developer->>MonsterTable: Get(1)
MonsterTable-->>Developer: MonsterConfig slime
Schema 模型与生成配置绑定的类图classDiagram
direction LR
class SchemaFileSpec {
+string FileName
+string EntityName
+string ClassName
+string TableName
+string Namespace
+string KeyClrType
+string KeyPropertyName
+string TableRegistrationName
+string ConfigRelativePath
+string SchemaRelativePath
+string Title
+string Description
+SchemaObjectSpec RootObject
}
class MonsterConfigBindings {
<<static>>
+const string TableName
+const string ConfigRelativePath
+const string SchemaRelativePath
+YamlConfigLoader RegisterMonsterTable(loader, comparer)
+MonsterTable GetMonsterTable(registry)
+bool TryGetMonsterTable(registry, table)
}
class YamlConfigLoader {
+YamlConfigLoader RegisterTable~TKey, TValue~(tableName, relativePath, schemaRelativePath, keySelector, comparer)
+YamlConfigLoader EnableHotReload(watcher, onReloaded)
+Task LoadAsync(registry)
}
class IConfigRegistry {
<<interface>>
+IConfigTable~TKey, TValue~ GetTable~TKey, TValue~(name)
+bool TryGetTable~TKey, TValue~(name, table)
}
class IConfigTable~TKey, TValue~ {
<<interface>>
+int Count()
+TValue Get(key)
+bool ContainsKey(key)
+IReadOnlyCollection~TValue~ All()
}
class MonsterTable {
-IConfigTable~int, MonsterConfig~ inner
+int Count()
+MonsterConfig Get(id)
+bool ContainsKey(id)
+IReadOnlyCollection~MonsterConfig~ All()
}
class MonsterConfig {
+int Id
+string Name
+int Hp
+int Attack
}
class SchemaConfigGenerator {
+Initialize(context)
-SchemaParseResult ParseSchema(file)
-string GenerateTableClass(schema)
-string GenerateBindingsClass(schema)
-string GetSchemaBaseName(path)
-string GetSchemaRelativePath(path)
}
SchemaConfigGenerator --> SchemaFileSpec : uses
SchemaConfigGenerator ..> MonsterConfigBindings : generates
SchemaConfigGenerator ..> MonsterTable : generates
SchemaConfigGenerator ..> MonsterConfig : generates
MonsterConfigBindings ..> YamlConfigLoader : extension RegisterMonsterTable
MonsterConfigBindings ..> IConfigRegistry : extension GetMonsterTable, TryGetMonsterTable
MonsterConfigBindings ..> MonsterTable : constructs
MonsterTable ..|> IConfigTable~int, MonsterConfig~ : implements
IConfigRegistry ..> IConfigTable~TKey, TValue~ : returns
MonsterConfig <-- MonsterTable : wraps values
SchemaFileSpec o--> SchemaObjectSpec : RootObject
文件级改动
提示与命令与 Sourcery 交互
自定义你的体验访问你的控制面板 以:
获取帮助Original review guide in EnglishReviewer's GuideExtends the schema-based config source generator to emit strongly typed runtime registration and access helpers for each schema, expands the schema model to carry naming and path metadata, wires new generator outputs into tests and documentation, and adds snapshot coverage for the generated bindings. Sequence diagram for generated config registration and access helperssequenceDiagram
actor Developer
participant YamlConfigLoader
participant MonsterConfigBindings
participant ConfigRegistry
participant IConfigRegistry
participant MonsterTable
Developer->>YamlConfigLoader: new YamlConfigLoader("config-root")
Developer->>YamlConfigLoader: RegisterMonsterTable()
activate YamlConfigLoader
YamlConfigLoader->>MonsterConfigBindings: extension RegisterMonsterTable(loader, comparer)
activate MonsterConfigBindings
MonsterConfigBindings->>YamlConfigLoader: RegisterTable<int, MonsterConfig>(
MonsterConfigBindings-->>YamlConfigLoader: returns loader
deactivate MonsterConfigBindings
YamlConfigLoader-->>Developer: loader
deactivate YamlConfigLoader
Developer->>YamlConfigLoader: LoadAsync(ConfigRegistry)
YamlConfigLoader->>ConfigRegistry: register table using TableName,
YamlConfigLoader-->>Developer: completed
Developer->>ConfigRegistry: GetMonsterTable()
activate ConfigRegistry
ConfigRegistry->>MonsterConfigBindings: extension GetMonsterTable(registry)
activate MonsterConfigBindings
MonsterConfigBindings->>IConfigRegistry: GetTable<int, MonsterConfig>(TableName)
activate IConfigRegistry
IConfigRegistry-->>MonsterConfigBindings: IConfigTable<int, MonsterConfig>
deactivate IConfigRegistry
MonsterConfigBindings->>MonsterTable: new MonsterTable(innerTable)
activate MonsterTable
MonsterTable-->>MonsterConfigBindings: instance
deactivate MonsterTable
MonsterConfigBindings-->>ConfigRegistry: MonsterTable
deactivate MonsterConfigBindings
ConfigRegistry-->>Developer: MonsterTable
deactivate ConfigRegistry
Developer->>MonsterTable: Get(1)
MonsterTable-->>Developer: MonsterConfig slime
Class diagram for schema model and generated config bindingsclassDiagram
direction LR
class SchemaFileSpec {
+string FileName
+string EntityName
+string ClassName
+string TableName
+string Namespace
+string KeyClrType
+string KeyPropertyName
+string TableRegistrationName
+string ConfigRelativePath
+string SchemaRelativePath
+string Title
+string Description
+SchemaObjectSpec RootObject
}
class MonsterConfigBindings {
<<static>>
+const string TableName
+const string ConfigRelativePath
+const string SchemaRelativePath
+YamlConfigLoader RegisterMonsterTable(loader, comparer)
+MonsterTable GetMonsterTable(registry)
+bool TryGetMonsterTable(registry, table)
}
class YamlConfigLoader {
+YamlConfigLoader RegisterTable~TKey, TValue~(tableName, relativePath, schemaRelativePath, keySelector, comparer)
+YamlConfigLoader EnableHotReload(watcher, onReloaded)
+Task LoadAsync(registry)
}
class IConfigRegistry {
<<interface>>
+IConfigTable~TKey, TValue~ GetTable~TKey, TValue~(name)
+bool TryGetTable~TKey, TValue~(name, table)
}
class IConfigTable~TKey, TValue~ {
<<interface>>
+int Count()
+TValue Get(key)
+bool ContainsKey(key)
+IReadOnlyCollection~TValue~ All()
}
class MonsterTable {
-IConfigTable~int, MonsterConfig~ inner
+int Count()
+MonsterConfig Get(id)
+bool ContainsKey(id)
+IReadOnlyCollection~MonsterConfig~ All()
}
class MonsterConfig {
+int Id
+string Name
+int Hp
+int Attack
}
class SchemaConfigGenerator {
+Initialize(context)
-SchemaParseResult ParseSchema(file)
-string GenerateTableClass(schema)
-string GenerateBindingsClass(schema)
-string GetSchemaBaseName(path)
-string GetSchemaRelativePath(path)
}
SchemaConfigGenerator --> SchemaFileSpec : uses
SchemaConfigGenerator ..> MonsterConfigBindings : generates
SchemaConfigGenerator ..> MonsterTable : generates
SchemaConfigGenerator ..> MonsterConfig : generates
MonsterConfigBindings ..> YamlConfigLoader : extension RegisterMonsterTable
MonsterConfigBindings ..> IConfigRegistry : extension GetMonsterTable, TryGetMonsterTable
MonsterConfigBindings ..> MonsterTable : constructs
MonsterTable ..|> IConfigTable~int, MonsterConfig~ : implements
IConfigRegistry ..> IConfigTable~TKey, TValue~ : returns
MonsterConfig <-- MonsterTable : wraps values
SchemaFileSpec o--> SchemaObjectSpec : RootObject
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - 我发现了 1 个问题。
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="GFramework.SourceGenerators.Tests/Config/snapshots/SchemaConfigGenerator/MonsterConfigBindings.g.txt" line_range="8-17" />
<code_context>
+/// The helper centralizes table naming, config directory, schema path, and strong-typed registry access so consumer projects do not need to duplicate the same conventions.
</code_context>
<issue_to_address>
**issue (typo):** 在这些 XML 注释中请使用更常见的表达方式 "strongly-typed",而不是 "strong-typed"。
在这些 XML 文档注释中,"strong-typed" 应该改为 "strongly-typed"(或 "strongly typed"),以符合标准的 .NET 术语。请更新所有出现的位置,使措辞更加自然。
建议修改为:
```
/// Auto-generated registration and lookup helpers for schema file 'monster.schema.json'.
/// The helper centralizes table naming, config directory, schema path, and strongly-typed registry access so consumer projects do not need to duplicate the same conventions.
```
在类似的生成绑定文件或相关快照文件中,可能还存在其他 "strong-typed" 的用法。为了保持一致性,请在整个解决方案中搜索(尤其是 `GFramework.SourceGenerators.Tests/Config/snapshots/SchemaConfigGenerator/` 目录下)所有 "strong-typed" 的出现,并在 XML 注释中将其全部替换为 "strongly-typed"(或者如果你更喜欢这种风格,也可以用 "strongly typed"),并与此处选定的表达方式保持一致。
</issue_to_address>帮我变得更有用!请对每条评论点 👍 或 👎,我会根据你的反馈改进后续的代码审查。
Original comment in English
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="GFramework.SourceGenerators.Tests/Config/snapshots/SchemaConfigGenerator/MonsterConfigBindings.g.txt" line_range="8-17" />
<code_context>
+/// The helper centralizes table naming, config directory, schema path, and strong-typed registry access so consumer projects do not need to duplicate the same conventions.
</code_context>
<issue_to_address>
**issue (typo):** Use the more standard phrasing "strongly-typed" instead of "strong-typed" in these XML comments.
In these XML doc comments, "strong-typed" should be "strongly-typed" (or "strongly typed") to match standard .NET terminology. Please update all occurrences for more natural wording.
Suggested implementation:
```
/// Auto-generated registration and lookup helpers for schema file 'monster.schema.json'.
/// The helper centralizes table naming, config directory, schema path, and strongly-typed registry access so consumer projects do not need to duplicate the same conventions.
```
There may be other occurrences of "strong-typed" in similar generated bindings or related snapshot files. For consistency, search the entire solution (especially under `GFramework.SourceGenerators.Tests/Config/snapshots/SchemaConfigGenerator/`) for "strong-typed" and replace all instances in XML comments with "strongly-typed" (or "strongly typed" if you prefer that style), matching the chosen phrasing here.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
- 实现了根据JSON schema自动生成配置类型和配置表包装的功能 - 支持嵌套对象、对象数组、标量数组的类型生成 - 提供可映射的default/enum/ref-table元数据支持 - 生成强类型的配置表包装器和运行时绑定辅助类 - 实现了完整的schema解析和C#代码生成功能 - 添加了详细的XML文档注释和错误诊断功能
- 引入 System.Globalization 用于区域设置相关操作 - 添加 System.IO 支持文件输入输出功能 - 集成 System.Text 提供文本处理能力 - 包含 System.Text.Json 用于 JSON 序列化反序列化
This was referenced May 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
从 JSON schema 文件生成强类型的配置注册与查找辅助工具,并更新文档和测试以反映新的绑定方式。
Enhancements:
Documentation:
Tests:
Original summary in English
Summary by Sourcery
Generate strongly-typed config registration and lookup helpers from JSON schema files and update docs and tests to reflect the new bindings.
Enhancements:
Documentation:
Tests: