@@ -12,7 +12,7 @@ public enum PublishableMacro {
1212
1313 static let attribute : AttributeSyntax = " @Publishable "
1414
15- private static func validate (
15+ private static func validateNode (
1616 _ node: AttributeSyntax ,
1717 attachedTo declaration: some DeclGroupSyntax ,
1818 in context: some MacroExpansionContext
@@ -24,6 +24,23 @@ public enum PublishableMacro {
2424 )
2525 }
2626
27+ if declaration. attributes. contains ( like: ObservableMacro . attribute) {
28+ context. diagnose (
29+ node: declaration,
30+ warningMessage: """
31+ @Publishable macro should be used with macros other than @Observable, \
32+ that supply their own Observable protocol conformance
33+ """ ,
34+ fixIts: [
35+ . replace(
36+ message: MacroExpansionFixItMessage ( " Apply @Relayed macro " ) ,
37+ oldNode: node. attributeName,
38+ newNode: RelayedMacro . attribute. attributeName. withTrivia ( from: node. attributeName)
39+ )
40+ ]
41+ )
42+ }
43+
2744 if declaration. attributes. contains ( like: SwiftDataModelMacro . attribute) {
2845 context. diagnose (
2946 node: declaration,
@@ -32,10 +49,9 @@ public enum PublishableMacro {
3249 but internals of SwiftData are incompatible with custom ObservationRegistrar
3350 """ ,
3451 fixIts: [
35- . replace(
36- message: MacroExpansionFixItMessage ( " Remove @Publishable macro " ) ,
37- oldNode: node,
38- newNode: " \( node. leadingTrivia) " as TokenSyntax
52+ . remove(
53+ message: " Remove @Publishable macro " ,
54+ oldNode: node
3955 )
4056 ]
4157 )
@@ -53,14 +69,14 @@ extension PublishableMacro: MemberMacro {
5369 conformingTo protocols: [ TypeSyntax ] ,
5470 in context: some MacroExpansionContext
5571 ) throws -> [ DeclSyntax ] {
56- let declaration = try validate ( node, attachedTo: declaration, in: context)
57- let properties = try PropertiesParser . parse ( memberBlock : declaration. memberBlock )
72+ let declaration = try validateNode ( node, attachedTo: declaration, in: context)
73+ let properties = try PropertiesParser . parse ( declarationGroup : declaration)
5874 let parameters = try Parameters ( from: node)
5975
6076 let hasPublishableSuperclass = protocols. isEmpty
6177 let trimmedSuperclassType = hasPublishableSuperclass ? declaration. possibleSuperclassType : nil
6278
63- let builderTypes : [ any ClassDeclBuilder ] = [
79+ let builders : [ any ClassDeclBuilder ] = [
6480 PublisherDeclBuilder (
6581 declaration: declaration,
6682 trimmedSuperclassType: trimmedSuperclassType
@@ -79,8 +95,8 @@ extension PublishableMacro: MemberMacro {
7995 )
8096 ]
8197
82- return try builderTypes . flatMap { builderType in
83- try builderType . build ( )
98+ return try builders . flatMap { builder in
99+ try builder . build ( )
84100 }
85101 }
86102}
@@ -98,7 +114,7 @@ extension PublishableMacro: ExtensionMacro {
98114 return [ ]
99115 }
100116
101- let declaration = try validate ( node, attachedTo: declaration, in: context)
117+ let declaration = try validateNode ( node, attachedTo: declaration, in: context)
102118 let parameters = try Parameters ( from: node)
103119
104120 let globalActorIsolation = GlobalActorIsolation . resolved (
@@ -107,15 +123,15 @@ extension PublishableMacro: ExtensionMacro {
107123 )
108124
109125 return [
110- . init (
126+ ExtensionDeclSyntax (
111127 attributes: declaration. availability ?? [ ] ,
112128 extendedType: type,
113- inheritanceClause: . init (
129+ inheritanceClause: InheritanceClauseSyntax (
114130 inheritedTypes: [
115131 InheritedTypeSyntax (
116132 type: AttributedTypeSyntax (
117133 globalActorIsolation: globalActorIsolation,
118- baseType: IdentifierTypeSyntax ( name : " Publishable " )
134+ baseType: " Relay. Publishable"
119135 )
120136 )
121137 ]
0 commit comments