@@ -116,7 +116,6 @@ abstract class CodeGenBase {
116116 private pollCount = 180
117117 private requestDelay = 10000
118118 public tokenSource : vscode . CancellationTokenSource
119- public isCancellationRequested : boolean
120119 public phase : SessionStatePhase = DevPhase . CODEGEN
121120 public readonly conversationId : string
122121 public readonly uploadId : string
@@ -127,7 +126,6 @@ abstract class CodeGenBase {
127126 public tabID : string
128127 ) {
129128 this . tokenSource = new vscode . CancellationTokenSource ( )
130- this . isCancellationRequested = false
131129 this . conversationId = config . conversationId
132130 this . uploadId = config . uploadId
133131 this . currentCodeGenerationId = config . currentCodeGenerationId || EmptyCodeGenID
@@ -139,12 +137,14 @@ abstract class CodeGenBase {
139137 codeGenerationId,
140138 telemetry : telemetry ,
141139 workspaceFolders,
140+ isCancellationRequested,
142141 } : {
143142 messenger : Messenger
144143 fs : VirtualFileSystem
145144 codeGenerationId : string
146145 telemetry : TelemetryHelper
147146 workspaceFolders : CurrentWsFolders
147+ isCancellationRequested ?: boolean
148148 } ) : Promise < {
149149 newFiles : NewFileInfo [ ]
150150 deletedFiles : DeletedFileInfo [ ]
@@ -154,7 +154,7 @@ abstract class CodeGenBase {
154154 } > {
155155 for (
156156 let pollingIteration = 0 ;
157- pollingIteration < this . pollCount && ! this . isCancellationRequested ;
157+ pollingIteration < this . pollCount && ! isCancellationRequested ;
158158 ++ pollingIteration
159159 ) {
160160 const codegenResult = await this . config . proxyClient . getCodeGeneration ( this . conversationId , codeGenerationId )
@@ -230,7 +230,7 @@ abstract class CodeGenBase {
230230 }
231231 }
232232 }
233- if ( ! this . isCancellationRequested ) {
233+ if ( ! isCancellationRequested ) {
234234 // still in progress
235235 const errorMessage = i18n ( 'AWS.amazonq.featureDev.error.codeGen.timeout' )
236236 throw new ToolkitError ( errorMessage , { code : 'CodeGenTimeout' } )
@@ -265,13 +265,6 @@ export class CodeGenState extends CodeGenBase implements SessionState {
265265 credentialStartUrl : AuthUtil . instance . startUrl ,
266266 } )
267267
268- action . tokenSource ?. token . onCancellationRequested ( ( ) => {
269- this . isCancellationRequested = true
270- if ( action . tokenSource ) {
271- this . tokenSource = action . tokenSource
272- }
273- } )
274-
275268 action . telemetry . setGenerateCodeIteration ( this . currentIteration )
276269 action . telemetry . setGenerateCodeLastInvocationTime ( )
277270 const codeGenerationId = randomUUID ( )
@@ -283,7 +276,7 @@ export class CodeGenState extends CodeGenBase implements SessionState {
283276 this . currentCodeGenerationId
284277 )
285278
286- if ( ! this . isCancellationRequested ) {
279+ if ( ! action . tokenSource ?. token . isCancellationRequested ) {
287280 action . messenger . sendAnswer ( {
288281 message : i18n ( 'AWS.amazonq.featureDev.pillText.generatingCode' ) ,
289282 type : 'answer-part' ,
@@ -301,9 +294,10 @@ export class CodeGenState extends CodeGenBase implements SessionState {
301294 codeGenerationId,
302295 telemetry : action . telemetry ,
303296 workspaceFolders : this . config . workspaceFolders ,
297+ isCancellationRequested : action . tokenSource ?. token . isCancellationRequested ,
304298 } )
305299
306- if ( codeGeneration && ! this . isCancellationRequested ) {
300+ if ( codeGeneration && ! action . tokenSource ?. token . isCancellationRequested ) {
307301 this . config . currentCodeGenerationId = codeGenerationId
308302 this . currentCodeGenerationId = codeGenerationId
309303 }
@@ -325,7 +319,7 @@ export class CodeGenState extends CodeGenBase implements SessionState {
325319 this . currentIteration + 1 ,
326320 this . codeGenerationRemainingIterationCount ,
327321 this . codeGenerationTotalIterationCount ,
328- this . tokenSource ,
322+ action . tokenSource ,
329323 this . currentCodeGenerationId
330324 )
331325 return {
@@ -481,16 +475,18 @@ export class PrepareCodeGenState implements SessionState {
481475 )
482476
483477 await uploadCode ( uploadUrl , zipFileBuffer , zipFileChecksum , kmsKeyArn )
484- action . messenger . sendAnswer ( {
485- message : i18n ( 'AWS.amazonq.featureDev.pillText.contextGatheringCompleted' ) ,
486- type : 'answer-part' ,
487- tabID : this . tabID ,
488- } )
478+ if ( ! action . tokenSource ?. token . isCancellationRequested ) {
479+ action . messenger . sendAnswer ( {
480+ message : i18n ( 'AWS.amazonq.featureDev.pillText.contextGatheringCompleted' ) ,
481+ type : 'answer-part' ,
482+ tabID : this . tabID ,
483+ } )
489484
490- action . messenger . sendUpdatePlaceholder (
491- this . tabID ,
492- i18n ( 'AWS.amazonq.featureDev.pillText.contextGatheringCompleted' )
493- )
485+ action . messenger . sendUpdatePlaceholder (
486+ this . tabID ,
487+ i18n ( 'AWS.amazonq.featureDev.pillText.contextGatheringCompleted' )
488+ )
489+ }
494490
495491 return uploadId
496492 } )
0 commit comments