From 5f211d8680aef607aa7476b0bc6b283589a716c2 Mon Sep 17 00:00:00 2001 From: GeWuYou <95328647+GeWuYou@users.noreply.github.com> Date: Sat, 27 Dec 2025 13:31:27 +0800 Subject: [PATCH] =?UTF-8?q?fix(generator):=20=E4=BF=AE=E5=A4=8DContextAwar?= =?UTF-8?q?e=E7=94=9F=E6=88=90=E5=99=A8=E4=BB=A3=E7=A0=81=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=92=8C=E6=B5=8B=E8=AF=95=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除ContextAwareGenerator中多余的空行 - 为生成的类添加IContextAware接口实现 - 在测试中添加IContextAware接口定义 - 修复Rider测试会话配置中的IsActive属性 - 更新测试ID以匹配正确的测试类路径 --- .../rule/ContextAwareGeneratorTests.cs | 10 +++++++++- .../rule/ContextAwareGenerator.cs | 1 - GFramework.sln.DotSettings.user | 6 +++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/GFramework.SourceGenerators.Tests/rule/ContextAwareGeneratorTests.cs b/GFramework.SourceGenerators.Tests/rule/ContextAwareGeneratorTests.cs index ba1b837..49e3f79 100644 --- a/GFramework.SourceGenerators.Tests/rule/ContextAwareGeneratorTests.cs +++ b/GFramework.SourceGenerators.Tests/rule/ContextAwareGeneratorTests.cs @@ -35,13 +35,21 @@ public class ContextAwareGeneratorTests using GFramework.SourceGenerators.Attributes.rule; [ContextAware] - public partial class MyRule + public partial class MyRule: GFramework.Core.rule.IContextAware { } } """; const string frameworkStub = """ + namespace GFramework.Core.rule + { + public interface IContextAware + { + void SetContext(GFramework.Core.architecture.IArchitectureContext context); + } + } + namespace GFramework.Core.architecture { public interface IArchitectureContext {} diff --git a/GFramework.SourceGenerators/rule/ContextAwareGenerator.cs b/GFramework.SourceGenerators/rule/ContextAwareGenerator.cs index 180e823..0124541 100644 --- a/GFramework.SourceGenerators/rule/ContextAwareGenerator.cs +++ b/GFramework.SourceGenerators/rule/ContextAwareGenerator.cs @@ -109,7 +109,6 @@ public sealed class ContextAwareGenerator : IIncrementalGenerator sb.AppendLine("{"); sb.AppendLine( " protected GFramework.Core.architecture.IArchitectureContext Context { get; private set; } = null!;"); - sb.AppendLine(); sb.AppendLine(" void GFramework.Core.rule.IContextAware.SetContext("); sb.AppendLine(" GFramework.Core.architecture.IArchitectureContext context)"); sb.AppendLine(" {"); diff --git a/GFramework.sln.DotSettings.user b/GFramework.sln.DotSettings.user index ed71e26..444ecc6 100644 --- a/GFramework.sln.DotSettings.user +++ b/GFramework.sln.DotSettings.user @@ -5,13 +5,13 @@ ForceIncluded ForceIncluded ForceIncluded - <SessionState ContinuousTestingMode="0" Name="Generates_ContextAware_Code" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> + <SessionState ContinuousTestingMode="0" IsActive="True" Name="Generates_ContextAware_Code" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> <TestAncestor> <TestId>NUnit3x::BB047F43-6AA0-4EA0-8AE9-E6B9784D9E8E::net8.0::GFramework.SourceGenerators.Tests.rule.ContextAwareGeneratorTests</TestId> </TestAncestor> </SessionState> - <SessionState ContinuousTestingMode="0" IsActive="True" Name="Generates_ContextAware_Code" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> + <SessionState ContinuousTestingMode="0" Name="Generates_ContextAware_Code" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> <TestAncestor> - <TestId>NUnit3x::BB047F43-6AA0-4EA0-8AE9-E6B9784D9E8E::net8.0::GFramework.SourceGenerators.Tests.rule.ContextAwareGeneratorTests.Generates_ContextAware_Code</TestId> + <TestId>NUnit3x::BB047F43-6AA0-4EA0-8AE9-E6B9784D9E8E::net8.0::GFramework.SourceGenerators.Tests.rule.ContextAwareGeneratorTests</TestId> </TestAncestor> </SessionState> \ No newline at end of file