3
3
4
4
import { inject , injectable } from 'inversify' ;
5
5
import { Terminal , Uri } from 'vscode' ;
6
- import { IInterpreterService } from '../../interpreter/contracts' ;
6
+ import { ICondaService } from '../../interpreter/contracts' ;
7
7
import { IServiceContainer } from '../../ioc/types' ;
8
8
import { ITerminalManager , IWorkspaceService } from '../application/types' ;
9
9
import '../extensions' ;
10
10
import { IPlatformService } from '../platform/types' ;
11
+ import { IConfigurationService } from '../types' ;
12
+ import { CondaActivationCommandProvider } from './environmentActivationProviders/condaActivationProvider' ;
11
13
import { ITerminalActivationCommandProvider , ITerminalHelper , TerminalShellType } from './types' ;
12
14
13
15
// Types of shells can be found here:
14
16
// 1. https://wiki.ubuntu.com/ChangingShells
15
17
const IS_BASH = / ( b a s h .e x e $ | w s l .e x e $ | b a s h $ | z s h $ | k s h $ ) / i;
16
18
const IS_COMMAND = / c m d .e x e $ / i;
17
- const IS_POWERSHELL = / ( p o w e r s h e l l .e x e $ | p w s h $ | p o w e r s h e l l $ ) / i;
19
+ const IS_POWERSHELL = / ( p o w e r s h e l l .e x e $ | p o w e r s h e l l $ ) / i;
20
+ const IS_POWERSHELL_CORE = / ( p w s h .e x e $ | p w s h $ ) / i;
18
21
const IS_FISH = / ( f i s h $ ) / i;
19
22
const IS_CSHELL = / ( c s h $ ) / i;
20
23
@@ -29,6 +32,7 @@ export class TerminalHelper implements ITerminalHelper {
29
32
this . detectableShells . set ( TerminalShellType . commandPrompt , IS_COMMAND ) ;
30
33
this . detectableShells . set ( TerminalShellType . fish , IS_FISH ) ;
31
34
this . detectableShells . set ( TerminalShellType . cshell , IS_CSHELL ) ;
35
+ this . detectableShells . set ( TerminalShellType . powershellCore , IS_POWERSHELL_CORE ) ;
32
36
}
33
37
public createTerminal ( title ?: string ) : Terminal {
34
38
const terminalManager = this . serviceContainer . get < ITerminalManager > ( ITerminalManager ) ;
@@ -62,23 +66,33 @@ export class TerminalHelper implements ITerminalHelper {
62
66
return shellConfig . get < string > ( osSection ) ! ;
63
67
}
64
68
public buildCommandForTerminal ( terminalShellType : TerminalShellType , command : string , args : string [ ] ) {
65
- const isPowershell = terminalShellType === TerminalShellType . powershell ;
69
+ const isPowershell = terminalShellType === TerminalShellType . powershell || terminalShellType === TerminalShellType . powershellCore ;
66
70
const commandPrefix = isPowershell ? '& ' : '' ;
67
71
return `${ commandPrefix } ${ command . toCommandArgument ( ) } ${ args . join ( ' ' ) } ` . trim ( ) ;
68
72
}
69
73
public async getEnvironmentActivationCommands ( terminalShellType : TerminalShellType , resource ?: Uri ) : Promise < string [ ] | undefined > {
70
- const interpreterService = this . serviceContainer . get < IInterpreterService > ( IInterpreterService ) ;
71
- const interperterInfo = await interpreterService . getActiveInterpreter ( resource ) ;
72
- if ( ! interperterInfo ) {
74
+ const settings = this . serviceContainer . get < IConfigurationService > ( IConfigurationService ) . getSettings ( resource ) ;
75
+ const activateEnvironment = settings . terminal . activateEnvironment ;
76
+ if ( ! activateEnvironment ) {
73
77
return ;
74
78
}
75
79
80
+ // If we have a conda environment, then use that.
81
+ const isCondaEnvironment = await this . serviceContainer . get < ICondaService > ( ICondaService ) . isCondaEnvironment ( settings . pythonPath ) ;
82
+ if ( isCondaEnvironment ) {
83
+ const condaActivationProvider = new CondaActivationCommandProvider ( this . serviceContainer ) ;
84
+ const activationCommands = await condaActivationProvider . getActivationCommands ( resource , terminalShellType ) ;
85
+ if ( Array . isArray ( activationCommands ) ) {
86
+ return activationCommands ;
87
+ }
88
+ }
89
+
76
90
// Search from the list of providers.
77
91
const providers = this . serviceContainer . getAll < ITerminalActivationCommandProvider > ( ITerminalActivationCommandProvider ) ;
78
92
const supportedProviders = providers . filter ( provider => provider . isShellSupported ( terminalShellType ) ) ;
79
93
80
94
for ( const provider of supportedProviders ) {
81
- const activationCommands = await provider . getActivationCommands ( interperterInfo , terminalShellType ) ;
95
+ const activationCommands = await provider . getActivationCommands ( resource , terminalShellType ) ;
82
96
if ( Array . isArray ( activationCommands ) ) {
83
97
return activationCommands ;
84
98
}
0 commit comments