Skip to content

Commit 6c53107

Browse files
authored
Merge pull request #3039 from al45tair/eng/PR-148520063
[Windows] Remove extra newlines from diagnostic output.
2 parents 820501e + 660b9a1 commit 6c53107

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

Diff for: Sources/SwiftDiagnostics/DiagnosticsFormatter.swift

+13-5
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,13 @@ public struct DiagnosticsFormatter {
293293
)
294294
)
295295

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

301304
let columnsWithDiagnostics = Set(
302305
annotatedLine.diagnostics.map {
@@ -331,8 +334,13 @@ public struct DiagnosticsFormatter {
331334
}
332335

333336
// Add suffix text.
334-
annotatedSource.append(annotatedLine.suffixText)
335-
if annotatedSource.last != "\n" {
337+
if !annotatedLine.suffixText.isEmpty {
338+
annotatedSource.append(annotatedLine.suffixText)
339+
340+
// See above for an explanation of why we do this
341+
if let last = annotatedSource.last, last.isNewline {
342+
annotatedSource.removeLast()
343+
}
336344
annotatedSource.append("\n")
337345
}
338346
}

0 commit comments

Comments
 (0)