@@ -165,6 +165,8 @@ fileprivate struct SimpleDiagnostic: DiagnosticMessage {
165
165
166
166
let severity : DiagnosticSeverity
167
167
168
+ let category : DiagnosticCategory ?
169
+
168
170
var diagnosticID : MessageID {
169
171
. init( domain: " SwiftCompiler " , id: " SimpleDiagnostic " )
170
172
}
@@ -237,6 +239,10 @@ public func addQueuedDiagnostic(
237
239
textLength: Int ,
238
240
severity: BridgedDiagnosticSeverity ,
239
241
cLoc: BridgedSourceLoc ,
242
+ categoryName: UnsafePointer < UInt8 > ? ,
243
+ categoryLength: Int ,
244
+ documentationPath: UnsafePointer < UInt8 > ? ,
245
+ documentationPathLength: Int ,
240
246
highlightRangesPtr: UnsafePointer < BridgedSourceLoc > ? ,
241
247
numHighlightRanges: Int
242
248
) {
@@ -333,13 +339,43 @@ public func addQueuedDiagnostic(
333
339
}
334
340
}
335
341
342
+ let category : DiagnosticCategory ? = categoryName. map { categoryNamePtr in
343
+ let categoryNameBuffer = UnsafeBufferPointer (
344
+ start: categoryNamePtr,
345
+ count: categoryLength
346
+ )
347
+ let categoryName = String ( decoding: categoryNameBuffer, as: UTF8 . self)
348
+
349
+ let documentationURL = documentationPath. map { documentationPathPtr in
350
+ let documentationPathBuffer = UnsafeBufferPointer (
351
+ start: documentationPathPtr,
352
+ count: documentationPathLength
353
+ )
354
+
355
+ let documentationPath = String ( decoding: documentationPathBuffer, as: UTF8 . self)
356
+
357
+ // If this looks doesn't look like a URL, prepend file://.
358
+ if !documentationPath. looksLikeURL {
359
+ return " file:// \( documentationPath) "
360
+ }
361
+
362
+ return documentationPath
363
+ }
364
+
365
+ return DiagnosticCategory (
366
+ name: categoryName,
367
+ documentationURL: documentationURL
368
+ )
369
+ }
370
+
336
371
let textBuffer = UnsafeBufferPointer ( start: text, count: textLength)
337
372
let diagnostic = Diagnostic (
338
373
node: node,
339
374
position: position,
340
375
message: SimpleDiagnostic (
341
376
message: String ( decoding: textBuffer, as: UTF8 . self) ,
342
- severity: severity. asSeverity
377
+ severity: severity. asSeverity,
378
+ category: category
343
379
) ,
344
380
highlights: highlights
345
381
)
@@ -361,3 +397,30 @@ public func renderQueuedDiagnostics(
361
397
362
398
renderedStringOutPtr. pointee = allocateBridgedString ( renderedStr)
363
399
}
400
+
401
+ extension String {
402
+ /// Simple check to determine whether the string looks like the start of a
403
+ /// URL.
404
+ fileprivate var looksLikeURL : Bool {
405
+ var forwardSlashes : Int = 0
406
+ for c in self {
407
+ if c == " / " {
408
+ forwardSlashes += 1
409
+ if forwardSlashes > 2 {
410
+ return true
411
+ }
412
+
413
+ continue
414
+ }
415
+
416
+ if c. isLetter || c. isNumber {
417
+ forwardSlashes = 0
418
+ continue
419
+ }
420
+
421
+ return false
422
+ }
423
+
424
+ return false
425
+ }
426
+ }
0 commit comments