@@ -12,6 +12,7 @@ import { IPlatformService } from '../../common/platform/types';
12
12
import { IProcessServiceFactory } from '../../common/process/types' ;
13
13
import { ITerminalHelper , TerminalShellType } from '../../common/terminal/types' ;
14
14
import { ICurrentProcess , IDisposable , Resource } from '../../common/types' ;
15
+ import { cacheResourceSpecificInterpreterData , clearCachedResourceSpecificIngterpreterData } from '../../common/utils/decorators' ;
15
16
import { OSType } from '../../common/utils/platform' ;
16
17
import { IEnvironmentVariablesProvider } from '../../common/variables/types' ;
17
18
import { EXTENSION_ROOT_DIR } from '../../constants' ;
@@ -21,6 +22,7 @@ import { PythonInterpreter } from '../contracts';
21
22
import { IEnvironmentActivationService } from './types' ;
22
23
23
24
const getEnvironmentPrefix = 'e8b39361-0157-4923-80e1-22d70d46dee6' ;
25
+ const cacheDuration = 10 * 60 * 1000 ;
24
26
export const getEnvironmentTimeout = 30000 ;
25
27
26
28
// The shell under which we'll execute activation scripts.
@@ -40,13 +42,16 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
40
42
@inject ( IProcessServiceFactory ) private processServiceFactory : IProcessServiceFactory ,
41
43
@inject ( ICurrentProcess ) private currentProcess : ICurrentProcess ,
42
44
@inject ( IEnvironmentVariablesProvider ) private readonly envVarsService : IEnvironmentVariablesProvider
43
- ) { }
45
+ ) {
46
+ this . envVarsService . onDidEnvironmentVariablesChange ( this . onDidEnvironmentVariablesChange , this , this . disposables ) ;
47
+ }
44
48
45
49
public dispose ( ) : void {
46
50
this . disposables . forEach ( d => d . dispose ( ) ) ;
47
51
}
48
52
@traceDecorators . verbose ( 'getActivatedEnvironmentVariables' , LogOptions . Arguments )
49
53
@captureTelemetry ( EventName . PYTHON_INTERPRETER_ACTIVATION_ENVIRONMENT_VARIABLES , { failed : false } , true )
54
+ @cacheResourceSpecificInterpreterData ( 'ActivatedEnvironmentVariables' , cacheDuration )
50
55
public async getActivatedEnvironmentVariables ( resource : Resource , interpreter ?: PythonInterpreter , allowExceptions ?: boolean ) : Promise < NodeJS . ProcessEnv | undefined > {
51
56
const shellInfo = defaultShells [ this . platform . osType ] ;
52
57
if ( ! shellInfo ) {
@@ -110,6 +115,9 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
110
115
}
111
116
}
112
117
}
118
+ protected onDidEnvironmentVariablesChange ( affectedResource : Resource ) {
119
+ clearCachedResourceSpecificIngterpreterData ( 'ActivatedEnvironmentVariables' , affectedResource ) ;
120
+ }
113
121
protected fixActivationCommands ( commands : string [ ] ) : string [ ] {
114
122
// Replace 'source ' with '. ' as that works in shell exec
115
123
return commands . map ( cmd => cmd . replace ( / ^ s o u r c e \s + / , '. ' ) ) ;
0 commit comments