Skip to content

Commit 7e35060

Browse files
author
Kartik Raj
authored
Reactivate terminals if .env file changes (#22969)
Closes #22920
1 parent e6c859d commit 7e35060

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/client/terminals/envCollectionActivation/service.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { defaultShells } from '../../interpreter/activation/service';
3232
import { IEnvironmentActivationService } from '../../interpreter/activation/types';
3333
import { EnvironmentType, PythonEnvironment } from '../../pythonEnvironments/info';
3434
import { getSearchPathEnvVarNames } from '../../common/utils/exec';
35-
import { EnvironmentVariables } from '../../common/variables/types';
35+
import { EnvironmentVariables, IEnvironmentVariablesProvider } from '../../common/variables/types';
3636
import { TerminalShellType } from '../../common/terminal/types';
3737
import { OSType } from '../../common/utils/platform';
3838
import { normCase } from '../../common/platform/fs-paths';
@@ -81,6 +81,8 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
8181
@inject(ITerminalDeactivateService) private readonly terminalDeactivateService: ITerminalDeactivateService,
8282
@inject(IPathUtils) private readonly pathUtils: IPathUtils,
8383
@inject(IShellIntegrationService) private readonly shellIntegrationService: IShellIntegrationService,
84+
@inject(IEnvironmentVariablesProvider)
85+
private readonly environmentVariablesProvider: IEnvironmentVariablesProvider,
8486
) {
8587
this.separator = platform.osType === OSType.Windows ? ';' : ':';
8688
this.progressService = new ProgressService(this.shell);
@@ -119,6 +121,13 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
119121
this,
120122
this.disposables,
121123
);
124+
this.environmentVariablesProvider.onDidEnvironmentVariablesChange(
125+
async (r: Resource) => {
126+
await this._applyCollection(r).ignoreErrors();
127+
},
128+
this,
129+
this.disposables,
130+
);
122131
this.applicationEnvironment.onDidChangeShell(
123132
async (shell: string) => {
124133
this.processEnvVars = undefined;

src/test/interpreters/activation/terminalEnvVarCollectionService.unit.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { PathUtils } from '../../../client/common/platform/pathUtils';
3838
import { PythonEnvType } from '../../../client/pythonEnvironments/base/info';
3939
import { PythonEnvironment } from '../../../client/pythonEnvironments/info';
4040
import { IShellIntegrationService, ITerminalDeactivateService } from '../../../client/terminals/types';
41+
import { IEnvironmentVariablesProvider } from '../../../client/common/variables/types';
4142

4243
suite('Terminal Environment Variable Collection Service', () => {
4344
let platform: IPlatformService;
@@ -74,6 +75,7 @@ suite('Terminal Environment Variable Collection Service', () => {
7475
interpreterService = mock<IInterpreterService>();
7576
context = mock<IExtensionContext>();
7677
shell = mock<IApplicationShell>();
78+
const envVarProvider = mock<IEnvironmentVariablesProvider>();
7779
shellIntegrationService = mock<IShellIntegrationService>();
7880
when(shellIntegrationService.isWorking()).thenResolve(true);
7981
globalCollection = mock<GlobalEnvironmentVariableCollection>();
@@ -113,6 +115,7 @@ suite('Terminal Environment Variable Collection Service', () => {
113115
instance(terminalDeactivateService),
114116
new PathUtils(getOSType() === OSType.Windows),
115117
instance(shellIntegrationService),
118+
instance(envVarProvider),
116119
);
117120
});
118121

0 commit comments

Comments
 (0)