@@ -99,16 +99,16 @@ public protocol SyntaxExpressibleByStringInterpolation:
99
99
enum SyntaxStringInterpolationError : Error , CustomStringConvertible {
100
100
case didNotConsumeAllTokens( remainingTokens: [ TokenSyntax ] )
101
101
case producedInvalidNodeType( expectedType: SyntaxProtocol . Type , actualType: SyntaxProtocol . Type )
102
- case diagnostics( [ Diagnostic ] )
102
+ case diagnostics( [ Diagnostic ] , tree : Syntax )
103
103
104
104
var description : String {
105
105
switch self {
106
106
case . didNotConsumeAllTokens( remainingTokens: let tokens) :
107
107
return " Extraneous text in snippet: ' \( tokens. map ( \. description) . joined ( ) ) ' "
108
108
case . producedInvalidNodeType( expectedType: let expectedType, actualType: let actualType) :
109
109
return " Parsing the code snippet was expected to produce a \( expectedType) but produced a \( actualType) "
110
- case . diagnostics( let diagnostics) :
111
- return diagnostics . map ( \ . debugDescription ) . joined ( separator : " \n " )
110
+ case . diagnostics( let diagnostics, let tree ) :
111
+ return DiagnosticsFormatter . annotatedSource ( tree : tree , diags : diagnostics )
112
112
}
113
113
}
114
114
}
@@ -145,7 +145,7 @@ extension SyntaxExpressibleByStringInterpolation {
145
145
if result. hasError {
146
146
let diagnostics = ParseDiagnosticsGenerator . diagnostics ( for: result)
147
147
assert ( !diagnostics. isEmpty)
148
- throw SyntaxStringInterpolationError . diagnostics ( diagnostics)
148
+ throw SyntaxStringInterpolationError . diagnostics ( diagnostics, tree : Syntax ( result ) )
149
149
}
150
150
return result
151
151
}
0 commit comments