@@ -92,7 +92,7 @@ public func expandFreestandingMacro(
9292 macroRole: MacroRole ,
9393 node: FreestandingMacroExpansionSyntax ,
9494 in context: some MacroExpansionContext ,
95- indentationWidth: Trivia = . spaces ( 4 )
95+ indentationWidth: Trivia ? = nil
9696) -> String ? {
9797 do {
9898 let expandedSyntax : Syntax
@@ -192,7 +192,7 @@ public func expandAttachedMacroWithoutCollapsing<Context: MacroExpansionContext>
192192 extendedType: TypeSyntax ? ,
193193 conformanceList: InheritedTypeListSyntax ? ,
194194 in context: Context ,
195- indentationWidth: Trivia = . spaces ( 4 )
195+ indentationWidth: Trivia ? = nil
196196) -> [ String ] ? {
197197 do {
198198 switch ( definition, macroRole) {
@@ -320,7 +320,7 @@ public func expandAttachedMacro<Context: MacroExpansionContext>(
320320 extendedType: TypeSyntax ? ,
321321 conformanceList: InheritedTypeListSyntax ? ,
322322 in context: Context ,
323- indentationWidth: Trivia = . spaces ( 4 )
323+ indentationWidth: Trivia ? = nil
324324) -> String ? {
325325 let expandedSources = expandAttachedMacroWithoutCollapsing (
326326 definition: definition,
@@ -341,7 +341,7 @@ public func expandAttachedMacro<Context: MacroExpansionContext>(
341341fileprivate extension SyntaxProtocol {
342342 /// Perform a format if required and then trim any leading/trailing
343343 /// whitespace.
344- func formattedExpansion( _ mode: FormatMode , indentationWidth: Trivia ) -> String {
344+ func formattedExpansion( _ mode: FormatMode , indentationWidth: Trivia ? ) -> String {
345345 let formatted : Syntax
346346 switch mode {
347347 case . auto:
@@ -396,7 +396,7 @@ public func collapse<Node: SyntaxProtocol>(
396396 expansions: [ String ] ,
397397 for role: MacroRole ,
398398 attachedTo declarationNode: Node ,
399- indentationWidth: Trivia = . spaces ( 4 )
399+ indentationWidth: Trivia ? = nil
400400) -> String {
401401 if expansions. isEmpty {
402402 return " "
@@ -421,7 +421,10 @@ public func collapse<Node: SyntaxProtocol>(
421421 onDeclarationWithoutAccessor = false
422422 }
423423 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 ) ) } )
425428 expansions [ 0 ] = " { \n " + expansions[ 0 ]
426429 expansions [ expansions. count - 1 ] += " \n } "
427430 }
0 commit comments