11import CopilotModel
22import Foundation
3+ import XPCShared
34
4- struct AsyncXPCService {
5+ public struct AsyncXPCService {
56 let connection : NSXPCConnection
7+
8+ public init ( connection: NSXPCConnection ) {
9+ self . connection = connection
10+ }
611
7- func checkStatus( ) async throws -> CopilotStatus {
12+ public func checkStatus( ) async throws -> CopilotStatus {
813 try await withXPCServiceConnected ( connection: connection) {
914 service, continuation in
1015 service. checkStatus { status, error in
@@ -20,7 +25,7 @@ struct AsyncXPCService {
2025 }
2126 }
2227
23- func getVersion( ) async throws -> String {
28+ public func getVersion( ) async throws -> String {
2429 try await withXPCServiceConnected ( connection: connection) {
2530 service, continuation in
2631 service. getVersion { version, error in
@@ -33,7 +38,7 @@ struct AsyncXPCService {
3338 }
3439 }
3540
36- func signInInitiate( ) async throws -> ( verificationUri: String , userCode: String ) {
41+ public func signInInitiate( ) async throws -> ( verificationUri: String , userCode: String ) {
3742 try await withXPCServiceConnected ( connection: connection) {
3843 service, continuation in
3944 service. signInInitiate { verificationUri, userCode, error in
@@ -46,7 +51,7 @@ struct AsyncXPCService {
4651 }
4752 }
4853
49- func signInConfirm( userCode: String ) async throws -> ( username: String , status: CopilotStatus ) {
54+ public func signInConfirm( userCode: String ) async throws -> ( username: String , status: CopilotStatus ) {
5055 try await withXPCServiceConnected ( connection: connection) {
5156 service, continuation in
5257 service. signInConfirm ( userCode: userCode) { username, status, error in
@@ -62,7 +67,7 @@ struct AsyncXPCService {
6267 }
6368 }
6469
65- func signOut( ) async throws -> CopilotStatus {
70+ public func signOut( ) async throws -> CopilotStatus {
6671 try await withXPCServiceConnected ( connection: connection) {
6772 service, continuation in
6873 service. signOut { finishstatus, error in
@@ -75,39 +80,39 @@ struct AsyncXPCService {
7580 }
7681 }
7782
78- func getSuggestedCode( editorContent: EditorContent ) async throws -> UpdatedContent {
83+ public func getSuggestedCode( editorContent: EditorContent ) async throws -> UpdatedContent {
7984 try await suggestionRequest (
8085 connection,
8186 editorContent,
8287 { $0. getSuggestedCode }
8388 )
8489 }
8590
86- func getNextSuggestedCode( editorContent: EditorContent ) async throws -> UpdatedContent {
91+ public func getNextSuggestedCode( editorContent: EditorContent ) async throws -> UpdatedContent {
8792 try await suggestionRequest (
8893 connection,
8994 editorContent,
9095 { $0. getNextSuggestedCode }
9196 )
9297 }
9398
94- func getPreviousSuggestedCode( editorContent: EditorContent ) async throws -> UpdatedContent {
99+ public func getPreviousSuggestedCode( editorContent: EditorContent ) async throws -> UpdatedContent {
95100 try await suggestionRequest (
96101 connection,
97102 editorContent,
98103 { $0. getPreviousSuggestedCode }
99104 )
100105 }
101106
102- func getSuggestionAcceptedCode( editorContent: EditorContent ) async throws -> UpdatedContent {
107+ public func getSuggestionAcceptedCode( editorContent: EditorContent ) async throws -> UpdatedContent {
103108 try await suggestionRequest (
104109 connection,
105110 editorContent,
106111 { $0. getSuggestionAcceptedCode }
107112 )
108113 }
109114
110- func getSuggestionRejectedCode( editorContent: EditorContent ) async throws -> UpdatedContent {
115+ public func getSuggestionRejectedCode( editorContent: EditorContent ) async throws -> UpdatedContent {
111116 try await suggestionRequest (
112117 connection,
113118 editorContent,
@@ -116,7 +121,7 @@ struct AsyncXPCService {
116121 }
117122}
118123
119- private struct AutoFinishContinuation < T> {
124+ struct AutoFinishContinuation < T> {
120125 var continuation : AsyncThrowingStream < T , Error > . Continuation
121126
122127 func resume( _ value: T ) {
@@ -129,7 +134,7 @@ private struct AutoFinishContinuation<T> {
129134 }
130135}
131136
132- private func withXPCServiceConnected< T> (
137+ func withXPCServiceConnected< T> (
133138 connection: NSXPCConnection ,
134139 _ fn: @escaping ( XPCServiceProtocol , AutoFinishContinuation < T > ) -> Void
135140) async throws -> T {
@@ -142,7 +147,7 @@ private func withXPCServiceConnected<T>(
142147 return try await stream. first ( where: { _ in true } ) !
143148}
144149
145- private func suggestionRequest(
150+ func suggestionRequest(
146151 _ connection: NSXPCConnection ,
147152 _ editorContent: EditorContent ,
148153 _ fn: @escaping ( any XPCServiceProtocol ) -> ( Data , @escaping ( Data ? , Error ? ) -> Void ) -> Void
0 commit comments