@@ -4,6 +4,7 @@ import { Disposable, EventEmitter, ProgressLocation, Terminal, TerminalOptions,
44import { PythonEnvironment , PythonEnvironmentApi , PythonProject , PythonTerminalCreateOptions } from '../../api' ;
55import { ActivationStrings } from '../../common/localize' ;
66import { traceInfo , traceVerbose } from '../../common/logging' ;
7+ import { onDidStartTaskProcess } from '../../common/tasks.apis' ;
78import {
89 createTerminal ,
910 onDidChangeWindowState ,
@@ -68,6 +69,7 @@ export interface TerminalManager
6869export class TerminalManagerImpl implements TerminalManager {
6970 private disposables : Disposable [ ] = [ ] ;
7071 private skipActivationOnOpen = new Set < Terminal > ( ) ;
72+ private taskProcessIds = new Set < number > ( ) ;
7173 private shellSetup : Map < string , boolean > = new Map < string , boolean > ( ) ;
7274
7375 private onTerminalOpenedEmitter = new EventEmitter < Terminal > ( ) ;
@@ -96,10 +98,22 @@ export class TerminalManagerImpl implements TerminalManager {
9698 onDidCloseTerminal ( ( t : Terminal ) => {
9799 this . onTerminalClosedEmitter . fire ( t ) ;
98100 } ) ,
101+ onDidStartTaskProcess ( ( tp ) => {
102+ this . taskProcessIds . add ( tp . processId ) ;
103+ traceVerbose ( `Task process started with PID: ${ tp . processId } ` ) ;
104+ } ) ,
99105 this . onTerminalOpened ( async ( t ) => {
100106 if ( this . skipActivationOnOpen . has ( t ) || ( t . creationOptions as TerminalOptions ) ?. hideFromUser ) {
101107 return ;
102108 }
109+ // Wait briefly to allow onDidStartTaskProcess to fire
110+ await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ;
111+ const terminalProcessId = await t . processId ;
112+ if ( terminalProcessId && this . taskProcessIds . has ( terminalProcessId ) ) {
113+ traceVerbose ( `Skipping activation for task terminal with PID: ${ terminalProcessId } ` ) ;
114+ return ;
115+ }
116+
103117 let env = this . ta . getEnvironment ( t ) ;
104118 if ( ! env ) {
105119 const api = await getPythonApi ( ) ;
@@ -109,8 +123,13 @@ export class TerminalManagerImpl implements TerminalManager {
109123 await this . autoActivateOnTerminalOpen ( t , env ) ;
110124 }
111125 } ) ,
112- this . onTerminalClosed ( ( t ) => {
126+ this . onTerminalClosed ( async ( t ) => {
113127 this . skipActivationOnOpen . delete ( t ) ;
128+ const terminalProcessId = await t . processId ;
129+ if ( terminalProcessId && this . taskProcessIds . has ( terminalProcessId ) ) {
130+ this . taskProcessIds . delete ( terminalProcessId ) ;
131+ traceVerbose ( `Removed task process ID ${ terminalProcessId } for closed terminal` ) ;
132+ }
114133 } ) ,
115134 this . ta . onDidChangeTerminalActivationState ( ( e ) => {
116135 this . onDidChangeTerminalActivationStateEmitter . fire ( e ) ;
0 commit comments