File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed
CodeGeneration/Sources/Utils Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -158,21 +158,30 @@ public class CodeGenerationFormat: BasicFormat {
158158 }
159159 formattedChildren = formattedChildren. map { child in
160160 var child = child
161- child. trailingTrivia = Trivia ( pieces: child. trailingTrivia. drop ( while: \. isSpaceOrTab) )
161+
162+ if let firstNonSpaceOrTabIndex = child. trailingTrivia. firstIndex ( where: { !$0. isSpaceOrTab } ) {
163+ if child. trailingTrivia [ firstNonSpaceOrTabIndex] . isNewline {
164+ child. trailingTrivia = Trivia ( pieces: child. trailingTrivia. suffix ( from: firstNonSpaceOrTabIndex) )
165+ }
166+ } else {
167+ child. trailingTrivia = Trivia ( )
168+ }
162169
163170 if !child. startsOnNewline {
164171 child. leadingTrivia = indentedNewline + child. leadingTrivia
165172 }
166173 return child
167174 }
168175 decreaseIndentationLevel ( )
169- if let lastChild = formattedChildren. last {
176+ if let lastChild = formattedChildren. last,
177+ !lastChild. trailingTrivia. contains ( where: \. isNewline)
178+ {
170179 let nextTokenStartsWithNewline =
171180 lastChild. nextToken ( viewMode: . sourceAccurate) ? . leadingTrivia. first? . isNewline ?? false
172181 if !nextTokenStartsWithNewline {
173182 formattedChildren [ formattedChildren. count - 1 ] = lastChild. with (
174183 \. trailingTrivia,
175- indentedNewline
184+ lastChild . trailingTrivia + indentedNewline
176185 )
177186 }
178187 }
You can’t perform that action at this time.
0 commit comments