@@ -128,6 +128,7 @@ abstract class CodeGenBase {
128128 public readonly conversationId : string
129129 public readonly uploadId : string
130130 public currentCodeGenerationId ?: string
131+ public isCancellationRequested ?: boolean
131132
132133 constructor (
133134 protected config : SessionStateConfig ,
@@ -145,14 +146,12 @@ abstract class CodeGenBase {
145146 codeGenerationId,
146147 telemetry : telemetry ,
147148 workspaceFolders,
148- isCancellationRequested,
149149 } : {
150150 messenger : Messenger
151151 fs : VirtualFileSystem
152152 codeGenerationId : string
153153 telemetry : TelemetryHelper
154154 workspaceFolders : CurrentWsFolders
155- isCancellationRequested ?: boolean
156155 } ) : Promise < {
157156 newFiles : NewFileInfo [ ]
158157 deletedFiles : DeletedFileInfo [ ]
@@ -162,7 +161,7 @@ abstract class CodeGenBase {
162161 } > {
163162 for (
164163 let pollingIteration = 0 ;
165- pollingIteration < this . pollCount && ! isCancellationRequested ;
164+ pollingIteration < this . pollCount && ! this . isCancellationRequested ;
166165 ++ pollingIteration
167166 ) {
168167 const codegenResult = await this . config . proxyClient . getCodeGeneration ( this . conversationId , codeGenerationId )
@@ -238,7 +237,7 @@ abstract class CodeGenBase {
238237 }
239238 }
240239 }
241- if ( ! isCancellationRequested ) {
240+ if ( ! this . isCancellationRequested ) {
242241 // still in progress
243242 const errorMessage = i18n ( 'AWS.amazonq.featureDev.error.codeGen.timeout' )
244243 throw new ToolkitError ( errorMessage , { code : 'CodeGenTimeout' } )
@@ -268,6 +267,12 @@ export class CodeGenState extends CodeGenBase implements SessionState {
268267 async interact ( action : SessionStateAction ) : Promise < SessionStateInteraction > {
269268 return telemetry . amazonq_codeGenerationInvoke . run ( async ( span ) => {
270269 try {
270+ action . tokenSource ?. token . onCancellationRequested ( ( ) => {
271+ this . isCancellationRequested = true
272+ if ( action . tokenSource ) {
273+ this . tokenSource = action . tokenSource
274+ }
275+ } )
271276 span . record ( {
272277 amazonqConversationId : this . config . conversationId ,
273278 credentialStartUrl : AuthUtil . instance . startUrl ,
@@ -284,7 +289,7 @@ export class CodeGenState extends CodeGenBase implements SessionState {
284289 this . currentCodeGenerationId
285290 )
286291
287- if ( ! action . tokenSource ?. token . isCancellationRequested ) {
292+ if ( ! this . isCancellationRequested ) {
288293 action . messenger . sendAnswer ( {
289294 message : i18n ( 'AWS.amazonq.featureDev.pillText.generatingCode' ) ,
290295 type : 'answer-part' ,
@@ -302,7 +307,6 @@ export class CodeGenState extends CodeGenBase implements SessionState {
302307 codeGenerationId,
303308 telemetry : action . telemetry ,
304309 workspaceFolders : this . config . workspaceFolders ,
305- isCancellationRequested : action . tokenSource ?. token . isCancellationRequested ,
306310 } )
307311
308312 if ( codeGeneration && ! action . tokenSource ?. token . isCancellationRequested ) {
0 commit comments