From 929ea6b2d6d1bc64a32eeaa0d161f0c1af841676 Mon Sep 17 00:00:00 2001 From: GwWuYou <95328647+GeWuYou@users.noreply.github.com> Date: Sun, 28 Dec 2025 08:54:52 +0800 Subject: [PATCH] =?UTF-8?q?refactor(godot):=20=E9=87=8D=E6=9E=84=E6=BA=90?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90=E5=99=A8=E4=BE=9D=E8=B5=96?= =?UTF-8?q?=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将CommonDiagnostics移至GFramework.SourceGenerators.Common模块 - 添加PathContests常量类统一管理路径常量 - 更新GodotLoggerGenerator使用新的路径常量和诊断引用 - 修改项目引用以包含GFramework.SourceGenerators.Common依赖 - 更新NuGet包配置以包含Common模块的DLL和XML文档 - 在解决方案文件中添加GFramework.SourceGenerators.Common项目引用 - 为Common模块创建Analyzer发布跟踪文件 --- .../AnalyzerReleases.Unshipped.md | 1 - .../GFramework.Godot.SourceGenerators.csproj | 8 +++++ ....GFramework.Godot.SourceGenerators.targets | 1 + .../constants/PathContests.cs | 6 ++++ .../logging/GodotLoggerGenerator.cs | 5 ++-- .../AnalyzerReleases.Shipped.md | 3 ++ .../AnalyzerReleases.Unshipped.md | 8 +++++ .../Directory.Build.props | 24 +++++++++++++++ .../GFramework.SourceGenerators.Common.csproj | 24 +++++++++++++++ .../diagnostics/CommonDiagnostics.cs | 2 +- .../AnalyzerReleases.Unshipped.md | 1 - .../GFramework.SourceGenerators.csproj | 9 +++++- ...eWuYou.GFramework.SourceGenerators.targets | 1 + .../constants/PathContests.cs | 6 ++++ .../diagnostics/CommonDiagnostics.cs | 29 ------------------- .../enums/EnumExtensionsGenerator.cs | 8 ++--- .../logging/LoggerGenerator.cs | 5 ++-- .../rule/ContextAwareGenerator.cs | 4 ++- GFramework.sln | 6 ++++ 19 files changed, 109 insertions(+), 42 deletions(-) create mode 100644 GFramework.Godot.SourceGenerators/constants/PathContests.cs create mode 100644 GFramework.SourceGenerators.Common/AnalyzerReleases.Shipped.md create mode 100644 GFramework.SourceGenerators.Common/AnalyzerReleases.Unshipped.md create mode 100644 GFramework.SourceGenerators.Common/Directory.Build.props create mode 100644 GFramework.SourceGenerators.Common/GFramework.SourceGenerators.Common.csproj rename {GFramework.Godot.SourceGenerators => GFramework.SourceGenerators.Common}/diagnostics/CommonDiagnostics.cs (93%) create mode 100644 GFramework.SourceGenerators/constants/PathContests.cs delete mode 100644 GFramework.SourceGenerators/diagnostics/CommonDiagnostics.cs diff --git a/GFramework.Godot.SourceGenerators/AnalyzerReleases.Unshipped.md b/GFramework.Godot.SourceGenerators/AnalyzerReleases.Unshipped.md index 7043d79..58de45e 100644 --- a/GFramework.Godot.SourceGenerators/AnalyzerReleases.Unshipped.md +++ b/GFramework.Godot.SourceGenerators/AnalyzerReleases.Unshipped.md @@ -5,5 +5,4 @@ Rule ID | Category | Severity | Notes ----------------------|--------------------------|----------|------------------------ - GF_Common_Class_001 | GFramework.Common | Error | CommonDiagnostics GF_Godot_Logging_001 | GFramework.Godot.Logging | Warning | GodotLoggerDiagnostics \ No newline at end of file diff --git a/GFramework.Godot.SourceGenerators/GFramework.Godot.SourceGenerators.csproj b/GFramework.Godot.SourceGenerators/GFramework.Godot.SourceGenerators.csproj index c62f58b..1e4b9fc 100644 --- a/GFramework.Godot.SourceGenerators/GFramework.Godot.SourceGenerators.csproj +++ b/GFramework.Godot.SourceGenerators/GFramework.Godot.SourceGenerators.csproj @@ -29,6 +29,7 @@ + @@ -44,10 +45,17 @@ Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false"/> + + + + diff --git a/GFramework.Godot.SourceGenerators/GeWuYou.GFramework.Godot.SourceGenerators.targets b/GFramework.Godot.SourceGenerators/GeWuYou.GFramework.Godot.SourceGenerators.targets index d1196d5..37971c9 100644 --- a/GFramework.Godot.SourceGenerators/GeWuYou.GFramework.Godot.SourceGenerators.targets +++ b/GFramework.Godot.SourceGenerators/GeWuYou.GFramework.Godot.SourceGenerators.targets @@ -6,6 +6,7 @@ + diff --git a/GFramework.Godot.SourceGenerators/constants/PathContests.cs b/GFramework.Godot.SourceGenerators/constants/PathContests.cs new file mode 100644 index 0000000..d439327 --- /dev/null +++ b/GFramework.Godot.SourceGenerators/constants/PathContests.cs @@ -0,0 +1,6 @@ +namespace GFramework.Godot.SourceGenerators.constants; + +public static class PathContests +{ + public const string RootAbstractionsPath = "GFramework.Godot.SourceGenerators.Abstractions"; +} \ No newline at end of file diff --git a/GFramework.Godot.SourceGenerators/logging/GodotLoggerGenerator.cs b/GFramework.Godot.SourceGenerators/logging/GodotLoggerGenerator.cs index 7ce8b19..e5f8dbd 100644 --- a/GFramework.Godot.SourceGenerators/logging/GodotLoggerGenerator.cs +++ b/GFramework.Godot.SourceGenerators/logging/GodotLoggerGenerator.cs @@ -1,7 +1,8 @@ using System; using System.Linq; using System.Text; -using GFramework.Godot.SourceGenerators.diagnostics; +using GFramework.Godot.SourceGenerators.constants; +using GFramework.SourceGenerators.Common.diagnostics; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -16,7 +17,7 @@ namespace GFramework.Godot.SourceGenerators.logging; public sealed class GodotLoggerGenerator : IIncrementalGenerator { private const string AttributeMetadataName = - "GFramework.Godot.SourceGenerators.Abstractions.logging.GodotLogAttribute"; + $"{PathContests.RootAbstractionsPath}.logging.GodotLogAttribute"; private const string AttributeShortName = "GodotLogAttribute"; private const string AttributeShortNameWithoutSuffix = "GodotLog"; diff --git a/GFramework.SourceGenerators.Common/AnalyzerReleases.Shipped.md b/GFramework.SourceGenerators.Common/AnalyzerReleases.Shipped.md new file mode 100644 index 0000000..60b59dd --- /dev/null +++ b/GFramework.SourceGenerators.Common/AnalyzerReleases.Shipped.md @@ -0,0 +1,3 @@ +; Shipped analyzer releases +; https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md + diff --git a/GFramework.SourceGenerators.Common/AnalyzerReleases.Unshipped.md b/GFramework.SourceGenerators.Common/AnalyzerReleases.Unshipped.md new file mode 100644 index 0000000..7f402e3 --- /dev/null +++ b/GFramework.SourceGenerators.Common/AnalyzerReleases.Unshipped.md @@ -0,0 +1,8 @@ +; Unshipped analyzer release +; https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md + +### New Rules + + Rule ID | Category | Severity | Notes +---------------------|-------------------|----------|------------------- + GF_Common_Class_001 | GFramework.Common | Error | CommonDiagnostics \ No newline at end of file diff --git a/GFramework.SourceGenerators.Common/Directory.Build.props b/GFramework.SourceGenerators.Common/Directory.Build.props new file mode 100644 index 0000000..82f43af --- /dev/null +++ b/GFramework.SourceGenerators.Common/Directory.Build.props @@ -0,0 +1,24 @@ + + + + netstandard2.0 + true + true + + preview + + + + all + runtime; build; native; contentfiles; analyzers + + + all + runtime; build; native; contentfiles; analyzers + + + diff --git a/GFramework.SourceGenerators.Common/GFramework.SourceGenerators.Common.csproj b/GFramework.SourceGenerators.Common/GFramework.SourceGenerators.Common.csproj new file mode 100644 index 0000000..2bcf12c --- /dev/null +++ b/GFramework.SourceGenerators.Common/GFramework.SourceGenerators.Common.csproj @@ -0,0 +1,24 @@ + + + + + false + true + T:System.Diagnostics.CodeAnalysis.NotNullWhenAttribute + + + + + + + + + + + + + + diff --git a/GFramework.Godot.SourceGenerators/diagnostics/CommonDiagnostics.cs b/GFramework.SourceGenerators.Common/diagnostics/CommonDiagnostics.cs similarity index 93% rename from GFramework.Godot.SourceGenerators/diagnostics/CommonDiagnostics.cs rename to GFramework.SourceGenerators.Common/diagnostics/CommonDiagnostics.cs index 2b7d586..78cd1b8 100644 --- a/GFramework.Godot.SourceGenerators/diagnostics/CommonDiagnostics.cs +++ b/GFramework.SourceGenerators.Common/diagnostics/CommonDiagnostics.cs @@ -1,6 +1,6 @@ using Microsoft.CodeAnalysis; -namespace GFramework.Godot.SourceGenerators.diagnostics; +namespace GFramework.SourceGenerators.Common.diagnostics; /// /// 提供通用诊断描述符的静态类 diff --git a/GFramework.SourceGenerators/AnalyzerReleases.Unshipped.md b/GFramework.SourceGenerators/AnalyzerReleases.Unshipped.md index 9ceb908..325ddf4 100644 --- a/GFramework.SourceGenerators/AnalyzerReleases.Unshipped.md +++ b/GFramework.SourceGenerators/AnalyzerReleases.Unshipped.md @@ -5,6 +5,5 @@ Rule ID | Category | Severity | Notes ---------------------|----------------------------------|----------|------------------------ - GF_Common_Class_001 | GFramework.Common | Error | CommonDiagnostics GF_Logging_001 | GFramework.Godot.Logging | Warning | LoggerDiagnostics GF_Rule_001 | GFramework.SourceGenerators.rule | Error | ContextAwareDiagnostic \ No newline at end of file diff --git a/GFramework.SourceGenerators/GFramework.SourceGenerators.csproj b/GFramework.SourceGenerators/GFramework.SourceGenerators.csproj index 86fc3f2..cec2481 100644 --- a/GFramework.SourceGenerators/GFramework.SourceGenerators.csproj +++ b/GFramework.SourceGenerators/GFramework.SourceGenerators.csproj @@ -29,6 +29,7 @@ + @@ -44,12 +45,18 @@ Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false"/> + + - + + diff --git a/GFramework.SourceGenerators/GeWuYou.GFramework.SourceGenerators.targets b/GFramework.SourceGenerators/GeWuYou.GFramework.SourceGenerators.targets index 1bfd5a0..de3165c 100644 --- a/GFramework.SourceGenerators/GeWuYou.GFramework.SourceGenerators.targets +++ b/GFramework.SourceGenerators/GeWuYou.GFramework.SourceGenerators.targets @@ -6,6 +6,7 @@ + diff --git a/GFramework.SourceGenerators/constants/PathContests.cs b/GFramework.SourceGenerators/constants/PathContests.cs new file mode 100644 index 0000000..9814aab --- /dev/null +++ b/GFramework.SourceGenerators/constants/PathContests.cs @@ -0,0 +1,6 @@ +namespace GFramework.SourceGenerators.constants; + +public static class PathContests +{ + public const string RootAbstractionsPath = "GFramework.SourceGenerators.Abstractions"; +} \ No newline at end of file diff --git a/GFramework.SourceGenerators/diagnostics/CommonDiagnostics.cs b/GFramework.SourceGenerators/diagnostics/CommonDiagnostics.cs deleted file mode 100644 index 1bd575d..0000000 --- a/GFramework.SourceGenerators/diagnostics/CommonDiagnostics.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Microsoft.CodeAnalysis; - -namespace GFramework.SourceGenerators.diagnostics; - -/// -/// 提供通用诊断描述符的静态类 -/// -public static class CommonDiagnostics -{ - /// - /// 定义类必须为partial的诊断描述符 - /// - /// - /// 诊断ID: GF001 - /// 诊断消息: "Class '{0}' must be declared partial for code generation" - /// 分类: GFramework.Common - /// 严重性: Error - /// 是否启用: true - /// - public static readonly DiagnosticDescriptor ClassMustBePartial = - new( - "GF_Common_Class_001", - "Class must be partial", - "Class '{0}' must be declared partial for code generation", - "GFramework.Common", - DiagnosticSeverity.Error, - true - ); -} \ No newline at end of file diff --git a/GFramework.SourceGenerators/enums/EnumExtensionsGenerator.cs b/GFramework.SourceGenerators/enums/EnumExtensionsGenerator.cs index 9d9b36f..1f23cab 100644 --- a/GFramework.SourceGenerators/enums/EnumExtensionsGenerator.cs +++ b/GFramework.SourceGenerators/enums/EnumExtensionsGenerator.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Text; +using GFramework.SourceGenerators.constants; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Text; @@ -11,7 +12,7 @@ namespace GFramework.SourceGenerators.enums; public class EnumExtensionsGenerator : IIncrementalGenerator { private const string AttributeFullName = - "GFramework.SourceGenerators.Abstractions.generator.enums.GenerateEnumExtensionsAttribute"; + $"{PathContests.RootAbstractionsPath}.enums.GenerateEnumExtensionsAttribute"; public void Initialize(IncrementalGeneratorInitializationContext context) { @@ -35,9 +36,8 @@ public class EnumExtensionsGenerator : IIncrementalGenerator .Where(symbol => symbol != null) .Select((symbol, _) => { - var hasAttr = symbol.GetAttributes().Any(ad => - ad.AttributeClass?.ToDisplayString() == AttributeFullName || - ad.AttributeClass?.ToDisplayString().EndsWith(".GenerateEnumExtensionsAttribute") == true); + var hasAttr = symbol!.GetAttributes().Any(ad => + ad.AttributeClass?.ToDisplayString() == AttributeFullName); return (Symbol: symbol, HasAttr: hasAttr); }) .Where(x => x.HasAttr) diff --git a/GFramework.SourceGenerators/logging/LoggerGenerator.cs b/GFramework.SourceGenerators/logging/LoggerGenerator.cs index fa2b3bf..554ab2a 100644 --- a/GFramework.SourceGenerators/logging/LoggerGenerator.cs +++ b/GFramework.SourceGenerators/logging/LoggerGenerator.cs @@ -1,7 +1,8 @@ using System; using System.Linq; using System.Text; -using GFramework.SourceGenerators.diagnostics; +using GFramework.SourceGenerators.Common.diagnostics; +using GFramework.SourceGenerators.constants; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -15,7 +16,7 @@ namespace GFramework.SourceGenerators.logging; [Generator] public sealed class LoggerGenerator : IIncrementalGenerator { - private const string AttributeMetadataName = "GFramework.SourceGenerators.Abstractions.logging.LogAttribute"; + private const string AttributeMetadataName = $"{PathContests.RootAbstractionsPath}.logging.LogAttribute"; private const string AttributeShortName = "LogAttribute"; private const string AttributeShortNameWithoutSuffix = "Log"; diff --git a/GFramework.SourceGenerators/rule/ContextAwareGenerator.cs b/GFramework.SourceGenerators/rule/ContextAwareGenerator.cs index 942e58e..d6a8ffb 100644 --- a/GFramework.SourceGenerators/rule/ContextAwareGenerator.cs +++ b/GFramework.SourceGenerators/rule/ContextAwareGenerator.cs @@ -1,5 +1,7 @@ using System.Linq; using System.Text; +using GFramework.SourceGenerators.Common.diagnostics; +using GFramework.SourceGenerators.constants; using GFramework.SourceGenerators.diagnostics; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; @@ -11,7 +13,7 @@ namespace GFramework.SourceGenerators.rule; public sealed class ContextAwareGenerator : IIncrementalGenerator { private const string AttributeMetadataName = - "GFramework.SourceGenerators.Abstractions.rule.ContextAwareAttribute"; + $"{PathContests.RootAbstractionsPath}.rule.ContextAwareAttribute"; public void Initialize(IncrementalGeneratorInitializationContext context) { diff --git a/GFramework.sln b/GFramework.sln index a7b836a..76f7d5f 100644 --- a/GFramework.sln +++ b/GFramework.sln @@ -18,6 +18,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GFramework.Godot.SourceGene EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GFramework.SourceGenerators.Tests", "GFramework.SourceGenerators.Tests\GFramework.SourceGenerators.Tests.csproj", "{BB047F43-6AA0-4EA0-8AE9-E6B9784D9E8E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GFramework.SourceGenerators.Common", "GFramework.SourceGenerators.Common\GFramework.SourceGenerators.Common.csproj", "{B6511C9A-40E1-4E51-8D1F-18EAFB3C5BFC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -60,5 +62,9 @@ Global {BB047F43-6AA0-4EA0-8AE9-E6B9784D9E8E}.Debug|Any CPU.Build.0 = Debug|Any CPU {BB047F43-6AA0-4EA0-8AE9-E6B9784D9E8E}.Release|Any CPU.ActiveCfg = Release|Any CPU {BB047F43-6AA0-4EA0-8AE9-E6B9784D9E8E}.Release|Any CPU.Build.0 = Release|Any CPU + {B6511C9A-40E1-4E51-8D1F-18EAFB3C5BFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B6511C9A-40E1-4E51-8D1F-18EAFB3C5BFC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B6511C9A-40E1-4E51-8D1F-18EAFB3C5BFC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B6511C9A-40E1-4E51-8D1F-18EAFB3C5BFC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal