@@ -151,18 +151,19 @@ public struct DiagnosticsFormatter {
151
151
} . mergingOverlappingRanges ( )
152
152
153
153
// Map the column ranges into index ranges within the source string itself.
154
- let sourceString = annotatedLine. sourceString
154
+ let sourceStringUTF8 = annotatedLine. sourceString. utf8
155
155
let highlightIndexRanges : [ Range < String . Index > ] = highlightRanges. map { highlightRange in
156
- let startIndex = sourceString . index ( sourceString . startIndex, offsetBy: highlightRange. lowerBound - 1 )
157
- let endIndex = sourceString . index ( startIndex, offsetBy: highlightRange. count)
156
+ let startIndex = sourceStringUTF8 . index ( sourceStringUTF8 . startIndex, offsetBy: highlightRange. lowerBound - 1 )
157
+ let endIndex = sourceStringUTF8 . index ( startIndex, offsetBy: highlightRange. count)
158
158
return startIndex..< endIndex
159
159
}
160
160
161
161
// Form the annotated string by copying in text from the original source,
162
162
// highlighting the column ranges.
163
163
var resultSourceString : String = " "
164
- var sourceIndex = sourceString. startIndex
165
164
let annotation = ANSIAnnotation . sourceHighlight
165
+ let sourceString = annotatedLine. sourceString
166
+ var sourceIndex = sourceString. startIndex
166
167
for highlightRange in highlightIndexRanges {
167
168
// Text before the highlight range
168
169
resultSourceString += sourceString [ sourceIndex..< highlightRange. lowerBound]
0 commit comments