@@ -153,6 +153,7 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
153153
154154 private _activeTasks : IStringDictionary < IActiveTerminalData > ;
155155 private _busyTasks : IStringDictionary < Task > ;
156+ private _taskByMapKey : Map < string , Task > ;
156157 private _taskErrors : IStringDictionary < boolean > ; // Tracks which tasks had errors from problem matchers
157158 private _taskDependencies : IStringDictionary < string [ ] > ; // Tracks which tasks depend on which other tasks
158159 private _terminals : IStringDictionary < ITerminalData > ;
@@ -215,6 +216,7 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
215216
216217 this . _activeTasks = Object . create ( null ) ;
217218 this . _busyTasks = Object . create ( null ) ;
219+ this . _taskByMapKey = new Map ( ) ;
218220 this . _taskErrors = Object . create ( null ) ;
219221 this . _taskDependencies = Object . create ( null ) ;
220222 this . _terminals = Object . create ( null ) ;
@@ -523,6 +525,7 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
523525 this . _showTaskLoadErrors ( task ) ;
524526
525527 const mapKey = task . getMapKey ( ) ;
528+ this . _taskByMapKey . set ( mapKey , task ) ;
526529
527530 // It's important that we add this task's entry to _activeTasks before
528531 // any of the code in the then runs (see #180541 and #180578). Wrapping
@@ -1931,6 +1934,16 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
19311934 return activeTask . task ;
19321935 }
19331936 }
1937+ for ( const key in this . _terminals ) {
1938+ const terminalData = this . _terminals [ key ] ;
1939+ if ( terminalData . terminal ?. instanceId === instanceId ) {
1940+ const task = this . _taskByMapKey . get ( terminalData . lastTask ) ;
1941+ if ( task ) {
1942+ this . _log ( `TaskSystem.getTaskForTerminal found cached task (instanceId=${ instanceId } , mapKey=${ terminalData . lastTask } , label=${ task . _label } )` ) ;
1943+ return task ;
1944+ }
1945+ }
1946+ }
19341947 this . _log ( `TaskSystem.getTaskForTerminal found no active task (instanceId=${ instanceId } )` ) ;
19351948 return undefined ;
19361949 }
0 commit comments