@@ -147,7 +147,6 @@ abstract class CodeGenBase {
147
147
public tabID : string
148
148
) {
149
149
this . tokenSource = new vscode . CancellationTokenSource ( )
150
- this . isCancellationRequested = false
151
150
this . conversationId = config . conversationId
152
151
this . uploadId = config . uploadId
153
152
this . currentCodeGenerationId = config . currentCodeGenerationId || EmptyCodeGenID
@@ -159,12 +158,14 @@ abstract class CodeGenBase {
159
158
codeGenerationId,
160
159
telemetry : telemetry ,
161
160
workspaceFolders,
161
+ isCancellationRequested,
162
162
} : {
163
163
messenger : Messenger
164
164
fs : VirtualFileSystem
165
165
codeGenerationId : string
166
166
telemetry : TelemetryHelper
167
167
workspaceFolders : CurrentWsFolders
168
+ isCancellationRequested ?: boolean
168
169
} ) : Promise < {
169
170
newFiles : NewFileInfo [ ]
170
171
deletedFiles : DeletedFileInfo [ ]
@@ -174,7 +175,7 @@ abstract class CodeGenBase {
174
175
} > {
175
176
for (
176
177
let pollingIteration = 0 ;
177
- pollingIteration < this . pollCount && ! this . isCancellationRequested ;
178
+ pollingIteration < this . pollCount && ! isCancellationRequested ;
178
179
++ pollingIteration
179
180
) {
180
181
const codegenResult = await this . config . proxyClient . getCodeGeneration ( this . conversationId , codeGenerationId )
@@ -259,7 +260,7 @@ abstract class CodeGenBase {
259
260
}
260
261
}
261
262
}
262
- if ( ! this . isCancellationRequested ) {
263
+ if ( ! isCancellationRequested ) {
263
264
// still in progress
264
265
const errorMessage = i18n ( 'AWS.amazonq.featureDev.error.codeGen.timeout' )
265
266
throw new ToolkitError ( errorMessage , { code : 'CodeGenTimeout' } )
@@ -302,12 +303,10 @@ export class CodeGenState extends CodeGenBase implements SessionState {
302
303
} )
303
304
304
305
action . tokenSource ?. token . onCancellationRequested ( ( ) => {
306
+ this . isCancellationRequested = true
305
307
if ( action . tokenSource ) {
306
308
this . tokenSource = action . tokenSource
307
309
}
308
- this . isCancellationRequested = true
309
- action . tokenSource ?. dispose ( )
310
- action . tokenSource = undefined
311
310
} )
312
311
313
312
action . telemetry . setGenerateCodeIteration ( this . currentIteration )
@@ -321,7 +320,7 @@ export class CodeGenState extends CodeGenBase implements SessionState {
321
320
this . currentCodeGenerationId
322
321
)
323
322
324
- if ( ! this . isCancellationRequested ) {
323
+ if ( ! action . tokenSource ?. token . isCancellationRequested ) {
325
324
action . messenger . sendAnswer ( {
326
325
message : i18n ( 'AWS.amazonq.featureDev.pillText.generatingCode' ) ,
327
326
type : 'answer-part' ,
@@ -339,6 +338,7 @@ export class CodeGenState extends CodeGenBase implements SessionState {
339
338
codeGenerationId,
340
339
telemetry : action . telemetry ,
341
340
workspaceFolders : this . config . workspaceFolders ,
341
+ isCancellationRequested : action . tokenSource ?. token . isCancellationRequested ,
342
342
} )
343
343
344
344
if ( codeGeneration && ! action . tokenSource ?. token . isCancellationRequested ) {
@@ -375,7 +375,7 @@ export class CodeGenState extends CodeGenBase implements SessionState {
375
375
this . codeGenerationTotalIterationCount ,
376
376
action . uploadHistory ,
377
377
codeGenerationId ,
378
- this . tokenSource ,
378
+ action . tokenSource ,
379
379
this . currentCodeGenerationId
380
380
)
381
381
return {
0 commit comments