@@ -12,7 +12,7 @@ import QuartzCore
1212import Workspace
1313import XcodeInspector
1414
15- public class RealtimeSuggestionController {
15+ public actor RealtimeSuggestionController {
1616 let eventObserver : CGEventObserverType = CGEventObserver ( eventsOfInterest: [ . keyDown] )
1717 private var task : Task < Void , Error > ?
1818 private var inflightPrefetchTask : Task < Void , Error > ?
@@ -23,12 +23,13 @@ public class RealtimeSuggestionController {
2323 private var sourceEditor : SourceEditor ?
2424
2525 init ( ) { }
26-
26+
27+ nonisolated
2728 func start( ) {
2829 Task { [ weak self] in
2930 if let app = ActiveApplicationMonitor . shared. activeXcode {
30- self ? . handleXcodeChanged ( app)
31- self ? . startHIDObservation ( )
31+ await self ? . handleXcodeChanged ( app)
32+ await self ? . startHIDObservation ( )
3233 }
3334 var previousApp = ActiveApplicationMonitor . shared. activeXcode
3435 for await app in ActiveApplicationMonitor . shared. createStream ( ) {
@@ -37,13 +38,13 @@ public class RealtimeSuggestionController {
3738 defer { previousApp = app }
3839
3940 if let app = ActiveApplicationMonitor . shared. activeXcode, app != previousApp {
40- self . handleXcodeChanged ( app)
41+ await self . handleXcodeChanged ( app)
4142 }
4243
4344 if ActiveApplicationMonitor . shared. activeXcode != nil {
44- startHIDObservation ( )
45+ await startHIDObservation ( )
4546 } else {
46- stopHIDObservation ( )
47+ await stopHIDObservation ( )
4748 }
4849 }
4950 }
@@ -85,7 +86,7 @@ public class RealtimeSuggestionController {
8586 for await _ in notifications {
8687 guard let self else { return }
8788 try Task . checkCancellation ( )
88- self . handleFocusElementChange ( )
89+ await self . handleFocusElementChange ( )
8990 }
9091 }
9192 }
@@ -112,7 +113,7 @@ public class RealtimeSuggestionController {
112113
113114 editorObservationTask = Task { [ weak self] in
114115 let fileURL = try await Environment . fetchCurrentFileURL ( )
115- if let sourceEditor = self ? . sourceEditor {
116+ if let sourceEditor = await self ? . sourceEditor {
116117 await PseudoCommandHandler ( ) . invalidateRealtimeSuggestionsIfNeeded (
117118 fileURL: fileURL,
118119 sourceEditor: sourceEditor
@@ -132,10 +133,10 @@ public class RealtimeSuggestionController {
132133 switch notification. name {
133134 case kAXValueChangedNotification:
134135 await cancelInFlightTasks ( )
135- self . triggerPrefetchDebounced ( )
136+ await self . triggerPrefetchDebounced ( )
136137 await self . notifyEditingFileChange ( editor: focusElement)
137138 case kAXSelectedTextChangedNotification:
138- guard let sourceEditor else { continue }
139+ guard let sourceEditor = await sourceEditor else { continue }
139140 let fileURL = XcodeInspector . shared. activeDocumentURL
140141 await PseudoCommandHandler ( ) . invalidateRealtimeSuggestionsIfNeeded (
141142 fileURL: fileURL,
0 commit comments