Skip to content

[Windows] Remove extra newlines from diagnostic output. #3039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 6, 2025
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