55// Created by Wes Wickwire on 5/3/25.
66//
77
8+ import Foundation
9+
810public protocol DiagnosticReporter {
9- func report( diagnostic: Diagnostic , source: String , fileName : String )
11+ func report( diagnostic: Diagnostic , source: String , filePath : String )
1012}
1113
1214extension DiagnosticReporter {
13- func report( diagnostics: Diagnostics , source: String , fileName : String ) {
15+ func report( diagnostics: Diagnostics , source: String , filePath : String ) {
1416 for diagnostic in diagnostics. sorted ( by: { $0. location. lowerBound < $1. location. lowerBound } ) {
15- report ( diagnostic: diagnostic, source: source, fileName : fileName )
17+ report ( diagnostic: diagnostic, source: source, filePath : filePath )
1618 }
1719 }
1820}
1921
20- public struct StdoutDiagnosticReporter : DiagnosticReporter {
22+ public final class StdoutDiagnosticReporter : DiagnosticReporter {
2123 private let dontColorize : Bool
24+ private var stderr = FileHandle . standardError
2225
2326 public init ( dontColorize: Bool = false ) {
2427 self . dontColorize = dontColorize
@@ -40,7 +43,8 @@ public struct StdoutDiagnosticReporter: DiagnosticReporter {
4043 dontColorize ? ( " " , " " ) : Self . bold
4144 }
4245
43- public func report( diagnostic: Diagnostic , source: String , fileName: String ) {
46+ public func report( diagnostic: Diagnostic , source: String , filePath: String ) {
47+ let fileName = filePath. split ( separator: " / " ) . last ?? " "
4448 let range = diagnostic. location. range
4549 let start = startOfLine ( index: range. lowerBound, source: source)
4650 // Note: This uses `lowerBound` as well to make sure we only get one line
@@ -59,7 +63,7 @@ public struct StdoutDiagnosticReporter: DiagnosticReporter {
5963 }
6064
6165 print ( """
62- \( fileName) : \( line) : \( column) : \( bold. open) \( color. open) \( diagnostic. level) \( color. close) \( bold. close)
66+ \( fileName) : \( line) : \( column) : \( bold. open) \( color. open) \( diagnostic. level) \( color. close) \( bold. close) :
6367
6468 \( source)
6569 \( indent) \( color. open) \( underline) \( color. close) - \( bold. open) \( diagnostic. message) \( bold. close)
@@ -90,3 +94,22 @@ public struct StdoutDiagnosticReporter: DiagnosticReporter {
9094 return index
9195 }
9296}
97+
98+ public final class XcodeDiagnosticReporter : DiagnosticReporter {
99+ private var stderr = FileHandle . standardError
100+
101+ public init ( ) { }
102+
103+ public func report( diagnostic: Diagnostic , source: String , filePath: String ) {
104+ let line = diagnostic. location. line
105+ let column = diagnostic. location. column
106+ print ( " \( filePath) : \( line) : \( column) : \( diagnostic. level) : \( diagnostic. message) " , to: & stderr)
107+ }
108+ }
109+
110+ extension FileHandle : TextOutputStream {
111+ public func write( _ string: String ) {
112+ let data = Data ( string. utf8)
113+ self . write ( data)
114+ }
115+ }
0 commit comments