@@ -19,8 +19,7 @@ import { ICodeExecutionService } from '../../terminals/types';
1919export class TerminalCodeExecutionProvider implements ICodeExecutionService {
2020 private hasRanOutsideCurrentDrive = false ;
2121 protected terminalTitle ! : string ;
22- private _terminalService ! : ITerminalService ;
23- private replActive ?: Promise < boolean > ;
22+ private replActive = new Map < string , Promise < boolean > > ( ) ;
2423 constructor (
2524 @inject ( ITerminalServiceFactory ) protected readonly terminalServiceFactory : ITerminalServiceFactory ,
2625 @inject ( IConfigurationService ) protected readonly configurationService : IConfigurationService ,
@@ -48,19 +47,27 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService {
4847 await this . getTerminalService ( resource ) . sendText ( code ) ;
4948 }
5049 public async initializeRepl ( resource ?: Uri ) {
51- if ( this . replActive && ( await this . replActive ) ) {
52- await this . _terminalService . show ( ) ;
50+ const terminalService = this . getTerminalService ( resource ) ;
51+ let replActive = this . replActive . get ( resource ?. fsPath || '' ) ;
52+ if ( replActive && ( await replActive ) ) {
53+ await terminalService . show ( ) ;
5354 return ;
5455 }
55- this . replActive = new Promise < boolean > ( async ( resolve ) => {
56+ replActive = new Promise < boolean > ( async ( resolve ) => {
5657 const replCommandArgs = await this . getExecutableInfo ( resource ) ;
57- await this . getTerminalService ( resource ) . sendCommand ( replCommandArgs . command , replCommandArgs . args ) ;
58+ terminalService . sendCommand ( replCommandArgs . command , replCommandArgs . args ) ;
5859
5960 // Give python repl time to start before we start sending text.
6061 setTimeout ( ( ) => resolve ( true ) , 1000 ) ;
6162 } ) ;
63+ this . replActive . set ( resource ?. fsPath || '' , replActive ) ;
64+ this . disposables . push (
65+ terminalService . onDidCloseTerminal ( ( ) => {
66+ this . replActive . delete ( resource ?. fsPath || '' ) ;
67+ } ) ,
68+ ) ;
6269
63- await this . replActive ;
70+ await replActive ;
6471 }
6572
6673 public async getExecutableInfo ( resource ?: Uri , args : string [ ] = [ ] ) : Promise < PythonExecInfo > {
@@ -77,18 +84,10 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService {
7784 return this . getExecutableInfo ( resource , executeArgs ) ;
7885 }
7986 private getTerminalService ( resource ?: Uri ) : ITerminalService {
80- if ( ! this . _terminalService ) {
81- this . _terminalService = this . terminalServiceFactory . getTerminalService ( {
82- resource,
83- title : this . terminalTitle ,
84- } ) ;
85- this . disposables . push (
86- this . _terminalService . onDidCloseTerminal ( ( ) => {
87- this . replActive = undefined ;
88- } ) ,
89- ) ;
90- }
91- return this . _terminalService ;
87+ return this . terminalServiceFactory . getTerminalService ( {
88+ resource,
89+ title : this . terminalTitle ,
90+ } ) ;
9291 }
9392 private async setCwdForFileExecution ( file : Uri ) {
9493 const pythonSettings = this . configurationService . getSettings ( file ) ;
0 commit comments