mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-05-07 17:21:16 +08:00
- 实现YamlConfigLoader类,支持从文件目录加载YAML配置 - 提供RegisterTable方法支持配置表定义注册 - 实现热重载功能,监听文件变更并自动重新加载 - 支持schema校验,拒绝未知字段和类型错误 - 实现跨表引用校验,确保配置一致性 - 添加YamlConfigTableRegistrationOptions选项类 - 支持防抖机制避免频繁重载 - 提供详细的错误诊断信息
77 lines
2.9 KiB
C#
77 lines
2.9 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);
|
|
} |