@@ -124,7 +124,6 @@ abstract class CodeGenBase {
124124 private pollCount = 180
125125 private requestDelay = 10000
126126 public tokenSource : vscode . CancellationTokenSource
127- public isCancellationRequested : boolean
128127 public phase : SessionStatePhase = DevPhase . CODEGEN
129128 public readonly conversationId : string
130129 public readonly uploadId : string
@@ -135,7 +134,6 @@ abstract class CodeGenBase {
135134 public tabID : string
136135 ) {
137136 this . tokenSource = new vscode . CancellationTokenSource ( )
138- this . isCancellationRequested = false
139137 this . conversationId = config . conversationId
140138 this . uploadId = config . uploadId
141139 this . currentCodeGenerationId = config . currentCodeGenerationId || EmptyCodeGenID
@@ -147,12 +145,14 @@ abstract class CodeGenBase {
147145 codeGenerationId,
148146 telemetry : telemetry ,
149147 workspaceFolders,
148+ isCancellationRequested,
150149 } : {
151150 messenger : Messenger
152151 fs : VirtualFileSystem
153152 codeGenerationId : string
154153 telemetry : TelemetryHelper
155154 workspaceFolders : CurrentWsFolders
155+ isCancellationRequested ?: boolean
156156 } ) : Promise < {
157157 newFiles : NewFileInfo [ ]
158158 deletedFiles : DeletedFileInfo [ ]
@@ -162,7 +162,7 @@ abstract class CodeGenBase {
162162 } > {
163163 for (
164164 let pollingIteration = 0 ;
165- pollingIteration < this . pollCount && ! this . isCancellationRequested ;
165+ pollingIteration < this . pollCount && ! isCancellationRequested ;
166166 ++ pollingIteration
167167 ) {
168168 const codegenResult = await this . config . proxyClient . getCodeGeneration ( this . conversationId , codeGenerationId )
@@ -238,7 +238,7 @@ abstract class CodeGenBase {
238238 }
239239 }
240240 }
241- if ( ! this . isCancellationRequested ) {
241+ if ( ! isCancellationRequested ) {
242242 // still in progress
243243 const errorMessage = i18n ( 'AWS.amazonq.featureDev.error.codeGen.timeout' )
244244 throw new ToolkitError ( errorMessage , { code : 'CodeGenTimeout' } )
@@ -273,13 +273,6 @@ export class CodeGenState extends CodeGenBase implements SessionState {
273273 credentialStartUrl : AuthUtil . instance . startUrl ,
274274 } )
275275
276- action . tokenSource ?. token . onCancellationRequested ( ( ) => {
277- this . isCancellationRequested = true
278- if ( action . tokenSource ) {
279- this . tokenSource = action . tokenSource
280- }
281- } )
282-
283276 action . telemetry . setGenerateCodeIteration ( this . currentIteration )
284277 action . telemetry . setGenerateCodeLastInvocationTime ( )
285278 const codeGenerationId = randomUUID ( )
@@ -291,7 +284,7 @@ export class CodeGenState extends CodeGenBase implements SessionState {
291284 this . currentCodeGenerationId
292285 )
293286
294- if ( ! this . isCancellationRequested ) {
287+ if ( ! action . tokenSource ?. token . isCancellationRequested ) {
295288 action . messenger . sendAnswer ( {
296289 message : i18n ( 'AWS.amazonq.featureDev.pillText.generatingCode' ) ,
297290 type : 'answer-part' ,
@@ -309,9 +302,10 @@ export class CodeGenState extends CodeGenBase implements SessionState {
309302 codeGenerationId,
310303 telemetry : action . telemetry ,
311304 workspaceFolders : this . config . workspaceFolders ,
305+ isCancellationRequested : action . tokenSource ?. token . isCancellationRequested ,
312306 } )
313307
314- if ( codeGeneration && ! this . isCancellationRequested ) {
308+ if ( codeGeneration && ! action . tokenSource ?. token . isCancellationRequested ) {
315309 this . config . currentCodeGenerationId = codeGenerationId
316310 this . currentCodeGenerationId = codeGenerationId
317311 }
@@ -333,7 +327,7 @@ export class CodeGenState extends CodeGenBase implements SessionState {
333327 this . currentIteration + 1 ,
334328 this . codeGenerationRemainingIterationCount ,
335329 this . codeGenerationTotalIterationCount ,
336- this . tokenSource ,
330+ action . tokenSource ,
337331 this . currentCodeGenerationId
338332 )
339333 return {
@@ -489,16 +483,18 @@ export class PrepareCodeGenState implements SessionState {
489483 )
490484
491485 await uploadCode ( uploadUrl , zipFileBuffer , zipFileChecksum , kmsKeyArn )
492- action . messenger . sendAnswer ( {
493- message : i18n ( 'AWS.amazonq.featureDev.pillText.contextGatheringCompleted' ) ,
494- type : 'answer-part' ,
495- tabID : this . tabID ,
496- } )
486+ if ( ! action . tokenSource ?. token . isCancellationRequested ) {
487+ action . messenger . sendAnswer ( {
488+ message : i18n ( 'AWS.amazonq.featureDev.pillText.contextGatheringCompleted' ) ,
489+ type : 'answer-part' ,
490+ tabID : this . tabID ,
491+ } )
497492
498- action . messenger . sendUpdatePlaceholder (
499- this . tabID ,
500- i18n ( 'AWS.amazonq.featureDev.pillText.contextGatheringCompleted' )
501- )
493+ action . messenger . sendUpdatePlaceholder (
494+ this . tabID ,
495+ i18n ( 'AWS.amazonq.featureDev.pillText.contextGatheringCompleted' )
496+ )
497+ }
502498
503499 return uploadId
504500 } )
0 commit comments