@@ -120,6 +120,7 @@ abstract class CodeGenBase {
120120 public readonly conversationId : string
121121 public readonly uploadId : string
122122 public currentCodeGenerationId ?: string
123+ public isCancellationRequested ?: boolean
123124
124125 constructor (
125126 protected config : SessionStateConfig ,
@@ -137,14 +138,12 @@ abstract class CodeGenBase {
137138 codeGenerationId,
138139 telemetry : telemetry ,
139140 workspaceFolders,
140- isCancellationRequested,
141141 } : {
142142 messenger : Messenger
143143 fs : VirtualFileSystem
144144 codeGenerationId : string
145145 telemetry : TelemetryHelper
146146 workspaceFolders : CurrentWsFolders
147- isCancellationRequested ?: boolean
148147 } ) : Promise < {
149148 newFiles : NewFileInfo [ ]
150149 deletedFiles : DeletedFileInfo [ ]
@@ -154,7 +153,7 @@ abstract class CodeGenBase {
154153 } > {
155154 for (
156155 let pollingIteration = 0 ;
157- pollingIteration < this . pollCount && ! isCancellationRequested ;
156+ pollingIteration < this . pollCount && ! this . isCancellationRequested ;
158157 ++ pollingIteration
159158 ) {
160159 const codegenResult = await this . config . proxyClient . getCodeGeneration ( this . conversationId , codeGenerationId )
@@ -230,7 +229,7 @@ abstract class CodeGenBase {
230229 }
231230 }
232231 }
233- if ( ! isCancellationRequested ) {
232+ if ( ! this . isCancellationRequested ) {
234233 // still in progress
235234 const errorMessage = i18n ( 'AWS.amazonq.featureDev.error.codeGen.timeout' )
236235 throw new ToolkitError ( errorMessage , { code : 'CodeGenTimeout' } )
@@ -260,6 +259,12 @@ export class CodeGenState extends CodeGenBase implements SessionState {
260259 async interact ( action : SessionStateAction ) : Promise < SessionStateInteraction > {
261260 return telemetry . amazonq_codeGenerationInvoke . run ( async ( span ) => {
262261 try {
262+ action . tokenSource ?. token . onCancellationRequested ( ( ) => {
263+ this . isCancellationRequested = true
264+ if ( action . tokenSource ) {
265+ this . tokenSource = action . tokenSource
266+ }
267+ } )
263268 span . record ( {
264269 amazonqConversationId : this . config . conversationId ,
265270 credentialStartUrl : AuthUtil . instance . startUrl ,
@@ -276,7 +281,7 @@ export class CodeGenState extends CodeGenBase implements SessionState {
276281 this . currentCodeGenerationId
277282 )
278283
279- if ( ! action . tokenSource ?. token . isCancellationRequested ) {
284+ if ( ! this . isCancellationRequested ) {
280285 action . messenger . sendAnswer ( {
281286 message : i18n ( 'AWS.amazonq.featureDev.pillText.generatingCode' ) ,
282287 type : 'answer-part' ,
@@ -294,7 +299,6 @@ export class CodeGenState extends CodeGenBase implements SessionState {
294299 codeGenerationId,
295300 telemetry : action . telemetry ,
296301 workspaceFolders : this . config . workspaceFolders ,
297- isCancellationRequested : action . tokenSource ?. token . isCancellationRequested ,
298302 } )
299303
300304 if ( codeGeneration && ! action . tokenSource ?. token . isCancellationRequested ) {
0 commit comments