@@ -346,17 +346,25 @@ public func addQueuedDiagnostic(
346
346
)
347
347
let categoryName = String ( decoding: categoryNameBuffer, as: UTF8 . self)
348
348
349
- let documentationPath = documentationPath. map { documentationPathPtr in
349
+ let documentationURL = documentationPath. map { documentationPathPtr in
350
350
let documentationPathBuffer = UnsafeBufferPointer (
351
351
start: documentationPathPtr,
352
352
count: documentationPathLength
353
353
)
354
- return String ( decoding: documentationPathBuffer, as: UTF8 . self)
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
355
363
}
356
364
357
365
return DiagnosticCategory (
358
366
name: categoryName,
359
- documentationPath : documentationPath
367
+ documentationURL : documentationURL
360
368
)
361
369
}
362
370
@@ -389,3 +397,30 @@ public func renderQueuedDiagnostics(
389
397
390
398
renderedStringOutPtr. pointee = allocateBridgedString ( renderedStr)
391
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