@@ -30,9 +30,8 @@ public struct SourceLocation: Codable {
30
30
public let file : String
31
31
32
32
public init ( file: String , position: AbsolutePosition ) {
33
- assert ( position is UTF8Position , " must be utf8 position " )
34
33
self . init ( line: position. line, column: position. column,
35
- offset: position. byteOffset , file: file)
34
+ offset: position. utf8Offset , file: file)
36
35
}
37
36
38
37
public init ( line: Int , column: Int , offset: Int , file: String ) {
@@ -88,7 +87,7 @@ public enum FixIt: Codable {
88
87
let string = try container. decode ( String . self, forKey: . string)
89
88
let loc = try container. decode ( SourceLocation . self, forKey: . location)
90
89
self = . insert( loc, string)
91
- case " replace " :
90
+ case " replace " :
92
91
let string = try container. decode ( String . self, forKey: . string)
93
92
let range = try container. decode ( SourceRange . self, forKey: . range)
94
93
self = . replace( range, string)
@@ -202,7 +201,11 @@ public struct Diagnostic: Codable {
202
201
/// An array of possible FixIts to apply to this diagnostic.
203
202
public let fixIts : [ FixIt ]
204
203
205
- /// A diagnostic builder that
204
+ /// A diagnostic builder that exposes mutating operations for notes,
205
+ /// highlights, and FixIts. When a Diagnostic is created, a builder
206
+ /// will be provided in a closure where the user can conditionally
207
+ /// add notes, highlights, and FixIts, that will then be wrapped
208
+ /// into the immutable Diagnostic object.
206
209
public struct Builder {
207
210
/// An in-flight array of notes.
208
211
internal var notes = [ Note] ( )
@@ -225,7 +228,7 @@ public struct Diagnostic: Codable {
225
228
/// - fixIts: Any FixIts that should be attached to this note.
226
229
public mutating func note( _ message: Message ,
227
230
location: SourceLocation ? = nil ,
228
- highlights: [ SourceRange ] = [ ] ,
231
+ highlights: [ SourceRange ] = [ ] ,
229
232
fixIts: [ FixIt ] = [ ] ) {
230
233
self . notes. append ( Note ( message: message, location: location,
231
234
highlights: highlights, fixIts: fixIts) )
@@ -252,7 +255,7 @@ public struct Diagnostic: Codable {
252
255
253
256
/// Adds a FixIt to replace the contents of the source file corresponding
254
257
/// to the provided SourceRange with the provided text.
255
- public mutating
258
+ public mutating
256
259
func fixItReplace( _ sourceRange: SourceRange , with text: String ) {
257
260
fixIts. append ( . replace( sourceRange, text) )
258
261
}
0 commit comments