@@ -98,7 +98,8 @@ struct ObservationDiagnostic: DiagnosticMessage {
9898 var severity : DiagnosticSeverity
9999
100100 init (
101- message: String , diagnosticID: SwiftDiagnostics . MessageID ,
101+ message: String ,
102+ diagnosticID: SwiftDiagnostics . MessageID ,
102103 severity: SwiftDiagnostics . DiagnosticSeverity = . error
103104 ) {
104105 self . message = message
@@ -107,7 +108,10 @@ struct ObservationDiagnostic: DiagnosticMessage {
107108 }
108109
109110 init (
110- message: String , domain: String , id: ID , severity: SwiftDiagnostics . DiagnosticSeverity = . error
111+ message: String ,
112+ domain: String ,
113+ id: ID ,
114+ severity: SwiftDiagnostics . DiagnosticSeverity = . error
111115 ) {
112116 self . message = message
113117 self . diagnosticID = MessageID ( domain: domain, id: id. rawValue)
@@ -117,7 +121,10 @@ struct ObservationDiagnostic: DiagnosticMessage {
117121
118122extension DiagnosticsError {
119123 init < S: SyntaxProtocol > (
120- syntax: S , message: String , domain: String = " Observation " , id: ObservationDiagnostic . ID ,
124+ syntax: S ,
125+ message: String ,
126+ domain: String = " Observation " ,
127+ id: ObservationDiagnostic . ID ,
121128 severity: SwiftDiagnostics . DiagnosticSeverity = . error
122129 ) {
123130 self . init ( diagnostics: [
@@ -158,8 +165,11 @@ extension TokenSyntax {
158165 switch tokenKind {
159166 case . identifier( let identifier) :
160167 return TokenSyntax (
161- . identifier( prefix + identifier) , leadingTrivia: leadingTrivia,
162- trailingTrivia: trailingTrivia, presence: presence)
168+ . identifier( prefix + identifier) ,
169+ leadingTrivia: leadingTrivia,
170+ trailingTrivia: trailingTrivia,
171+ presence: presence
172+ )
163173 default :
164174 return self
165175 }
@@ -183,7 +193,8 @@ extension PatternBindingListSyntax {
183193 initializer: binding. initializer,
184194 accessorBlock: binding. accessorBlock,
185195 trailingComma: binding. trailingComma,
186- trailingTrivia: binding. trailingTrivia)
196+ trailingTrivia: binding. trailingTrivia
197+ )
187198
188199 }
189200 }
@@ -202,8 +213,11 @@ extension VariableDeclSyntax {
202213 attributes: newAttributes,
203214 modifiers: modifiers. privatePrefixed ( prefix) ,
204215 bindingSpecifier: TokenSyntax (
205- bindingSpecifier. tokenKind, leadingTrivia: . space, trailingTrivia: . space,
206- presence: . present) ,
216+ bindingSpecifier. tokenKind,
217+ leadingTrivia: . space,
218+ trailingTrivia: . space,
219+ presence: . present
220+ ) ,
207221 bindings: bindings. privatePrefixed ( prefix) ,
208222 trailingTrivia: trailingTrivia
209223 )
@@ -215,13 +229,38 @@ extension VariableDeclSyntax {
215229}
216230
217231extension ObservableStateMacro : MemberMacro {
218- public static func expansion<
219- Declaration: DeclGroupSyntax ,
220- Context: MacroExpansionContext
221- > (
232+ #if canImport(SwiftSyntax601)
233+ public static func expansion(
234+ of node: AttributeSyntax ,
235+ providingMembersOf declaration: some DeclGroupSyntax ,
236+ conformingTo protocols: [ TypeSyntax ] ,
237+ in context: some MacroExpansionContext
238+ ) throws -> [ DeclSyntax ] {
239+ try _expansion (
240+ of: node,
241+ providingMembersOf: declaration,
242+ conformingTo: protocols,
243+ in: context
244+ )
245+ }
246+ #else
247+ public static func expansion<
248+ Declaration: DeclGroupSyntax ,
249+ Context: MacroExpansionContext
250+ > (
251+ of node: AttributeSyntax ,
252+ providingMembersOf declaration: Declaration ,
253+ in context: Context
254+ ) throws -> [ DeclSyntax ] {
255+ try _expansion ( of: node, providingMembersOf: declaration, conformingTo: [ ] , in: context)
256+ }
257+ #endif
258+
259+ private static func _expansion(
222260 of node: AttributeSyntax ,
223- providingMembersOf declaration: Declaration ,
224- in context: Context
261+ providingMembersOf declaration: some DeclGroupSyntax ,
262+ conformingTo protocols: [ TypeSyntax ] ,
263+ in context: some MacroExpansionContext
225264 ) throws -> [ DeclSyntax ] {
226265 guard !declaration. isEnum
227266 else {
@@ -239,20 +278,24 @@ extension ObservableStateMacro: MemberMacro {
239278 throw DiagnosticsError (
240279 syntax: node,
241280 message: " '@ObservableState' cannot be applied to class type ' \( observableType. text) ' " ,
242- id: . invalidApplication)
281+ id: . invalidApplication
282+ )
243283 }
244284 if declaration. isActor {
245285 // actors cannot yet be supported for their isolation
246286 throw DiagnosticsError (
247287 syntax: node,
248288 message: " '@ObservableState' cannot be applied to actor type ' \( observableType. text) ' " ,
249- id: . invalidApplication)
289+ id: . invalidApplication
290+ )
250291 }
251292
252293 var declarations = [ DeclSyntax] ( )
253294
254295 declaration. addIfNeeded (
255- ObservableStateMacro . registrarVariable ( observableType) , to: & declarations)
296+ ObservableStateMacro . registrarVariable ( observableType) ,
297+ to: & declarations
298+ )
256299 declaration. addIfNeeded ( ObservableStateMacro . idVariable ( ) , to: & declarations)
257300 declaration. addIfNeeded ( ObservableStateMacro . willModifyFunction ( ) , to: & declarations)
258301
@@ -453,14 +496,18 @@ extension ObservableStateMacro: MemberAttributeMacro {
453496 return [
454497 AttributeSyntax (
455498 attributeName: IdentifierTypeSyntax (
456- name: . identifier( ObservableStateMacro . ignoredMacroName) ) )
499+ name: . identifier( ObservableStateMacro . ignoredMacroName)
500+ )
501+ )
457502 ]
458503 }
459504
460505 return [
461506 AttributeSyntax (
462507 attributeName: IdentifierTypeSyntax (
463- name: . identifier( ObservableStateMacro . trackedMacroName) ) )
508+ name: . identifier( ObservableStateMacro . trackedMacroName)
509+ )
510+ )
464511 ]
465512 }
466513}
@@ -606,7 +653,8 @@ extension ObservationStateTrackedMacro: PeerMacro {
606653 }
607654
608655 let storage = DeclSyntax (
609- property. privatePrefixed ( " _ " , addingAttribute: ObservableStateMacro . ignoredAttribute) )
656+ property. privatePrefixed ( " _ " , addingAttribute: ObservableStateMacro . ignoredAttribute)
657+ )
610658 return [ storage]
611659 }
612660}
0 commit comments