@@ -29,8 +29,9 @@ extension Sequence where Element == Range<Int> {
29
29
}
30
30
31
31
// If the ranges overlap, expand the prior range.
32
+ assert ( priorRange. lowerBound <= range. lowerBound)
32
33
if priorRange. overlaps ( range) {
33
- let lower = Swift . min ( priorRange. lowerBound, range . lowerBound )
34
+ let lower = priorRange. lowerBound
34
35
let upper = Swift . max ( priorRange. upperBound, range. upperBound)
35
36
prior = lower..< upper
36
37
continue
@@ -151,18 +152,19 @@ public struct DiagnosticsFormatter {
151
152
} . mergingOverlappingRanges ( )
152
153
153
154
// Map the column ranges into index ranges within the source string itself.
154
- let sourceString = annotatedLine. sourceString
155
+ let sourceStringUTF8 = annotatedLine. sourceString. utf8
155
156
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)
157
+ let startIndex = sourceStringUTF8 . index ( sourceStringUTF8 . startIndex, offsetBy: highlightRange. lowerBound - 1 )
158
+ let endIndex = sourceStringUTF8 . index ( startIndex, offsetBy: highlightRange. count)
158
159
return startIndex..< endIndex
159
160
}
160
161
161
162
// Form the annotated string by copying in text from the original source,
162
163
// highlighting the column ranges.
163
164
var resultSourceString : String = " "
164
- var sourceIndex = sourceString. startIndex
165
165
let annotation = ANSIAnnotation . sourceHighlight
166
+ let sourceString = annotatedLine. sourceString
167
+ var sourceIndex = sourceString. startIndex
166
168
for highlightRange in highlightIndexRanges {
167
169
// Text before the highlight range
168
170
resultSourceString += sourceString [ sourceIndex..< highlightRange. lowerBound]
@@ -188,7 +190,7 @@ public struct DiagnosticsFormatter {
188
190
tree: SyntaxType ,
189
191
diags: [ Diagnostic ] ,
190
192
indentString: String ,
191
- suffixTexts: [ ( AbsolutePosition , String ) ] ,
193
+ suffixTexts: [ AbsolutePosition : String ] ,
192
194
sourceLocationConverter: SourceLocationConverter ? = nil
193
195
) -> String {
194
196
let slc = sourceLocationConverter ?? SourceLocationConverter ( file: fileName ?? " " , tree: tree)
@@ -318,7 +320,7 @@ public struct DiagnosticsFormatter {
318
320
tree: tree,
319
321
diags: diags,
320
322
indentString: " " ,
321
- suffixTexts: [ ]
323
+ suffixTexts: [ : ]
322
324
)
323
325
}
324
326
@@ -372,6 +374,7 @@ struct ANSIAnnotation {
372
374
case magenta = 35
373
375
case cyan = 36
374
376
case white = 37
377
+ case `default` = 39
375
378
}
376
379
377
380
enum Trait : UInt8 {
@@ -414,6 +417,6 @@ struct ANSIAnnotation {
414
417
415
418
/// Annotation used for highlighting source text.
416
419
static var sourceHighlight : ANSIAnnotation {
417
- ANSIAnnotation ( color: . white , trait: . underline)
420
+ ANSIAnnotation ( color: . default , trait: . underline)
418
421
}
419
422
}
0 commit comments