File tree Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Original file line number Diff line number Diff line change 12
12
13
13
import SwiftSyntax
14
14
15
- public struct Diagnostic {
15
+ public struct Diagnostic : CustomDebugStringConvertible {
16
16
/// The message that should be displayed to the user
17
17
public let diagMessage : DiagnosticMessage
18
18
@@ -39,5 +39,15 @@ public struct Diagnostic {
39
39
public func location( converter: SourceLocationConverter ) -> SourceLocation {
40
40
return node. startLocation ( converter: converter)
41
41
}
42
+
43
+ public var debugDescription : String {
44
+ if let root = node. root. as ( SourceFileSyntax . self) {
45
+ let locationConverter = SourceLocationConverter ( file: " " , tree: root)
46
+ let location = location ( converter: locationConverter)
47
+ return " \( location) : \( message) "
48
+ } else {
49
+ return " <unknown>: \( message) "
50
+ }
51
+ }
42
52
}
43
53
Original file line number Diff line number Diff line change @@ -132,14 +132,11 @@ class PrintDiags: ParsableCommand {
132
132
enableBareSlashRegexLiteral: enableBareSlashRegex
133
133
)
134
134
let diags = ParseDiagnosticsGenerator . diagnostics ( for: tree)
135
- let locationConverter = SourceLocationConverter ( file: sourceFile, tree: tree)
136
135
if diags. isEmpty {
137
136
print ( " No diagnostics produced " )
138
137
}
139
138
for diag in diags {
140
- let location = diag. location ( converter: locationConverter)
141
- let message = diag. message
142
- print ( " \( location) : \( message) " )
139
+ print ( " \( diag. debugDescription) " )
143
140
}
144
141
}
145
142
}
You can’t perform that action at this time.
0 commit comments