@@ -29,8 +29,9 @@ extension Sequence where Element == Range<Int> {
2929 }
3030
3131 // If the ranges overlap, expand the prior range.
32+ assert ( priorRange. lowerBound <= range. lowerBound)
3233 if priorRange. overlaps ( range) {
33- let lower = Swift . min ( priorRange. lowerBound, range . lowerBound )
34+ let lower = priorRange. lowerBound
3435 let upper = Swift . max ( priorRange. upperBound, range. upperBound)
3536 prior = lower..< upper
3637 continue
@@ -151,18 +152,19 @@ public struct DiagnosticsFormatter {
151152 } . mergingOverlappingRanges ( )
152153
153154 // Map the column ranges into index ranges within the source string itself.
154- let sourceString = annotatedLine. sourceString
155+ let sourceStringUTF8 = annotatedLine. sourceString. utf8
155156 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)
158159 return startIndex..< endIndex
159160 }
160161
161162 // Form the annotated string by copying in text from the original source,
162163 // highlighting the column ranges.
163164 var resultSourceString : String = " "
164- var sourceIndex = sourceString. startIndex
165165 let annotation = ANSIAnnotation . sourceHighlight
166+ let sourceString = annotatedLine. sourceString
167+ var sourceIndex = sourceString. startIndex
166168 for highlightRange in highlightIndexRanges {
167169 // Text before the highlight range
168170 resultSourceString += sourceString [ sourceIndex..< highlightRange. lowerBound]
@@ -188,7 +190,7 @@ public struct DiagnosticsFormatter {
188190 tree: SyntaxType ,
189191 diags: [ Diagnostic ] ,
190192 indentString: String ,
191- suffixTexts: [ ( AbsolutePosition , String ) ] ,
193+ suffixTexts: [ AbsolutePosition : String ] ,
192194 sourceLocationConverter: SourceLocationConverter ? = nil
193195 ) -> String {
194196 let slc = sourceLocationConverter ?? SourceLocationConverter ( file: fileName ?? " " , tree: tree)
@@ -318,7 +320,7 @@ public struct DiagnosticsFormatter {
318320 tree: tree,
319321 diags: diags,
320322 indentString: " " ,
321- suffixTexts: [ ]
323+ suffixTexts: [ : ]
322324 )
323325 }
324326
@@ -372,6 +374,7 @@ struct ANSIAnnotation {
372374 case magenta = 35
373375 case cyan = 36
374376 case white = 37
377+ case `default` = 39
375378 }
376379
377380 enum Trait : UInt8 {
@@ -414,6 +417,6 @@ struct ANSIAnnotation {
414417
415418 /// Annotation used for highlighting source text.
416419 static var sourceHighlight : ANSIAnnotation {
417- ANSIAnnotation ( color: . white , trait: . underline)
420+ ANSIAnnotation ( color: . default , trait: . underline)
418421 }
419422}
0 commit comments