@@ -13,7 +13,7 @@ import SwiftSyntaxMacros
1313/// `@Entity` macro
1414///
1515/// Adds protocol conformance and implementaion for entity name.
16- public struct EntityMacro : MemberMacro {
16+ public struct EntityMacro : MemberMacro , ExtensionMacro {
1717
1818 public static var expansionNames : [ String ] {
1919 [
@@ -23,6 +23,34 @@ public struct EntityMacro: MemberMacro {
2323 ]
2424 }
2525
26+ // Add protocol conformance via extension
27+ public static func expansion(
28+ of node: AttributeSyntax ,
29+ attachedTo declaration: some DeclGroupSyntax ,
30+ providingExtensionsOf type: some TypeSyntaxProtocol ,
31+ conformingTo protocols: [ TypeSyntax ] ,
32+ in context: some MacroExpansionContext
33+ ) throws -> [ ExtensionDeclSyntax ] {
34+ let extensionDecl = ExtensionDeclSyntax (
35+ leadingTrivia: nil ,
36+ attributes: [ ] ,
37+ modifiers: [ ] ,
38+ extensionKeyword: . keyword( . extension) ,
39+ extendedType: TypeSyntax ( type) ,
40+ inheritanceClause: InheritanceClauseSyntax (
41+ colon: . colonToken( trailingTrivia: . space) ,
42+ inheritedTypes: InheritedTypeListSyntax {
43+ InheritedTypeSyntax (
44+ type: TypeSyntax ( stringLiteral: " CoreModel.Entity " )
45+ )
46+ }
47+ ) ,
48+ genericWhereClause: nil ,
49+ memberBlock: MemberBlockSyntax ( members: [ ] )
50+ )
51+ return [ extensionDecl]
52+ }
53+
2654 public static func expansion(
2755 of node: AttributeSyntax ,
2856 providingMembersOf declaration: some DeclGroupSyntax ,
0 commit comments