Skip to content

Commit

Permalink
Reactivate terminals if .env file changes (#22969)
Browse files Browse the repository at this point in the history
Closes #22920
  • Loading branch information
Kartik Raj authored and anthonykim1 committed Feb 29, 2024
1 parent 1796450 commit 2c09414
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/client/terminals/envCollectionActivation/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { defaultShells } from '../../interpreter/activation/service';
import { IEnvironmentActivationService } from '../../interpreter/activation/types';
import { EnvironmentType, PythonEnvironment } from '../../pythonEnvironments/info';
import { getSearchPathEnvVarNames } from '../../common/utils/exec';
import { EnvironmentVariables } from '../../common/variables/types';
import { EnvironmentVariables, IEnvironmentVariablesProvider } from '../../common/variables/types';
import { TerminalShellType } from '../../common/terminal/types';
import { OSType } from '../../common/utils/platform';
import { normCase } from '../../common/platform/fs-paths';
Expand Down Expand Up @@ -81,6 +81,8 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
@inject(ITerminalDeactivateService) private readonly terminalDeactivateService: ITerminalDeactivateService,
@inject(IPathUtils) private readonly pathUtils: IPathUtils,
@inject(IShellIntegrationService) private readonly shellIntegrationService: IShellIntegrationService,
@inject(IEnvironmentVariablesProvider)
private readonly environmentVariablesProvider: IEnvironmentVariablesProvider,
) {
this.separator = platform.osType === OSType.Windows ? ';' : ':';
this.progressService = new ProgressService(this.shell);
Expand Down Expand Up @@ -119,6 +121,13 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
this,
this.disposables,
);
this.environmentVariablesProvider.onDidEnvironmentVariablesChange(
async (r: Resource) => {
await this._applyCollection(r).ignoreErrors();
},
this,
this.disposables,
);
this.applicationEnvironment.onDidChangeShell(
async (shell: string) => {
this.processEnvVars = undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { PathUtils } from '../../../client/common/platform/pathUtils';
import { PythonEnvType } from '../../../client/pythonEnvironments/base/info';
import { PythonEnvironment } from '../../../client/pythonEnvironments/info';
import { IShellIntegrationService, ITerminalDeactivateService } from '../../../client/terminals/types';
import { IEnvironmentVariablesProvider } from '../../../client/common/variables/types';

suite('Terminal Environment Variable Collection Service', () => {
let platform: IPlatformService;
Expand Down Expand Up @@ -74,6 +75,7 @@ suite('Terminal Environment Variable Collection Service', () => {
interpreterService = mock<IInterpreterService>();
context = mock<IExtensionContext>();
shell = mock<IApplicationShell>();
const envVarProvider = mock<IEnvironmentVariablesProvider>();
shellIntegrationService = mock<IShellIntegrationService>();
when(shellIntegrationService.isWorking()).thenResolve(true);
globalCollection = mock<GlobalEnvironmentVariableCollection>();
Expand Down Expand Up @@ -113,6 +115,7 @@ suite('Terminal Environment Variable Collection Service', () => {
instance(terminalDeactivateService),
new PathUtils(getOSType() === OSType.Windows),
instance(shellIntegrationService),
instance(envVarProvider),
);
});

Expand Down

0 comments on commit 2c09414

Please sign in to comment.