@@ -80,47 +80,47 @@ public struct AsyncXPCService {
8080 }
8181 }
8282
83- public func getSuggestedCode( editorContent: EditorContent ) async throws -> UpdatedContent {
83+ public func getSuggestedCode( editorContent: EditorContent ) async throws -> UpdatedContent ? {
8484 try await suggestionRequest (
8585 connection,
8686 editorContent,
8787 { $0. getSuggestedCode }
8888 )
8989 }
9090
91- public func getNextSuggestedCode( editorContent: EditorContent ) async throws -> UpdatedContent {
91+ public func getNextSuggestedCode( editorContent: EditorContent ) async throws -> UpdatedContent ? {
9292 try await suggestionRequest (
9393 connection,
9494 editorContent,
9595 { $0. getNextSuggestedCode }
9696 )
9797 }
9898
99- public func getPreviousSuggestedCode( editorContent: EditorContent ) async throws -> UpdatedContent {
99+ public func getPreviousSuggestedCode( editorContent: EditorContent ) async throws -> UpdatedContent ? {
100100 try await suggestionRequest (
101101 connection,
102102 editorContent,
103103 { $0. getPreviousSuggestedCode }
104104 )
105105 }
106106
107- public func getSuggestionAcceptedCode( editorContent: EditorContent ) async throws -> UpdatedContent {
107+ public func getSuggestionAcceptedCode( editorContent: EditorContent ) async throws -> UpdatedContent ? {
108108 try await suggestionRequest (
109109 connection,
110110 editorContent,
111111 { $0. getSuggestionAcceptedCode }
112112 )
113113 }
114114
115- public func getSuggestionRejectedCode( editorContent: EditorContent ) async throws -> UpdatedContent {
115+ public func getSuggestionRejectedCode( editorContent: EditorContent ) async throws -> UpdatedContent ? {
116116 try await suggestionRequest (
117117 connection,
118118 editorContent,
119119 { $0. getSuggestionRejectedCode }
120120 )
121121 }
122122
123- public func getRealtimeSuggestedCode( editorContent: EditorContent ) async throws -> UpdatedContent {
123+ public func getRealtimeSuggestedCode( editorContent: EditorContent ) async throws -> UpdatedContent ? {
124124 try await suggestionRequest (
125125 connection,
126126 editorContent,
@@ -172,7 +172,7 @@ func suggestionRequest(
172172 _ connection: NSXPCConnection ,
173173 _ editorContent: EditorContent ,
174174 _ fn: @escaping ( any XPCServiceProtocol ) -> ( Data , @escaping ( Data ? , Error ? ) -> Void ) -> Void
175- ) async throws -> UpdatedContent {
175+ ) async throws -> UpdatedContent ? {
176176 let data = try JSONEncoder ( ) . encode ( editorContent)
177177 return try await withXPCServiceConnected ( connection: connection) {
178178 service, continuation in
@@ -182,9 +182,13 @@ func suggestionRequest(
182182 return
183183 }
184184 do {
185- let updatedContent = try JSONDecoder ( )
186- . decode ( UpdatedContent . self, from: updatedData ?? Data ( ) )
187- continuation. resume ( updatedContent)
185+ if let updatedData {
186+ let updatedContent = try JSONDecoder ( )
187+ . decode ( UpdatedContent . self, from: updatedData ?? Data ( ) )
188+ continuation. resume ( updatedContent)
189+ } else {
190+ continuation. resume ( nil )
191+ }
188192 } catch {
189193 continuation. reject ( error)
190194 }
0 commit comments