@@ -320,7 +320,12 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
320
320
321
321
const execution = new BackgroundTerminalExecution ( toolTerminal . instance , xterm , command ) ;
322
322
RunInTerminalTool . _backgroundExecutions . set ( termId , execution ) ;
323
+
323
324
outputAndIdle = await pollForOutputAndIdle ( execution , false , token , this . _languageModelsService ) ;
325
+ if ( token . isCancellationRequested ) {
326
+ throw new CancellationError ( ) ;
327
+ }
328
+
324
329
if ( ! outputAndIdle . terminalExecutionIdleBeforeTimeout ) {
325
330
outputAndIdle = await racePollingOrPrompt (
326
331
( ) => pollForOutputAndIdle ( execution , true , token , this . _languageModelsService ) ,
@@ -330,6 +335,9 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
330
335
this . _languageModelsService ,
331
336
execution
332
337
) ;
338
+ if ( token . isCancellationRequested ) {
339
+ throw new CancellationError ( ) ;
340
+ }
333
341
}
334
342
335
343
let resultText = (
@@ -351,11 +359,11 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
351
359
} ]
352
360
} ;
353
361
} catch ( e ) {
354
- error = 'threw' ;
355
362
if ( termId ) {
356
363
RunInTerminalTool . _backgroundExecutions . get ( termId ) ?. dispose ( ) ;
357
364
RunInTerminalTool . _backgroundExecutions . delete ( termId ) ;
358
365
}
366
+ error = e instanceof CancellationError ? 'canceled' : 'unexpectedException' ;
359
367
throw e ;
360
368
} finally {
361
369
store . dispose ( ) ;
@@ -402,6 +410,10 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
402
410
}
403
411
this . _logService . debug ( `RunInTerminalTool: Using \`${ strategy . type } \` execute strategy for command \`${ command } \`` ) ;
404
412
const executeResult = await strategy . execute ( command , token ) ;
413
+ if ( token . isCancellationRequested ) {
414
+ throw new CancellationError ( ) ;
415
+ }
416
+
405
417
this . _logService . debug ( `RunInTerminalTool: Finished \`${ strategy . type } \` execute strategy with exitCode \`${ executeResult . exitCode } \`, result.length \`${ executeResult . output ?. length } \`, error \`${ executeResult . error } \`` ) ;
406
418
outputLineCount = executeResult . output === undefined ? 0 : count ( executeResult . output . trim ( ) , '\n' ) + 1 ;
407
419
exitCode = executeResult . exitCode ;
@@ -419,7 +431,7 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
419
431
} catch ( e ) {
420
432
this . _logService . debug ( `RunInTerminalTool: Threw exception` ) ;
421
433
toolTerminal . instance . dispose ( ) ;
422
- error = 'threw ';
434
+ error = e instanceof CancellationError ? 'canceled' : 'unexpectedException ';
423
435
throw e ;
424
436
} finally {
425
437
store . dispose ( ) ;
0 commit comments