From 9ec33eb03d74e0a718de0702ba25f81b3e970db4 Mon Sep 17 00:00:00 2001 From: Daniel Cazzulino Date: Mon, 29 Jul 2024 19:49:35 -0300 Subject: [PATCH] Decouple Orleans server dependency from base CloudActors We already had a separate assembly for the Orleans server extensions. By moving the grain generator to its own assembly, we can fully decouple the server/hosting interface and types from the bare business logic implemented via cloud actors. The only dependency would be the serializer generation which needs to be based on annotating the actual types, so it's unavoidable. But this is just the abstractions package. --- CloudActors.sln | 8 ++- .../ActorBusOverloadGenerator.cs | 4 +- .../ActorMessageAnalyzer.cs | 0 .../ActorMessageGenerator.cs | 5 +- .../ActorState.sbntxt | 0 .../ActorStateGenerator.cs | 4 +- .../AnalysisExtensions.cs | 66 +++++++++++++++++++ .../CloudActors.CodeAnalysis.csproj} | 0 .../Diagnostics.cs | 30 --------- .../EventSourced.sbntxt | 0 .../EventSourcedGenerator.cs | 4 +- src/CloudActors.CodeAnalysis/Extensions.cs | 10 +++ .../OrleansGenerator.cs | 0 .../PartialAnalyzer.cs | 4 +- .../Properties/launchSettings.json | 0 src/CloudActors.CodeAnaysis/Extensions.cs | 49 -------------- .../CloudActors.CodeFix.csproj | 2 +- .../ActorGrain.sbntxt | 0 .../ActorGrainGenerator.cs | 21 ++++-- .../CloudActors.Orleans.CodeAnalysis.csproj | 45 +++++++++++++ .../CloudActors.Orleans.csproj | 6 +- .../CloudActors.Package.msbuildproj | 3 +- src/TestDomain/TestDomain.csproj | 2 +- src/Tests/Tests.csproj | 3 +- 24 files changed, 164 insertions(+), 102 deletions(-) rename src/{CloudActors.CodeAnaysis => CloudActors.CodeAnalysis}/ActorBusOverloadGenerator.cs (97%) rename src/{CloudActors.CodeAnaysis => CloudActors.CodeAnalysis}/ActorMessageAnalyzer.cs (100%) rename src/{CloudActors.CodeAnaysis => CloudActors.CodeAnalysis}/ActorMessageGenerator.cs (95%) rename src/{CloudActors.CodeAnaysis => CloudActors.CodeAnalysis}/ActorState.sbntxt (100%) rename src/{CloudActors.CodeAnaysis => CloudActors.CodeAnalysis}/ActorStateGenerator.cs (96%) create mode 100644 src/CloudActors.CodeAnalysis/AnalysisExtensions.cs rename src/{CloudActors.CodeAnaysis/CloudActors.CodeAnaysis.csproj => CloudActors.CodeAnalysis/CloudActors.CodeAnalysis.csproj} (100%) rename src/{CloudActors.CodeAnaysis => CloudActors.CodeAnalysis}/Diagnostics.cs (51%) rename src/{CloudActors.CodeAnaysis => CloudActors.CodeAnalysis}/EventSourced.sbntxt (100%) rename src/{CloudActors.CodeAnaysis => CloudActors.CodeAnalysis}/EventSourcedGenerator.cs (93%) create mode 100644 src/CloudActors.CodeAnalysis/Extensions.cs rename src/{CloudActors.CodeAnaysis => CloudActors.CodeAnalysis}/OrleansGenerator.cs (100%) rename src/{CloudActors.CodeAnaysis => CloudActors.CodeAnalysis}/PartialAnalyzer.cs (96%) rename src/{CloudActors.CodeAnaysis => CloudActors.CodeAnalysis}/Properties/launchSettings.json (100%) delete mode 100644 src/CloudActors.CodeAnaysis/Extensions.cs rename src/{CloudActors.CodeAnaysis => CloudActors.Orleans.CodeAnalysis}/ActorGrain.sbntxt (100%) rename src/{CloudActors.CodeAnaysis => CloudActors.Orleans.CodeAnalysis}/ActorGrainGenerator.cs (81%) create mode 100644 src/CloudActors.Orleans.CodeAnalysis/CloudActors.Orleans.CodeAnalysis.csproj diff --git a/CloudActors.sln b/CloudActors.sln index 307c059..0bdd161 100644 --- a/CloudActors.sln +++ b/CloudActors.sln @@ -7,7 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CloudActors", "src\CloudAct EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "src\Tests\Tests.csproj", "{1F95CDB9-4030-4F16-A20D-12AE362D00DB}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CloudActors.CodeAnaysis", "src\CloudActors.CodeAnaysis\CloudActors.CodeAnaysis.csproj", "{A610D1AC-9F46-4CC7-90AC-4B2DFBF4D5C2}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CloudActors.CodeAnalysis", "src\CloudActors.CodeAnalysis\CloudActors.CodeAnalysis.csproj", "{A610D1AC-9F46-4CC7-90AC-4B2DFBF4D5C2}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CloudActors.CodeFix", "src\CloudActors.CodeFix\CloudActors.CodeFix.csproj", "{03D8620C-6745-476A-B097-7C62D076F9A7}" EndProject @@ -26,6 +26,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestDomain", "src\TestDomain\TestDomain.csproj", "{1D75C6E9-C4E9-44D8-B598-3A2D45C25EE6}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CloudActors.Orleans.CodeAnalysis", "src\CloudActors.Orleans.CodeAnalysis\CloudActors.Orleans.CodeAnalysis.csproj", "{68823E7F-269E-4947-8E2B-9905F163C96B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -64,6 +66,10 @@ Global {1D75C6E9-C4E9-44D8-B598-3A2D45C25EE6}.Debug|Any CPU.Build.0 = Debug|Any CPU {1D75C6E9-C4E9-44D8-B598-3A2D45C25EE6}.Release|Any CPU.ActiveCfg = Release|Any CPU {1D75C6E9-C4E9-44D8-B598-3A2D45C25EE6}.Release|Any CPU.Build.0 = Release|Any CPU + {68823E7F-269E-4947-8E2B-9905F163C96B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {68823E7F-269E-4947-8E2B-9905F163C96B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {68823E7F-269E-4947-8E2B-9905F163C96B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {68823E7F-269E-4947-8E2B-9905F163C96B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/CloudActors.CodeAnaysis/ActorBusOverloadGenerator.cs b/src/CloudActors.CodeAnalysis/ActorBusOverloadGenerator.cs similarity index 97% rename from src/CloudActors.CodeAnaysis/ActorBusOverloadGenerator.cs rename to src/CloudActors.CodeAnalysis/ActorBusOverloadGenerator.cs index df8c5e8..0c9b1a6 100644 --- a/src/CloudActors.CodeAnaysis/ActorBusOverloadGenerator.cs +++ b/src/CloudActors.CodeAnalysis/ActorBusOverloadGenerator.cs @@ -1,6 +1,6 @@ using System.Linq; using Microsoft.CodeAnalysis; -using static Devlooped.CloudActors.Diagnostics; +using static Devlooped.CloudActors.AnalysisExtensions; namespace Devlooped.CloudActors; @@ -10,7 +10,7 @@ public class ActorBusOverloadGenerator : IIncrementalGenerator public void Initialize(IncrementalGeneratorInitializationContext context) { var source = context.CompilationProvider.SelectMany((x, _) => x.Assembly.GetAllTypes().OfType()) - .Where(IsActorMessage) + .Where(t => t.IsActorMessage()) .Combine(context.CompilationProvider .Select((c, _) => new { diff --git a/src/CloudActors.CodeAnaysis/ActorMessageAnalyzer.cs b/src/CloudActors.CodeAnalysis/ActorMessageAnalyzer.cs similarity index 100% rename from src/CloudActors.CodeAnaysis/ActorMessageAnalyzer.cs rename to src/CloudActors.CodeAnalysis/ActorMessageAnalyzer.cs diff --git a/src/CloudActors.CodeAnaysis/ActorMessageGenerator.cs b/src/CloudActors.CodeAnalysis/ActorMessageGenerator.cs similarity index 95% rename from src/CloudActors.CodeAnaysis/ActorMessageGenerator.cs rename to src/CloudActors.CodeAnalysis/ActorMessageGenerator.cs index 49e0cd5..0c2d5f6 100644 --- a/src/CloudActors.CodeAnaysis/ActorMessageGenerator.cs +++ b/src/CloudActors.CodeAnalysis/ActorMessageGenerator.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using System.Linq; using Microsoft.CodeAnalysis; -using static Devlooped.CloudActors.Diagnostics; namespace Devlooped.CloudActors; @@ -13,7 +12,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context) var options = context.GetOrleansOptions(); var messages = context.CompilationProvider .SelectMany((x, _) => x.Assembly.GetAllTypes().OfType()) - .Where(IsActorMessage) + .Where(t => t.IsActorMessage()) .Where(t => t.IsPartial()); var additionalTypes = messages.SelectMany((x, _) => @@ -31,7 +30,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context) .Select(p => p.Type) .OfType())) // We already generate separately for actor messages. - .Where(t => !IsActorMessage(t) && t.IsPartial()) + .Where(t => !t.IsActorMessage() && t.IsPartial()) .Collect(); context.RegisterImplementationSourceOutput(messages.Combine(options), GenerateCode); diff --git a/src/CloudActors.CodeAnaysis/ActorState.sbntxt b/src/CloudActors.CodeAnalysis/ActorState.sbntxt similarity index 100% rename from src/CloudActors.CodeAnaysis/ActorState.sbntxt rename to src/CloudActors.CodeAnalysis/ActorState.sbntxt diff --git a/src/CloudActors.CodeAnaysis/ActorStateGenerator.cs b/src/CloudActors.CodeAnalysis/ActorStateGenerator.cs similarity index 96% rename from src/CloudActors.CodeAnaysis/ActorStateGenerator.cs rename to src/CloudActors.CodeAnalysis/ActorStateGenerator.cs index 7243465..8b86247 100644 --- a/src/CloudActors.CodeAnaysis/ActorStateGenerator.cs +++ b/src/CloudActors.CodeAnalysis/ActorStateGenerator.cs @@ -3,7 +3,7 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Scriban; -using static Devlooped.CloudActors.Diagnostics; +using static Devlooped.CloudActors.AnalysisExtensions; namespace Devlooped.CloudActors; @@ -22,7 +22,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context) var actors = context.CompilationProvider .SelectMany((x, _) => x.Assembly.GetAllTypes().OfType()) - .Where(x => x.GetAttributes().Any(IsActor)); + .Where(x => x.GetAttributes().Any(x => x.IsActor())); context.RegisterImplementationSourceOutput(actors.Combine(options), (ctx, source) => { diff --git a/src/CloudActors.CodeAnalysis/AnalysisExtensions.cs b/src/CloudActors.CodeAnalysis/AnalysisExtensions.cs new file mode 100644 index 0000000..dc2e55e --- /dev/null +++ b/src/CloudActors.CodeAnalysis/AnalysisExtensions.cs @@ -0,0 +1,66 @@ +using System.Collections.Generic; +using System.Linq; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; + +namespace Devlooped.CloudActors; + +public static class AnalysisExtensions +{ + public static SymbolDisplayFormat FullName { get; } = new( + typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, + genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters, + miscellaneousOptions: SymbolDisplayMiscellaneousOptions.ExpandNullable); + + public static IEnumerable GetAllTypes(this IAssemblySymbol assembly) + => GetAllTypes(assembly.GlobalNamespace); + + static IEnumerable GetAllTypes(INamespaceSymbol namespaceSymbol) + { + foreach (var typeSymbol in namespaceSymbol.GetTypeMembers()) + { + yield return typeSymbol; + } + + foreach (var childNamespace in namespaceSymbol.GetNamespaceMembers()) + { + foreach (var typeSymbol in GetAllTypes(childNamespace)) + { + yield return typeSymbol; + } + } + } + + public static string GetTypeName(this ITypeSymbol type, string containingNamespace) + { + var typeName = type.ToDisplayString(FullName); + if (typeName.StartsWith(containingNamespace + ".")) + return typeName.Substring(containingNamespace.Length + 1); + + return typeName; + } + + public static string ToFileName(this ITypeSymbol type) => type.ToDisplayString(FullName).Replace('+', '.'); + + public static bool IsActorMessage(this ITypeSymbol type) => type.AllInterfaces.Any(x => + x.ToDisplayString(FullName).Equals("Devlooped.CloudActors.IActorMessage")); + + public static bool IsActorCommand(this ITypeSymbol type) => type.AllInterfaces.Any(x => + x.ToDisplayString(FullName).StartsWith("Devlooped.CloudActors.IActorCommand") && x.IsGenericType); + + public static bool IsActorVoidCommand(this ITypeSymbol type) => type.AllInterfaces.Any(x => + x.ToDisplayString(FullName).StartsWith("Devlooped.CloudActors.IActorCommand") && !x.IsGenericType); + + public static bool IsActorQuery(this ITypeSymbol type) => type.AllInterfaces.Any(x => + x.ToDisplayString(FullName).StartsWith("Devlooped.CloudActors.IActorQuery") && x.IsGenericType); + + public static bool IsActor(this ITypeSymbol type) => type.GetAttributes().Any(a => a.IsActor()); + + public static bool IsActor(this AttributeData attr) => + attr.AttributeClass?.ToDisplayString(FullName) == "Devlooped.CloudActors.ActorAttribute"; + + public static bool IsPartial(this ITypeSymbol node) => node.DeclaringSyntaxReferences.Any( + r => r.GetSyntax() is TypeDeclarationSyntax { Modifiers: { } modifiers } && + modifiers.Any(m => m.IsKind(SyntaxKind.PartialKeyword))); +} diff --git a/src/CloudActors.CodeAnaysis/CloudActors.CodeAnaysis.csproj b/src/CloudActors.CodeAnalysis/CloudActors.CodeAnalysis.csproj similarity index 100% rename from src/CloudActors.CodeAnaysis/CloudActors.CodeAnaysis.csproj rename to src/CloudActors.CodeAnalysis/CloudActors.CodeAnalysis.csproj diff --git a/src/CloudActors.CodeAnaysis/Diagnostics.cs b/src/CloudActors.CodeAnalysis/Diagnostics.cs similarity index 51% rename from src/CloudActors.CodeAnaysis/Diagnostics.cs rename to src/CloudActors.CodeAnalysis/Diagnostics.cs index 3f933c1..a56a8dc 100644 --- a/src/CloudActors.CodeAnaysis/Diagnostics.cs +++ b/src/CloudActors.CodeAnalysis/Diagnostics.cs @@ -50,34 +50,4 @@ public static class Diagnostics "Build", DiagnosticSeverity.Error, isEnabledByDefault: true); - - public static SymbolDisplayFormat FullName { get; } = new( - typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, - genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters, - miscellaneousOptions: SymbolDisplayMiscellaneousOptions.ExpandNullable); - - public static string ToFileName(this ITypeSymbol type) => type.ToDisplayString(FullName).Replace('+', '.'); - - public static bool IsActorMessage(ITypeSymbol type) => type.AllInterfaces.Any(x => - x.ToDisplayString(FullName).Equals("Devlooped.CloudActors.IActorMessage")); - - public static bool IsActorCommand(this ITypeSymbol type) => type.AllInterfaces.Any(x => - x.ToDisplayString(FullName).StartsWith("Devlooped.CloudActors.IActorCommand") && x.IsGenericType); - - public static bool IsActorVoidCommand(this ITypeSymbol type) => type.AllInterfaces.Any(x => - x.ToDisplayString(FullName).StartsWith("Devlooped.CloudActors.IActorCommand") && !x.IsGenericType); - - public static bool IsActorQuery(this ITypeSymbol type) => type.AllInterfaces.Any(x => - x.ToDisplayString(FullName).StartsWith("Devlooped.CloudActors.IActorQuery") && x.IsGenericType); - - public static bool IsActor(AttributeData attr) => - attr.AttributeClass?.ToDisplayString(FullName) == "Devlooped.CloudActors.ActorAttribute"; - - public static bool IsPartial(ITypeSymbol node) => - node.DeclaringSyntaxReferences.Any(r => - r.GetSyntax() is ClassDeclarationSyntax { Modifiers: { } modifiers } && - modifiers.Any(m => m.IsKind(SyntaxKind.PartialKeyword))) || - node.DeclaringSyntaxReferences.Any(r => - r.GetSyntax() is RecordDeclarationSyntax { Modifiers: { } modifiers } && - modifiers.Any(m => m.IsKind(SyntaxKind.PartialKeyword))); } diff --git a/src/CloudActors.CodeAnaysis/EventSourced.sbntxt b/src/CloudActors.CodeAnalysis/EventSourced.sbntxt similarity index 100% rename from src/CloudActors.CodeAnaysis/EventSourced.sbntxt rename to src/CloudActors.CodeAnalysis/EventSourced.sbntxt diff --git a/src/CloudActors.CodeAnaysis/EventSourcedGenerator.cs b/src/CloudActors.CodeAnalysis/EventSourcedGenerator.cs similarity index 93% rename from src/CloudActors.CodeAnaysis/EventSourcedGenerator.cs rename to src/CloudActors.CodeAnalysis/EventSourcedGenerator.cs index 29c1e2d..adfa626 100644 --- a/src/CloudActors.CodeAnaysis/EventSourcedGenerator.cs +++ b/src/CloudActors.CodeAnalysis/EventSourcedGenerator.cs @@ -6,7 +6,7 @@ using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Scriban; -using static Devlooped.CloudActors.Diagnostics; +using static Devlooped.CloudActors.AnalysisExtensions; namespace Devlooped.CloudActors; @@ -18,7 +18,7 @@ public class EventSourcedGenerator : IIncrementalGenerator public void Initialize(IncrementalGeneratorInitializationContext context) { var actors = context.CompilationProvider.SelectMany((x, _) => x.Assembly.GetAllTypes().OfType()) - .Where(x => x.GetAttributes().Any(IsActor) && x.AllInterfaces.Any(i => i.ToDisplayString(FullName) == "Devlooped.CloudActors.IEventSourced")) + .Where(x => x.GetAttributes().Any(a => a.IsActor()) && x.AllInterfaces.Any(i => i.ToDisplayString(FullName) == "Devlooped.CloudActors.IEventSourced")) .Combine(context.CompilationProvider.Select((c, _) => c.GetTypeByMetadataName("Devlooped.CloudActors.IEventSourced"))) .Where(x => x.Right != null && !x.Right // Only if users haven't already implemented *any* members of the interface diff --git a/src/CloudActors.CodeAnalysis/Extensions.cs b/src/CloudActors.CodeAnalysis/Extensions.cs new file mode 100644 index 0000000..7c7bc9f --- /dev/null +++ b/src/CloudActors.CodeAnalysis/Extensions.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; + +namespace Devlooped.CloudActors; + +static class Extensions +{ +} diff --git a/src/CloudActors.CodeAnaysis/OrleansGenerator.cs b/src/CloudActors.CodeAnalysis/OrleansGenerator.cs similarity index 100% rename from src/CloudActors.CodeAnaysis/OrleansGenerator.cs rename to src/CloudActors.CodeAnalysis/OrleansGenerator.cs diff --git a/src/CloudActors.CodeAnaysis/PartialAnalyzer.cs b/src/CloudActors.CodeAnalysis/PartialAnalyzer.cs similarity index 96% rename from src/CloudActors.CodeAnaysis/PartialAnalyzer.cs rename to src/CloudActors.CodeAnalysis/PartialAnalyzer.cs index 036edc4..f0fc71b 100644 --- a/src/CloudActors.CodeAnaysis/PartialAnalyzer.cs +++ b/src/CloudActors.CodeAnalysis/PartialAnalyzer.cs @@ -33,7 +33,7 @@ static void Analyze(SyntaxNodeAnalysisContext context) return; // Only require this for actor and message types - if (!symbol.GetAttributes().Any(IsActor) && + if (!symbol.GetAttributes().Any(x => x.IsActor()) && // symbol implements IActorMessage !symbol.AllInterfaces.Contains(messageType, SymbolEqualityComparer.Default)) return; @@ -69,7 +69,7 @@ static void Analyze(CompilationAnalysisContext context) // where the type is not partial //.Where(t => !t.GetAttributes().Any(a => generateAttr.Equals(a.AttributeClass, SymbolEqualityComparer.Default))), .Where(t => - !t.GetAttributes().Any(IsActor) && + !t.GetAttributes().Any(x => x.IsActor()) && !t.AllInterfaces.Contains(messageType, SymbolEqualityComparer.Default) && !t.IsPartial() && t.Locations.Any(l => l.IsInSource)), diff --git a/src/CloudActors.CodeAnaysis/Properties/launchSettings.json b/src/CloudActors.CodeAnalysis/Properties/launchSettings.json similarity index 100% rename from src/CloudActors.CodeAnaysis/Properties/launchSettings.json rename to src/CloudActors.CodeAnalysis/Properties/launchSettings.json diff --git a/src/CloudActors.CodeAnaysis/Extensions.cs b/src/CloudActors.CodeAnaysis/Extensions.cs deleted file mode 100644 index 972841e..0000000 --- a/src/CloudActors.CodeAnaysis/Extensions.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System.Collections.Generic; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.CSharp.Syntax; - -namespace Devlooped.CloudActors; - -static class Extensions -{ - public static IEnumerable GetAllTypes(this IAssemblySymbol assembly) - => GetAllTypes(assembly.GlobalNamespace); - - static IEnumerable GetAllTypes(INamespaceSymbol namespaceSymbol) - { - foreach (var typeSymbol in namespaceSymbol.GetTypeMembers()) - { - yield return typeSymbol; - } - - foreach (var childNamespace in namespaceSymbol.GetNamespaceMembers()) - { - foreach (var typeSymbol in GetAllTypes(childNamespace)) - { - yield return typeSymbol; - } - } - } - - public static string GetTypeName(this ITypeSymbol type, string containingNamespace) - { - var typeName = type.ToDisplayString(Diagnostics.FullName); - if (typeName.StartsWith(containingNamespace + ".")) - return typeName.Substring(containingNamespace.Length + 1); - - return typeName; - } - - public static bool IsPartial(this INamedTypeSymbol type) - { - foreach (var syntax in type.DeclaringSyntaxReferences) - { - if (syntax.GetSyntax() is TypeDeclarationSyntax typeDeclarationSyntax && - typeDeclarationSyntax.Modifiers.Any(SyntaxKind.PartialKeyword)) - return true; - } - - return false; - } -} diff --git a/src/CloudActors.CodeFix/CloudActors.CodeFix.csproj b/src/CloudActors.CodeFix/CloudActors.CodeFix.csproj index 49b7693..491897a 100644 --- a/src/CloudActors.CodeFix/CloudActors.CodeFix.csproj +++ b/src/CloudActors.CodeFix/CloudActors.CodeFix.csproj @@ -18,7 +18,7 @@ - + diff --git a/src/CloudActors.CodeAnaysis/ActorGrain.sbntxt b/src/CloudActors.Orleans.CodeAnalysis/ActorGrain.sbntxt similarity index 100% rename from src/CloudActors.CodeAnaysis/ActorGrain.sbntxt rename to src/CloudActors.Orleans.CodeAnalysis/ActorGrain.sbntxt diff --git a/src/CloudActors.CodeAnaysis/ActorGrainGenerator.cs b/src/CloudActors.Orleans.CodeAnalysis/ActorGrainGenerator.cs similarity index 81% rename from src/CloudActors.CodeAnaysis/ActorGrainGenerator.cs rename to src/CloudActors.Orleans.CodeAnalysis/ActorGrainGenerator.cs index 59e0961..e7c13d7 100644 --- a/src/CloudActors.CodeAnaysis/ActorGrainGenerator.cs +++ b/src/CloudActors.Orleans.CodeAnalysis/ActorGrainGenerator.cs @@ -1,8 +1,9 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using Microsoft.CodeAnalysis; using Scriban; -using static Devlooped.CloudActors.Diagnostics; +using static Devlooped.CloudActors.AnalysisExtensions; namespace Devlooped.CloudActors; @@ -16,14 +17,24 @@ public void Initialize(IncrementalGeneratorInitializationContext context) var options = context.GetOrleansOptions(); var actors = context.CompilationProvider - .SelectMany((x, _) => x.Assembly.GetAllTypes().OfType()) - .Where(x => x.GetAttributes().Any(IsActor)); + .SelectMany((x, _) => x.Assembly + .GetAllTypes() + .OfType() + .Where(t => t.IsActor()) + .Concat(x.GetUsedAssemblyReferences() + .SelectMany(r => + { + if (x.GetAssemblyOrModuleSymbol(r) is IAssemblySymbol asm) + return asm.GetAllTypes().OfType().Where(t => t.IsActor()); + + return []; + }))); context.RegisterImplementationSourceOutput(actors.Combine(options), (ctx, source) => { var (actor, options) = source; - var attribute = actor.GetAttributes().First(IsActor); + var attribute = actor.GetAttributes().First(x => x.IsActor()); var state = default(string); var storage = default(string); if (attribute.ConstructorArguments.Length >= 1) diff --git a/src/CloudActors.Orleans.CodeAnalysis/CloudActors.Orleans.CodeAnalysis.csproj b/src/CloudActors.Orleans.CodeAnalysis/CloudActors.Orleans.CodeAnalysis.csproj new file mode 100644 index 0000000..1873529 --- /dev/null +++ b/src/CloudActors.Orleans.CodeAnalysis/CloudActors.Orleans.CodeAnalysis.csproj @@ -0,0 +1,45 @@ + + + + Devlooped.CloudActors.Orleans.CodeAnalysis + netstandard2.0 + + true + + RS1036;CS8785 + + analyzers/dotnet/roslyn4.5/cs + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/CloudActors.Orleans/CloudActors.Orleans.csproj b/src/CloudActors.Orleans/CloudActors.Orleans.csproj index e01c8b5..44bb4a2 100644 --- a/src/CloudActors.Orleans/CloudActors.Orleans.csproj +++ b/src/CloudActors.Orleans/CloudActors.Orleans.csproj @@ -1,8 +1,11 @@ - Devlooped.CloudActors.Orleans + Devlooped.CloudActors.Server net8.0 + $(AssemblyName) + Cloud Native Actors Server/Hosting + dotnet orleans actor server @@ -12,6 +15,7 @@ + diff --git a/src/CloudActors.Package/CloudActors.Package.msbuildproj b/src/CloudActors.Package/CloudActors.Package.msbuildproj index 127a3b0..514041b 100644 --- a/src/CloudActors.Package/CloudActors.Package.msbuildproj +++ b/src/CloudActors.Package/CloudActors.Package.msbuildproj @@ -9,9 +9,8 @@ - + - \ No newline at end of file diff --git a/src/TestDomain/TestDomain.csproj b/src/TestDomain/TestDomain.csproj index 20bd4e3..bee3ca9 100644 --- a/src/TestDomain/TestDomain.csproj +++ b/src/TestDomain/TestDomain.csproj @@ -12,7 +12,7 @@ - + diff --git a/src/Tests/Tests.csproj b/src/Tests/Tests.csproj index e87f34e..15a6032 100644 --- a/src/Tests/Tests.csproj +++ b/src/Tests/Tests.csproj @@ -31,8 +31,9 @@ - + +