@@ -10,7 +10,7 @@ import { IWorkspaceService } from '../../common/application/types';
10
10
import '../../common/extensions' ;
11
11
import { IPlatformService } from '../../common/platform/types' ;
12
12
import { ITerminalService , ITerminalServiceFactory } from '../../common/terminal/types' ;
13
- import { IConfigurationService , IDisposableRegistry } from '../../common/types' ;
13
+ import { IConfigurationService , IDisposableRegistry , Resource } from '../../common/types' ;
14
14
import { IInterpreterService } from '../../interpreter/contracts' ;
15
15
import { buildPythonExecInfo , PythonExecInfo } from '../../pythonEnvironments/exec' ;
16
16
import { ICodeExecutionService } from '../../terminals/types' ;
@@ -19,7 +19,6 @@ 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
22
private replActive ?: Promise < boolean > ;
24
23
constructor (
25
24
@inject ( ITerminalServiceFactory ) protected readonly terminalServiceFactory : ITerminalServiceFactory ,
@@ -30,35 +29,41 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService {
30
29
@inject ( IInterpreterService ) protected readonly interpreterService : IInterpreterService ,
31
30
) { }
32
31
33
- public async executeFile ( file : Uri ) {
32
+ public async executeFile ( file : Uri , options ?: { newTerminalPerFile : boolean } ) {
34
33
await this . setCwdForFileExecution ( file ) ;
35
34
const { command, args } = await this . getExecuteFileArgs ( file , [
36
35
file . fsPath . fileToCommandArgumentForPythonExt ( ) ,
37
36
] ) ;
38
37
39
- await this . getTerminalService ( file ) . sendCommand ( command , args ) ;
38
+ await this . getTerminalService ( file , options ) . sendCommand ( command , args ) ;
40
39
}
41
40
42
41
public async execute ( code : string , resource ?: Uri ) : Promise < void > {
43
42
if ( ! code || code . trim ( ) . length === 0 ) {
44
43
return ;
45
44
}
46
45
47
- await this . initializeRepl ( ) ;
46
+ await this . initializeRepl ( resource ) ;
48
47
await this . getTerminalService ( resource ) . sendText ( code ) ;
49
48
}
50
- public async initializeRepl ( resource ?: Uri ) {
49
+ public async initializeRepl ( resource : Resource ) {
50
+ const terminalService = this . getTerminalService ( resource ) ;
51
51
if ( this . replActive && ( await this . replActive ) ) {
52
- await this . _terminalService . show ( ) ;
52
+ await terminalService . show ( ) ;
53
53
return ;
54
54
}
55
55
this . replActive = new Promise < boolean > ( async ( resolve ) => {
56
56
const replCommandArgs = await this . getExecutableInfo ( resource ) ;
57
- await this . getTerminalService ( resource ) . sendCommand ( replCommandArgs . command , replCommandArgs . args ) ;
57
+ terminalService . sendCommand ( replCommandArgs . command , replCommandArgs . args ) ;
58
58
59
59
// Give python repl time to start before we start sending text.
60
60
setTimeout ( ( ) => resolve ( true ) , 1000 ) ;
61
61
} ) ;
62
+ this . disposables . push (
63
+ terminalService . onDidCloseTerminal ( ( ) => {
64
+ this . replActive = undefined ;
65
+ } ) ,
66
+ ) ;
62
67
63
68
await this . replActive ;
64
69
}
@@ -76,19 +81,12 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService {
76
81
public async getExecuteFileArgs ( resource ?: Uri , executeArgs : string [ ] = [ ] ) : Promise < PythonExecInfo > {
77
82
return this . getExecutableInfo ( resource , executeArgs ) ;
78
83
}
79
- 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 ;
84
+ private getTerminalService ( resource : Resource , options ?: { newTerminalPerFile : boolean } ) : ITerminalService {
85
+ return this . terminalServiceFactory . getTerminalService ( {
86
+ resource,
87
+ title : this . terminalTitle ,
88
+ newTerminalPerFile : options ?. newTerminalPerFile ,
89
+ } ) ;
92
90
}
93
91
private async setCwdForFileExecution ( file : Uri ) {
94
92
const pythonSettings = this . configurationService . getSettings ( file ) ;
0 commit comments