33
44import { inject , injectable } from 'inversify' ;
55import { Terminal , Uri } from 'vscode' ;
6- import { IInterpreterService } from '../../interpreter/contracts' ;
6+ import { ICondaService } from '../../interpreter/contracts' ;
77import { IServiceContainer } from '../../ioc/types' ;
88import { ITerminalManager , IWorkspaceService } from '../application/types' ;
99import '../extensions' ;
1010import { IPlatformService } from '../platform/types' ;
11+ import { IConfigurationService } from '../types' ;
12+ import { CondaActivationCommandProvider } from './environmentActivationProviders/condaActivationProvider' ;
1113import { ITerminalActivationCommandProvider , ITerminalHelper , TerminalShellType } from './types' ;
1214
1315// Types of shells can be found here:
1416// 1. https://wiki.ubuntu.com/ChangingShells
1517const 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;
1618const 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;
1821const IS_FISH = / ( f i s h $ ) / i;
1922const IS_CSHELL = / ( c s h $ ) / i;
2023
@@ -29,6 +32,7 @@ export class TerminalHelper implements ITerminalHelper {
2932 this . detectableShells . set ( TerminalShellType . commandPrompt , IS_COMMAND ) ;
3033 this . detectableShells . set ( TerminalShellType . fish , IS_FISH ) ;
3134 this . detectableShells . set ( TerminalShellType . cshell , IS_CSHELL ) ;
35+ this . detectableShells . set ( TerminalShellType . powershellCore , IS_POWERSHELL_CORE ) ;
3236 }
3337 public createTerminal ( title ?: string ) : Terminal {
3438 const terminalManager = this . serviceContainer . get < ITerminalManager > ( ITerminalManager ) ;
@@ -62,23 +66,33 @@ export class TerminalHelper implements ITerminalHelper {
6266 return shellConfig . get < string > ( osSection ) ! ;
6367 }
6468 public buildCommandForTerminal ( terminalShellType : TerminalShellType , command : string , args : string [ ] ) {
65- const isPowershell = terminalShellType === TerminalShellType . powershell ;
69+ const isPowershell = terminalShellType === TerminalShellType . powershell || terminalShellType === TerminalShellType . powershellCore ;
6670 const commandPrefix = isPowershell ? '& ' : '' ;
6771 return `${ commandPrefix } ${ command . toCommandArgument ( ) } ${ args . join ( ' ' ) } ` . trim ( ) ;
6872 }
6973 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 ) {
7377 return ;
7478 }
7579
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+
7690 // Search from the list of providers.
7791 const providers = this . serviceContainer . getAll < ITerminalActivationCommandProvider > ( ITerminalActivationCommandProvider ) ;
7892 const supportedProviders = providers . filter ( provider => provider . isShellSupported ( terminalShellType ) ) ;
7993
8094 for ( const provider of supportedProviders ) {
81- const activationCommands = await provider . getActivationCommands ( interperterInfo , terminalShellType ) ;
95+ const activationCommands = await provider . getActivationCommands ( resource , terminalShellType ) ;
8296 if ( Array . isArray ( activationCommands ) ) {
8397 return activationCommands ;
8498 }
0 commit comments