@@ -45,11 +45,13 @@ public final class GitHubCopilotChatService: BuiltinExtensionChatServiceType {
4545 workspaceFolder: workspace. projectURL. path
4646 ) )
4747
48- var cont : AsyncThrowingStream < String , Error > . Continuation ? = nil
4948 let stream = AsyncThrowingStream < String , Error > { continuation in
50- cont = continuation
5149 let startTimestamp = Date ( )
5250
51+ continuation. onTermination = { _ in
52+ Task { service. unregisterNotificationHandler ( id: id) }
53+ }
54+
5355 service. registerNotificationHandler ( id: id) { notification, data in
5456 // just incase the conversation is stuck, we will cancel it after timeout
5557 if Date ( ) . timeIntervalSince ( startTimestamp) > 60 * 30 {
@@ -71,11 +73,9 @@ public final class GitHubCopilotChatService: BuiltinExtensionChatServiceType {
7173 if let error = progress. value. error,
7274 progress. value. cancellationReason == nil
7375 {
74- continuation. finish ( throwing: ServerError . serverError (
75- code: 0 ,
76- message: error,
77- data: nil
78- ) )
76+ continuation. finish (
77+ throwing: GitHubCopilotError . chatEndsWithError ( error)
78+ )
7979 } else {
8080 continuation. finish ( )
8181 }
@@ -99,22 +99,22 @@ public final class GitHubCopilotChatService: BuiltinExtensionChatServiceType {
9999 return false
100100 }
101101 }
102- }
103102
104- do {
105- let createResponse = try await service. server. sendRequest ( request)
106- cont? . onTermination = { _ in
107- Task {
108- service. unregisterNotificationHandler ( id: id)
103+ Task {
104+ do {
105+ // this will return when the response is generated.
106+ let createResponse = try await service. server. sendRequest ( request, timeout: 120 )
109107 _ = try await service. server. sendRequest (
110108 GitHubCopilotRequest . ConversationDestroy ( requestBody: . init(
111109 conversationId: createResponse. conversationId
112110 ) )
113111 )
112+ } catch let error as ServerError {
113+ continuation. finish ( throwing: GitHubCopilotError . languageServerError ( error) )
114+ } catch {
115+ continuation. finish ( throwing: error)
114116 }
115117 }
116- } catch {
117- cont? . finish ( throwing: error)
118118 }
119119
120120 return stream
@@ -168,7 +168,7 @@ extension GitHubCopilotChatService {
168168 func createNewMessage( references: [ RetrievedContent ] , message: String ) -> String {
169169 return message
170170 }
171-
171+
172172 struct JSONRPC < Params: Decodable > : Decodable {
173173 var jsonrpc : String
174174 var method : String
0 commit comments