@@ -236,6 +236,14 @@ public func addQueuedSourceFile(
236236 queuedDiagnostics. pointee. sourceFileIDs [ bufferID] = allocatedSourceFileID
237237}
238238
239+ private struct BridgedFixItMessage : FixItMessage {
240+ var message : String { " " }
241+
242+ var fixItID : MessageID {
243+ . init( domain: " SwiftCompiler " , id: " BridgedFixIt " )
244+ }
245+ }
246+
239247/// Add a new diagnostic to the queue.
240248@_cdecl ( " swift_ASTGen_addQueuedDiagnostic " )
241249public func addQueuedDiagnostic(
@@ -247,7 +255,8 @@ public func addQueuedDiagnostic(
247255 categoryName: BridgedStringRef ,
248256 documentationPath: BridgedStringRef ,
249257 highlightRangesPtr: UnsafePointer < BridgedCharSourceRange > ? ,
250- numHighlightRanges: Int
258+ numHighlightRanges: Int ,
259+ fixItsUntyped: BridgedArrayRef
251260) {
252261 let queuedDiagnostics = queuedDiagnosticsPtr. assumingMemoryBound (
253262 to: QueuedDiagnostics . self
@@ -374,6 +383,33 @@ public func addQueuedDiagnostic(
374383 diagnosticState. pointee. referencedCategories. insert ( category)
375384 }
376385
386+ // Map the Fix-Its
387+ let fixItChanges : [ FixIt . Change ] = fixItsUntyped. withElements ( ofType: BridgedFixIt . self) { fixIts in
388+ fixIts. compactMap { fixIt in
389+ guard let startPos = sourceFile. position ( of: fixIt. replacementRange. start) ,
390+ let endPos = sourceFile. position (
391+ of: fixIt. replacementRange. start. advanced (
392+ by: fixIt. replacementRange. byteLength) ) else {
393+ return nil
394+ }
395+
396+ return FixIt . Change. replaceText (
397+ range: startPos..< endPos,
398+ with: String ( bridged: fixIt. replacementText) ,
399+ in: sourceFile. syntax
400+ )
401+ }
402+ }
403+
404+ let fixIts : [ FixIt ] = fixItChanges. isEmpty
405+ ? [ ]
406+ : [
407+ FixIt (
408+ message: BridgedFixItMessage ( ) ,
409+ changes: fixItChanges
410+ )
411+ ]
412+
377413 let diagnostic = Diagnostic (
378414 node: node,
379415 position: position,
@@ -382,7 +418,8 @@ public func addQueuedDiagnostic(
382418 severity: severity. asSeverity,
383419 category: category
384420 ) ,
385- highlights: highlights
421+ highlights: highlights,
422+ fixIts: fixIts
386423 )
387424
388425 queuedDiagnostics. pointee. grouped. addDiagnostic ( diagnostic)
0 commit comments