@@ -98,7 +98,8 @@ struct ObservationDiagnostic: DiagnosticMessage {
98
98
var severity : DiagnosticSeverity
99
99
100
100
init (
101
- message: String , diagnosticID: SwiftDiagnostics . MessageID ,
101
+ message: String ,
102
+ diagnosticID: SwiftDiagnostics . MessageID ,
102
103
severity: SwiftDiagnostics . DiagnosticSeverity = . error
103
104
) {
104
105
self . message = message
@@ -107,7 +108,10 @@ struct ObservationDiagnostic: DiagnosticMessage {
107
108
}
108
109
109
110
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
111
115
) {
112
116
self . message = message
113
117
self . diagnosticID = MessageID ( domain: domain, id: id. rawValue)
@@ -117,7 +121,10 @@ struct ObservationDiagnostic: DiagnosticMessage {
117
121
118
122
extension DiagnosticsError {
119
123
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 ,
121
128
severity: SwiftDiagnostics . DiagnosticSeverity = . error
122
129
) {
123
130
self . init ( diagnostics: [
@@ -158,8 +165,11 @@ extension TokenSyntax {
158
165
switch tokenKind {
159
166
case . identifier( let identifier) :
160
167
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
+ )
163
173
default :
164
174
return self
165
175
}
@@ -183,7 +193,8 @@ extension PatternBindingListSyntax {
183
193
initializer: binding. initializer,
184
194
accessorBlock: binding. accessorBlock,
185
195
trailingComma: binding. trailingComma,
186
- trailingTrivia: binding. trailingTrivia)
196
+ trailingTrivia: binding. trailingTrivia
197
+ )
187
198
188
199
}
189
200
}
@@ -202,8 +213,11 @@ extension VariableDeclSyntax {
202
213
attributes: newAttributes,
203
214
modifiers: modifiers. privatePrefixed ( prefix) ,
204
215
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
+ ) ,
207
221
bindings: bindings. privatePrefixed ( prefix) ,
208
222
trailingTrivia: trailingTrivia
209
223
)
@@ -215,13 +229,38 @@ extension VariableDeclSyntax {
215
229
}
216
230
217
231
extension 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(
222
260
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
225
264
) throws -> [ DeclSyntax ] {
226
265
guard !declaration. isEnum
227
266
else {
@@ -239,20 +278,24 @@ extension ObservableStateMacro: MemberMacro {
239
278
throw DiagnosticsError (
240
279
syntax: node,
241
280
message: " '@ObservableState' cannot be applied to class type ' \( observableType. text) ' " ,
242
- id: . invalidApplication)
281
+ id: . invalidApplication
282
+ )
243
283
}
244
284
if declaration. isActor {
245
285
// actors cannot yet be supported for their isolation
246
286
throw DiagnosticsError (
247
287
syntax: node,
248
288
message: " '@ObservableState' cannot be applied to actor type ' \( observableType. text) ' " ,
249
- id: . invalidApplication)
289
+ id: . invalidApplication
290
+ )
250
291
}
251
292
252
293
var declarations = [ DeclSyntax] ( )
253
294
254
295
declaration. addIfNeeded (
255
- ObservableStateMacro . registrarVariable ( observableType) , to: & declarations)
296
+ ObservableStateMacro . registrarVariable ( observableType) ,
297
+ to: & declarations
298
+ )
256
299
declaration. addIfNeeded ( ObservableStateMacro . idVariable ( ) , to: & declarations)
257
300
declaration. addIfNeeded ( ObservableStateMacro . willModifyFunction ( ) , to: & declarations)
258
301
@@ -453,14 +496,18 @@ extension ObservableStateMacro: MemberAttributeMacro {
453
496
return [
454
497
AttributeSyntax (
455
498
attributeName: IdentifierTypeSyntax (
456
- name: . identifier( ObservableStateMacro . ignoredMacroName) ) )
499
+ name: . identifier( ObservableStateMacro . ignoredMacroName)
500
+ )
501
+ )
457
502
]
458
503
}
459
504
460
505
return [
461
506
AttributeSyntax (
462
507
attributeName: IdentifierTypeSyntax (
463
- name: . identifier( ObservableStateMacro . trackedMacroName) ) )
508
+ name: . identifier( ObservableStateMacro . trackedMacroName)
509
+ )
510
+ )
464
511
]
465
512
}
466
513
}
@@ -606,7 +653,8 @@ extension ObservationStateTrackedMacro: PeerMacro {
606
653
}
607
654
608
655
let storage = DeclSyntax (
609
- property. privatePrefixed ( " _ " , addingAttribute: ObservableStateMacro . ignoredAttribute) )
656
+ property. privatePrefixed ( " _ " , addingAttribute: ObservableStateMacro . ignoredAttribute)
657
+ )
610
658
return [ storage]
611
659
}
612
660
}
0 commit comments