@@ -42,6 +42,7 @@ import {
4242 LINK_CLICK_NOTIFICATION_METHOD ,
4343 LinkClickParams ,
4444 INFO_LINK_CLICK_NOTIFICATION_METHOD ,
45+ CancellationTokenSource ,
4546} from '@aws/language-server-runtimes/protocol'
4647import { v4 as uuidv4 } from 'uuid'
4748import * as vscode from 'vscode'
@@ -109,6 +110,8 @@ export function registerMessageListeners(
109110 return
110111 }
111112
113+ const chatStreamTokens = new Map < string , CancellationTokenSource > ( ) // tab id -> token
114+
112115 const webview = provider . webview
113116 switch ( message . command ) {
114117 case COPY_TO_CLIPBOARD :
@@ -181,10 +184,21 @@ export function registerMessageListeners(
181184 void openUrl ( vscode . Uri . parse ( linkParams . link ) )
182185 break
183186 }
187+ case STOP_RESPONSE : {
188+ const tabId = ( message as StopResponseMessage ) . tabId
189+ const token = chatStreamTokens . get ( tabId )
190+ token ?. cancel ( )
191+ token ?. dispose ( )
192+ chatStreamTokens . delete ( tabId )
193+ break
194+ }
184195 case chatRequestType . method : {
185196 const chatParams : ChatParams = { ...message . params }
186197 const partialResultToken = uuidv4 ( )
187198 let lastPartialResult : ChatResult | undefined
199+ const cancellationToken = new CancellationTokenSource ( )
200+ chatStreamTokens . set ( message . params . tabId , cancellationToken )
201+
188202 const chatDisposable = languageClient . onProgress (
189203 chatRequestType ,
190204 partialResultToken ,
0 commit comments