@@ -92,7 +92,7 @@ public func expandFreestandingMacro(
92
92
macroRole: MacroRole ,
93
93
node: FreestandingMacroExpansionSyntax ,
94
94
in context: some MacroExpansionContext ,
95
- indentationWidth: Trivia = . spaces ( 4 )
95
+ indentationWidth: Trivia ? = nil
96
96
) -> String ? {
97
97
do {
98
98
let expandedSyntax : Syntax
@@ -192,7 +192,7 @@ public func expandAttachedMacroWithoutCollapsing<Context: MacroExpansionContext>
192
192
extendedType: TypeSyntax ? ,
193
193
conformanceList: InheritedTypeListSyntax ? ,
194
194
in context: Context ,
195
- indentationWidth: Trivia = . spaces ( 4 )
195
+ indentationWidth: Trivia ? = nil
196
196
) -> [ String ] ? {
197
197
do {
198
198
switch ( definition, macroRole) {
@@ -320,7 +320,7 @@ public func expandAttachedMacro<Context: MacroExpansionContext>(
320
320
extendedType: TypeSyntax ? ,
321
321
conformanceList: InheritedTypeListSyntax ? ,
322
322
in context: Context ,
323
- indentationWidth: Trivia = . spaces ( 4 )
323
+ indentationWidth: Trivia ? = nil
324
324
) -> String ? {
325
325
let expandedSources = expandAttachedMacroWithoutCollapsing (
326
326
definition: definition,
@@ -341,7 +341,7 @@ public func expandAttachedMacro<Context: MacroExpansionContext>(
341
341
fileprivate extension SyntaxProtocol {
342
342
/// Perform a format if required and then trim any leading/trailing
343
343
/// whitespace.
344
- func formattedExpansion( _ mode: FormatMode , indentationWidth: Trivia ) -> String {
344
+ func formattedExpansion( _ mode: FormatMode , indentationWidth: Trivia ? ) -> String {
345
345
let formatted : Syntax
346
346
switch mode {
347
347
case . auto:
@@ -396,7 +396,7 @@ public func collapse<Node: SyntaxProtocol>(
396
396
expansions: [ String ] ,
397
397
for role: MacroRole ,
398
398
attachedTo declarationNode: Node ,
399
- indentationWidth: Trivia = . spaces ( 4 )
399
+ indentationWidth: Trivia ? = nil
400
400
) -> String {
401
401
if expansions. isEmpty {
402
402
return " "
@@ -421,7 +421,10 @@ public func collapse<Node: SyntaxProtocol>(
421
421
onDeclarationWithoutAccessor = false
422
422
}
423
423
if onDeclarationWithoutAccessor {
424
- expansions = expansions. map ( { $0. indented ( by: indentationWidth) } )
424
+ // Default to 4 spaces if no indentation was passed.
425
+ // In the future, we could consider inferring the indentation width from
426
+ // the expansions to collapse.
427
+ expansions = expansions. map ( { $0. indented ( by: indentationWidth ?? . spaces( 4 ) ) } )
425
428
expansions [ 0 ] = " { \n " + expansions[ 0 ]
426
429
expansions [ expansions. count - 1 ] += " \n } "
427
430
}
0 commit comments