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