@@ -11,14 +11,15 @@ import {
1111import { PythonEnvironment , PythonEnvironmentApi , PythonProject , PythonTerminalCreateOptions } from '../../api' ;
1212import { isActivatableEnvironment } from '../common/activation' ;
1313import { getConfiguration } from '../../common/workspace.apis' ;
14- import { getEnvironmentForTerminal , waitForShellIntegration } from './utils' ;
14+ import { getAutoActivationType , getEnvironmentForTerminal , waitForShellIntegration } from './utils' ;
1515import {
1616 DidChangeTerminalActivationStateEvent ,
1717 TerminalActivation ,
1818 TerminalActivationInternal ,
1919 TerminalEnvironment ,
2020} from './terminalActivationState' ;
2121import { getPythonApi } from '../pythonApi' ;
22+ import { traceInfo , traceVerbose } from '../../common/logging' ;
2223
2324export interface TerminalCreation {
2425 create ( environment : PythonEnvironment , options : PythonTerminalCreateOptions ) : Promise < Terminal > ;
@@ -97,26 +98,33 @@ export class TerminalManagerImpl implements TerminalManager {
9798 }
9899
99100 private async autoActivateOnTerminalOpen ( terminal : Terminal , environment : PythonEnvironment ) : Promise < void > {
100- const config = getConfiguration ( 'python' ) ;
101- if ( ! config . get < boolean > ( 'terminal.activateEnvironment' , false ) ) {
102- return ;
103- }
104-
105- if ( isActivatableEnvironment ( environment ) ) {
106- await withProgress (
107- {
108- location : ProgressLocation . Window ,
109- title : `Activating environment: ${ environment . environmentPath . fsPath } ` ,
110- } ,
111- async ( ) => {
112- await waitForShellIntegration ( terminal ) ;
113- await this . activate ( terminal , environment ) ;
114- } ,
101+ const actType = getAutoActivationType ( ) ;
102+ if ( actType === 'command' ) {
103+ if ( isActivatableEnvironment ( environment ) ) {
104+ await withProgress (
105+ {
106+ location : ProgressLocation . Window ,
107+ title : `Activating environment: ${ environment . environmentPath . fsPath } ` ,
108+ } ,
109+ async ( ) => {
110+ await waitForShellIntegration ( terminal ) ;
111+ await this . activate ( terminal , environment ) ;
112+ } ,
113+ ) ;
114+ } else {
115+ traceVerbose ( `Environment ${ environment . environmentPath . fsPath } is not activatable` ) ;
116+ }
117+ } else if ( actType === 'off' ) {
118+ traceInfo ( `"python-envs.terminal.autoActivationType" is set to "${ actType } ", skipping auto activation` ) ;
119+ } else if ( actType === 'startup' ) {
120+ traceInfo (
121+ `"python-envs.terminal.autoActivationType" is set to "${ actType } ", terminal should be activated by shell startup script` ,
115122 ) ;
116123 }
117124 }
118125
119126 public async create ( environment : PythonEnvironment , options : PythonTerminalCreateOptions ) : Promise < Terminal > {
127+ // https://github.com/microsoft/vscode-python-environments/issues/172
120128 // const name = options.name ?? `Python: ${environment.displayName}`;
121129 const newTerminal = createTerminal ( {
122130 name : options . name ,
@@ -214,8 +222,7 @@ export class TerminalManagerImpl implements TerminalManager {
214222 }
215223
216224 public async initialize ( api : PythonEnvironmentApi ) : Promise < void > {
217- const config = getConfiguration ( 'python' ) ;
218- if ( config . get < boolean > ( 'terminal.activateEnvInCurrentTerminal' , false ) ) {
225+ if ( getAutoActivationType ( ) === 'command' ) {
219226 await Promise . all (
220227 terminals ( ) . map ( async ( t ) => {
221228 this . skipActivationOnOpen . add ( t ) ;
0 commit comments