Skip to content

Commit 3cfaf44

Browse files
committed
fix(amazonqFeatureDev): use shared context from action to check cancellation
1 parent 7b7da92 commit 3cfaf44

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

packages/core/src/amazonqFeatureDev/session/sessionState.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ abstract class CodeGenBase {
147147
public tabID: string
148148
) {
149149
this.tokenSource = new vscode.CancellationTokenSource()
150-
this.isCancellationRequested = false
151150
this.conversationId = config.conversationId
152151
this.uploadId = config.uploadId
153152
this.currentCodeGenerationId = config.currentCodeGenerationId || EmptyCodeGenID
@@ -159,12 +158,14 @@ abstract class CodeGenBase {
159158
codeGenerationId,
160159
telemetry: telemetry,
161160
workspaceFolders,
161+
isCancellationRequested,
162162
}: {
163163
messenger: Messenger
164164
fs: VirtualFileSystem
165165
codeGenerationId: string
166166
telemetry: TelemetryHelper
167167
workspaceFolders: CurrentWsFolders
168+
isCancellationRequested?: boolean
168169
}): Promise<{
169170
newFiles: NewFileInfo[]
170171
deletedFiles: DeletedFileInfo[]
@@ -174,7 +175,7 @@ abstract class CodeGenBase {
174175
}> {
175176
for (
176177
let pollingIteration = 0;
177-
pollingIteration < this.pollCount && !this.isCancellationRequested;
178+
pollingIteration < this.pollCount && !isCancellationRequested;
178179
++pollingIteration
179180
) {
180181
const codegenResult = await this.config.proxyClient.getCodeGeneration(this.conversationId, codeGenerationId)
@@ -259,7 +260,7 @@ abstract class CodeGenBase {
259260
}
260261
}
261262
}
262-
if (!this.isCancellationRequested) {
263+
if (!isCancellationRequested) {
263264
// still in progress
264265
const errorMessage = i18n('AWS.amazonq.featureDev.error.codeGen.timeout')
265266
throw new ToolkitError(errorMessage, { code: 'CodeGenTimeout' })
@@ -302,12 +303,10 @@ export class CodeGenState extends CodeGenBase implements SessionState {
302303
})
303304

304305
action.tokenSource?.token.onCancellationRequested(() => {
306+
this.isCancellationRequested = true
305307
if (action.tokenSource) {
306308
this.tokenSource = action.tokenSource
307309
}
308-
this.isCancellationRequested = true
309-
action.tokenSource?.dispose()
310-
action.tokenSource = undefined
311310
})
312311

313312
action.telemetry.setGenerateCodeIteration(this.currentIteration)
@@ -321,7 +320,7 @@ export class CodeGenState extends CodeGenBase implements SessionState {
321320
this.currentCodeGenerationId
322321
)
323322

324-
if (!this.isCancellationRequested) {
323+
if (!action.tokenSource?.token.isCancellationRequested) {
325324
action.messenger.sendAnswer({
326325
message: i18n('AWS.amazonq.featureDev.pillText.generatingCode'),
327326
type: 'answer-part',
@@ -339,6 +338,7 @@ export class CodeGenState extends CodeGenBase implements SessionState {
339338
codeGenerationId,
340339
telemetry: action.telemetry,
341340
workspaceFolders: this.config.workspaceFolders,
341+
isCancellationRequested: action.tokenSource?.token.isCancellationRequested,
342342
})
343343

344344
if (codeGeneration && !action.tokenSource?.token.isCancellationRequested) {
@@ -375,7 +375,7 @@ export class CodeGenState extends CodeGenBase implements SessionState {
375375
this.codeGenerationTotalIterationCount,
376376
action.uploadHistory,
377377
codeGenerationId,
378-
this.tokenSource,
378+
action.tokenSource,
379379
this.currentCodeGenerationId
380380
)
381381
return {

0 commit comments

Comments
 (0)