@@ -12,6 +12,7 @@ import { IPlatformService } from '../../common/platform/types';
1212import { IProcessServiceFactory } from '../../common/process/types' ;
1313import { ITerminalHelper , TerminalShellType } from '../../common/terminal/types' ;
1414import { ICurrentProcess , IDisposable , Resource } from '../../common/types' ;
15+ import { cacheResourceSpecificInterpreterData , clearCachedResourceSpecificIngterpreterData } from '../../common/utils/decorators' ;
1516import { OSType } from '../../common/utils/platform' ;
1617import { IEnvironmentVariablesProvider } from '../../common/variables/types' ;
1718import { EXTENSION_ROOT_DIR } from '../../constants' ;
@@ -21,6 +22,7 @@ import { PythonInterpreter } from '../contracts';
2122import { IEnvironmentActivationService } from './types' ;
2223
2324const getEnvironmentPrefix = 'e8b39361-0157-4923-80e1-22d70d46dee6' ;
25+ const cacheDuration = 10 * 60 * 1000 ;
2426export const getEnvironmentTimeout = 30000 ;
2527
2628// The shell under which we'll execute activation scripts.
@@ -40,13 +42,16 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
4042 @inject ( IProcessServiceFactory ) private processServiceFactory : IProcessServiceFactory ,
4143 @inject ( ICurrentProcess ) private currentProcess : ICurrentProcess ,
4244 @inject ( IEnvironmentVariablesProvider ) private readonly envVarsService : IEnvironmentVariablesProvider
43- ) { }
45+ ) {
46+ this . envVarsService . onDidEnvironmentVariablesChange ( this . onDidEnvironmentVariablesChange , this , this . disposables ) ;
47+ }
4448
4549 public dispose ( ) : void {
4650 this . disposables . forEach ( d => d . dispose ( ) ) ;
4751 }
4852 @traceDecorators . verbose ( 'getActivatedEnvironmentVariables' , LogOptions . Arguments )
4953 @captureTelemetry ( EventName . PYTHON_INTERPRETER_ACTIVATION_ENVIRONMENT_VARIABLES , { failed : false } , true )
54+ @cacheResourceSpecificInterpreterData ( 'ActivatedEnvironmentVariables' , cacheDuration )
5055 public async getActivatedEnvironmentVariables ( resource : Resource , interpreter ?: PythonInterpreter , allowExceptions ?: boolean ) : Promise < NodeJS . ProcessEnv | undefined > {
5156 const shellInfo = defaultShells [ this . platform . osType ] ;
5257 if ( ! shellInfo ) {
@@ -110,6 +115,9 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
110115 }
111116 }
112117 }
118+ protected onDidEnvironmentVariablesChange ( affectedResource : Resource ) {
119+ clearCachedResourceSpecificIngterpreterData ( 'ActivatedEnvironmentVariables' , affectedResource ) ;
120+ }
113121 protected fixActivationCommands ( commands : string [ ] ) : string [ ] {
114122 // Replace 'source ' with '. ' as that works in shell exec
115123 return commands . map ( cmd => cmd . replace ( / ^ s o u r c e \s + / , '. ' ) ) ;
0 commit comments