mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-05-07 17:21:16 +08:00
- 新增配置系统架构说明,涵盖 YAML 源文件、JSON Schema 结构描述、运行时只读查询等核心功能 - 完善推荐目录结构和 Schema 示例,包括怪物、物品配置表的标准定义方式 - 提供完整的接入模板,包含 csproj 配置、GameConfigHost 生命周期管理、GameConfigRuntime 读取入口 - 添加运行时校验行为说明,支持必填字段、类型匹配、数值范围、字符串长度、正则表达式、数组长度等多种约束 - 集成跨表引用功能,支持通过 x-gframework-ref-table 声明关联关系并进行有效性检查 - 添加开发期热重载支持,可自动监听配置目录和 schema 文件变更并重载对应表格 - 提供 VS Code 工具集成说明,包括配置浏览、raw 编辑、schema 打开、表单入口等功能 - 补充生成器接入约定,从 *.schema.json 自动生成配置类型、表包装、注册辅助等代码 - 添加完整的 Analyzer 规则文档,涵盖 GF_ConfigSchema_001 到 GF_ConfigSchema_008 等错误诊断码 - 增加单元测试验证,确保消费者项目可以正常使用生成的聚合注册辅助和强类型访问入口
100 lines
3.7 KiB
C#
100 lines
3.7 KiB
C#
using GFramework.SourceGenerators.Common.Constants;
|
|
|
|
namespace GFramework.SourceGenerators.Diagnostics;
|
|
|
|
/// <summary>
|
|
/// 提供配置 schema 代码生成相关诊断。
|
|
/// </summary>
|
|
public static class ConfigSchemaDiagnostics
|
|
{
|
|
private const string SourceGeneratorsConfigCategory = $"{PathContests.SourceGeneratorsPath}.Config";
|
|
|
|
/// <summary>
|
|
/// schema JSON 无法解析。
|
|
/// </summary>
|
|
public static readonly DiagnosticDescriptor InvalidSchemaJson = new(
|
|
"GF_ConfigSchema_001",
|
|
"Config schema JSON is invalid",
|
|
"Schema file '{0}' could not be parsed: {1}",
|
|
SourceGeneratorsConfigCategory,
|
|
DiagnosticSeverity.Error,
|
|
true);
|
|
|
|
/// <summary>
|
|
/// schema 顶层必须是 object。
|
|
/// </summary>
|
|
public static readonly DiagnosticDescriptor RootObjectSchemaRequired = new(
|
|
"GF_ConfigSchema_002",
|
|
"Config schema root must describe an object",
|
|
"Schema file '{0}' must declare a root object schema",
|
|
SourceGeneratorsConfigCategory,
|
|
DiagnosticSeverity.Error,
|
|
true);
|
|
|
|
/// <summary>
|
|
/// schema 必须声明 id 字段作为主键。
|
|
/// </summary>
|
|
public static readonly DiagnosticDescriptor IdPropertyRequired = new(
|
|
"GF_ConfigSchema_003",
|
|
"Config schema must declare an id property",
|
|
"Schema file '{0}' must declare a required 'id' property for table generation",
|
|
SourceGeneratorsConfigCategory,
|
|
DiagnosticSeverity.Error,
|
|
true);
|
|
|
|
/// <summary>
|
|
/// schema 包含暂不支持的字段类型。
|
|
/// </summary>
|
|
public static readonly DiagnosticDescriptor UnsupportedPropertyType = new(
|
|
"GF_ConfigSchema_004",
|
|
"Config schema contains an unsupported property type",
|
|
"Property '{1}' in schema file '{0}' uses unsupported type '{2}'",
|
|
SourceGeneratorsConfigCategory,
|
|
DiagnosticSeverity.Error,
|
|
true);
|
|
|
|
/// <summary>
|
|
/// schema 的 id 字段类型不支持作为主键。
|
|
/// </summary>
|
|
public static readonly DiagnosticDescriptor UnsupportedKeyType = new(
|
|
"GF_ConfigSchema_005",
|
|
"Config schema uses an unsupported key type",
|
|
"Schema file '{0}' uses unsupported id type '{1}'. Supported key types are 'integer' and 'string'.",
|
|
SourceGeneratorsConfigCategory,
|
|
DiagnosticSeverity.Error,
|
|
true);
|
|
|
|
/// <summary>
|
|
/// schema 字段名无法安全映射为 C# 标识符。
|
|
/// </summary>
|
|
public static readonly DiagnosticDescriptor InvalidGeneratedIdentifier = new(
|
|
"GF_ConfigSchema_006",
|
|
"Config schema property name cannot be converted to a valid C# identifier",
|
|
"Property '{1}' in schema file '{0}' uses schema key '{2}', which generates invalid C# identifier '{3}'",
|
|
SourceGeneratorsConfigCategory,
|
|
DiagnosticSeverity.Error,
|
|
true);
|
|
|
|
/// <summary>
|
|
/// schema 顶层自定义配置目录元数据无效。
|
|
/// </summary>
|
|
public static readonly DiagnosticDescriptor InvalidConfigRelativePathMetadata = new(
|
|
"GF_ConfigSchema_007",
|
|
"Config schema uses invalid custom config path metadata",
|
|
"Schema file '{0}' uses invalid '{1}' metadata: {2}",
|
|
SourceGeneratorsConfigCategory,
|
|
DiagnosticSeverity.Error,
|
|
true);
|
|
|
|
/// <summary>
|
|
/// schema 字段的查询索引元数据无效。
|
|
/// </summary>
|
|
public static readonly DiagnosticDescriptor InvalidLookupIndexMetadata = new(
|
|
"GF_ConfigSchema_008",
|
|
"Config schema uses invalid lookup index metadata",
|
|
"Property '{1}' in schema file '{0}' uses invalid '{2}' metadata: {3}",
|
|
SourceGeneratorsConfigCategory,
|
|
DiagnosticSeverity.Error,
|
|
true);
|
|
}
|