@@ -298,23 +298,20 @@ fileprivate func generateLines(codeBlockItemList: CodeBlockItemListSyntax, conte
298298 }
299299
300300 for block in codeBlockItemList {
301-
302- if let leadingTrivia = block. leadingTrivia {
303- afterNewline = false
304-
305- for piece in leadingTrivia {
306- switch piece {
307- // Create new Line objects when we encounter newlines.
308- case . newlines( let N) :
309- for _ in 0 ..< N {
310- appendNewLine ( )
311- }
312- default :
313- if afterNewline || isFirstBlock {
314- currentLine. leadingTrivia. append ( piece) // This will be a standalone comment.
315- } else {
316- currentLine. trailingTrivia. append ( piece) // This will be a trailing line comment.
317- }
301+ afterNewline = false
302+
303+ for piece in block. leadingTrivia {
304+ switch piece {
305+ // Create new Line objects when we encounter newlines.
306+ case . newlines( let N) :
307+ for _ in 0 ..< N {
308+ appendNewLine ( )
309+ }
310+ default :
311+ if afterNewline || isFirstBlock {
312+ currentLine. leadingTrivia. append ( piece) // This will be a standalone comment.
313+ } else {
314+ currentLine. trailingTrivia. append ( piece) // This will be a trailing line comment.
318315 }
319316 }
320317 }
@@ -491,8 +488,7 @@ fileprivate class Line {
491488 // description includes all leading and trailing trivia. It would be unusual to have any
492489 // non-whitespace trivia on the components of the import. Trim off the leading trivia, where
493490 // comments could be, and trim whitespace that might be after the import.
494- let leadingText = importDecl. leadingTrivia? . reduce ( into: " " ) { $1. write ( to: & $0) } ?? " "
495- return importDecl. description. dropFirst ( leadingText. count)
491+ return importDecl. with ( \. leadingTrivia, [ ] ) . description
496492 . trimmingCharacters ( in: . whitespacesAndNewlines)
497493 }
498494
0 commit comments