@@ -2,6 +2,7 @@ import AppKit
22import CopilotService
33import Foundation
44import LanguageServerProtocol
5+ import os. log
56import XPCShared
67
78@globalActor enum ServiceActor {
@@ -16,24 +17,6 @@ public class XPCService: NSObject, XPCServiceProtocol {
1617 @ServiceActor
1718 lazy var authService : CopilotAuthServiceType = Environment . createAuthService ( )
1819
19- override public init ( ) {
20- super. init ( )
21- let identifier = ObjectIdentifier ( self )
22- Task {
23- await AutoTrigger . shared. start ( by: identifier)
24- }
25- }
26-
27- deinit {
28- let identifier = ObjectIdentifier ( self )
29- Task { @ServiceActor in
30- for (_, workspace) in workspaces {
31- workspace. isRealtimeSuggestionEnabled = false
32- }
33- await AutoTrigger . shared. stop ( by: identifier)
34- }
35- }
36-
3720 public func checkStatus( withReply reply: @escaping ( String ? , Error ? ) -> Void ) {
3821 Task { @ServiceActor in
3922 do {
@@ -113,7 +96,7 @@ public class XPCService: NSObject, XPCServiceProtocol {
11396 }
11497 reply ( try JSONEncoder ( ) . encode ( updatedContent) , nil )
11598 } catch {
116- print ( error)
99+ os_log ( . error, " %@ " , error . localizedDescription )
117100 reply ( nil , NSError . from ( error) )
118101 }
119102 }
@@ -140,7 +123,7 @@ public class XPCService: NSObject, XPCServiceProtocol {
140123 }
141124 reply ( try JSONEncoder ( ) . encode ( updatedContent) , nil )
142125 } catch {
143- print ( error)
126+ os_log ( . error, " %@ " , error . localizedDescription )
144127 reply ( nil , NSError . from ( error) )
145128 }
146129 }
@@ -167,7 +150,7 @@ public class XPCService: NSObject, XPCServiceProtocol {
167150 }
168151 reply ( try JSONEncoder ( ) . encode ( updatedContent) , nil )
169152 } catch {
170- print ( error)
153+ os_log ( . error, " %@ " , error . localizedDescription )
171154 reply ( nil , NSError . from ( error) )
172155 }
173156 }
@@ -191,7 +174,7 @@ public class XPCService: NSObject, XPCServiceProtocol {
191174 )
192175 reply ( try JSONEncoder ( ) . encode ( updatedContent) , nil )
193176 } catch {
194- print ( error)
177+ os_log ( . error, " %@ " , error . localizedDescription )
195178 reply ( nil , NSError . from ( error) )
196179 }
197180 }
@@ -218,7 +201,7 @@ public class XPCService: NSObject, XPCServiceProtocol {
218201 }
219202 reply ( try JSONEncoder ( ) . encode ( updatedContent) , nil )
220203 } catch {
221- print ( error)
204+ os_log ( . error, " %@ " , error . localizedDescription )
222205 reply ( nil , NSError . from ( error) )
223206 }
224207 }
@@ -247,7 +230,7 @@ public class XPCService: NSObject, XPCServiceProtocol {
247230 }
248231 reply ( try JSONEncoder ( ) . encode ( updatedContent) , nil )
249232 } catch {
250- print ( error)
233+ os_log ( . error, " %@ " , error . localizedDescription )
251234 reply ( nil , NSError . from ( error) )
252235 }
253236 }
@@ -257,11 +240,19 @@ public class XPCService: NSObject, XPCServiceProtocol {
257240 Task { @ServiceActor in
258241 let fileURL = try await Environment . fetchCurrentFileURL ( )
259242 let workspace = try await fetchOrCreateWorkspaceIfNeeded ( fileURL: fileURL)
260- workspace. isRealtimeSuggestionEnabled = enabled
243+ if var state = UserDefaults . shared. dictionary ( forKey: SettingsKey . realtimeSuggestionState) {
244+ state [ workspace. projectRootURL. absoluteString] = enabled
245+ UserDefaults . shared. set ( state, forKey: SettingsKey . realtimeSuggestionState)
246+ } else {
247+ UserDefaults . shared. set (
248+ [ workspace. projectRootURL. absoluteString: enabled] ,
249+ forKey: SettingsKey . realtimeSuggestionState
250+ )
251+ }
261252 reply ( nil )
262253 }
263254 }
264-
255+
265256 public func prefetchRealtimeSuggestions(
266257 editorContent: Data ,
267258 withReply reply: @escaping ( ) -> Void
@@ -282,7 +273,7 @@ public class XPCService: NSObject, XPCServiceProtocol {
282273 )
283274 reply ( )
284275 } catch {
285- print ( error)
276+ os_log ( . error, " %@ " , error . localizedDescription )
286277 reply ( )
287278 }
288279 }
0 commit comments