File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments