Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions Sources/SwiftDiagnostics/DiagnosticsFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,13 @@ public struct DiagnosticsFormatter {
)
)

// If the line did not end with \n (e.g. the last line), append it manually
if annotatedSource.last != "\n" {
annotatedSource.append("\n")
// Remove any trailing newline and replace it; this may seem
// counterintuitive, but if we're running within CMake and we let a
// '\r\n' through, CMake will turn that into *two* newlines.
if let last = annotatedSource.last, last.isNewline {
annotatedSource.removeLast()
}
annotatedSource.append("\n")

let columnsWithDiagnostics = Set(
annotatedLine.diagnostics.map {
Expand Down Expand Up @@ -331,8 +334,13 @@ public struct DiagnosticsFormatter {
}

// Add suffix text.
annotatedSource.append(annotatedLine.suffixText)
if annotatedSource.last != "\n" {
if !annotatedLine.suffixText.isEmpty {
annotatedSource.append(annotatedLine.suffixText)

// See above for an explanation of why we do this
if let last = annotatedSource.last, last.isNewline {
annotatedSource.removeLast()
}
annotatedSource.append("\n")
}
}
Expand Down