@@ -19,8 +19,7 @@ import { ICodeExecutionService } from '../../terminals/types';
19
19
export class TerminalCodeExecutionProvider implements ICodeExecutionService {
20
20
private hasRanOutsideCurrentDrive = false ;
21
21
protected terminalTitle ! : string ;
22
- private _terminalService ! : ITerminalService ;
23
- private replActive ?: Promise < boolean > ;
22
+ private replActive = new Map < string , Promise < boolean > > ( ) ;
24
23
constructor (
25
24
@inject ( ITerminalServiceFactory ) protected readonly terminalServiceFactory : ITerminalServiceFactory ,
26
25
@inject ( IConfigurationService ) protected readonly configurationService : IConfigurationService ,
@@ -48,19 +47,27 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService {
48
47
await this . getTerminalService ( resource ) . sendText ( code ) ;
49
48
}
50
49
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 ( ) ;
53
54
return ;
54
55
}
55
- this . replActive = new Promise < boolean > ( async ( resolve ) => {
56
+ replActive = new Promise < boolean > ( async ( resolve ) => {
56
57
const replCommandArgs = await this . getExecutableInfo ( resource ) ;
57
- await this . getTerminalService ( resource ) . sendCommand ( replCommandArgs . command , replCommandArgs . args ) ;
58
+ terminalService . sendCommand ( replCommandArgs . command , replCommandArgs . args ) ;
58
59
59
60
// Give python repl time to start before we start sending text.
60
61
setTimeout ( ( ) => resolve ( true ) , 1000 ) ;
61
62
} ) ;
63
+ this . replActive . set ( resource ?. fsPath || '' , replActive ) ;
64
+ this . disposables . push (
65
+ terminalService . onDidCloseTerminal ( ( ) => {
66
+ this . replActive . delete ( resource ?. fsPath || '' ) ;
67
+ } ) ,
68
+ ) ;
62
69
63
- await this . replActive ;
70
+ await replActive ;
64
71
}
65
72
66
73
public async getExecutableInfo ( resource ?: Uri , args : string [ ] = [ ] ) : Promise < PythonExecInfo > {
@@ -77,18 +84,10 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService {
77
84
return this . getExecutableInfo ( resource , executeArgs ) ;
78
85
}
79
86
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
+ } ) ;
92
91
}
93
92
private async setCwdForFileExecution ( file : Uri ) {
94
93
const pythonSettings = this . configurationService . getSettings ( file ) ;
0 commit comments