@@ -241,15 +241,12 @@ public func addQueuedSourceFile(
241
241
public func addQueuedDiagnostic(
242
242
queuedDiagnosticsPtr: UnsafeMutableRawPointer ,
243
243
perFrontendDiagnosticStatePtr: UnsafeMutableRawPointer ,
244
- text: UnsafePointer < UInt8 > ,
245
- textLength: Int ,
244
+ text: BridgedStringRef ,
246
245
severity: BridgedDiagnosticSeverity ,
247
246
cLoc: BridgedSourceLoc ,
248
- categoryName: UnsafePointer < UInt8 > ? ,
249
- categoryLength: Int ,
250
- documentationPath: UnsafePointer < UInt8 > ? ,
251
- documentationPathLength: Int ,
252
- highlightRangesPtr: UnsafePointer < BridgedSourceLoc > ? ,
247
+ categoryName: BridgedStringRef ,
248
+ documentationPath: BridgedStringRef ,
249
+ highlightRangesPtr: UnsafePointer < BridgedCharSourceRange > ? ,
253
250
numHighlightRanges: Int
254
251
) {
255
252
let queuedDiagnostics = queuedDiagnosticsPtr. assumingMemoryBound (
@@ -302,14 +299,16 @@ public func addQueuedDiagnostic(
302
299
303
300
// Map the highlights.
304
301
var highlights : [ Syntax ] = [ ]
305
- let highlightRanges = UnsafeBufferPointer < BridgedSourceLoc > (
302
+ let highlightRanges = UnsafeBufferPointer < BridgedCharSourceRange > (
306
303
start: highlightRangesPtr,
307
- count: numHighlightRanges * 2
304
+ count: numHighlightRanges
308
305
)
309
306
for index in 0 ..< numHighlightRanges {
307
+ let range = highlightRanges [ index]
308
+
310
309
// Make sure both the start and the end land within this source file.
311
- guard let start = highlightRanges [ index * 2 ] . getOpaquePointerValue ( ) ,
312
- let end = highlightRanges [ index * 2 + 1 ] . getOpaquePointerValue ( )
310
+ guard let start = range . start . getOpaquePointerValue ( ) ,
311
+ let end = range . start . advanced ( by : range . byteLength ) . getOpaquePointerValue ( )
313
312
else {
314
313
continue
315
314
}
@@ -349,53 +348,37 @@ public func addQueuedDiagnostic(
349
348
}
350
349
}
351
350
352
- let category : DiagnosticCategory ? = categoryName. flatMap { categoryNamePtr in
353
- let categoryNameBuffer = UnsafeBufferPointer (
354
- start: categoryNamePtr,
355
- count: categoryLength
356
- )
357
- let categoryName = String ( decoding: categoryNameBuffer, as: UTF8 . self)
358
-
359
- // If the data comes from serialized diagnostics, it's possible that
360
- // the category name is empty because StringRef() is serialized into
361
- // an empty string.
362
- guard !categoryName. isEmpty else {
363
- return nil
351
+ let documentationPath = String ( bridged: documentationPath)
352
+ let documentationURL : String ? = if !documentationPath. isEmpty {
353
+ // If this looks doesn't look like a URL, prepend file://.
354
+ documentationPath. looksLikeURL ? documentationPath : " file:// \( documentationPath) "
355
+ } else {
356
+ nil
364
357
}
365
358
366
- let documentationURL = documentationPath. map { documentationPathPtr in
367
- let documentationPathBuffer = UnsafeBufferPointer (
368
- start: documentationPathPtr,
369
- count: documentationPathLength
359
+ let categoryName = String ( bridged: categoryName)
360
+ // If the data comes from serialized diagnostics, it's possible that
361
+ // the category name is empty because StringRef() is serialized into
362
+ // an empty string.
363
+ let category : DiagnosticCategory ? = if !categoryName. isEmpty {
364
+ DiagnosticCategory (
365
+ name: categoryName,
366
+ documentationURL: documentationURL
370
367
)
371
-
372
- let documentationPath = String ( decoding: documentationPathBuffer, as: UTF8 . self)
373
-
374
- // If this looks doesn't look like a URL, prepend file://.
375
- if !documentationPath. looksLikeURL {
376
- return " file:// \( documentationPath) "
377
- }
378
-
379
- return documentationPath
368
+ } else {
369
+ nil
380
370
}
381
371
382
- return DiagnosticCategory (
383
- name: categoryName,
384
- documentationURL: documentationURL
385
- )
386
- }
387
-
388
372
// Note that we referenced this category.
389
373
if let category {
390
374
diagnosticState. pointee. referencedCategories. insert ( category)
391
375
}
392
376
393
- let textBuffer = UnsafeBufferPointer ( start: text, count: textLength)
394
377
let diagnostic = Diagnostic (
395
378
node: node,
396
379
position: position,
397
380
message: SimpleDiagnostic (
398
- message: String ( decoding : textBuffer , as : UTF8 . self ) ,
381
+ message: String ( bridged : text ) ,
399
382
severity: severity. asSeverity,
400
383
category: category
401
384
) ,
0 commit comments