Skip to content

Commit 7aa6660

Browse files
author
Kartik Raj
authored
Clear environment collection only after all async operations are done (#21975)
For #20950
1 parent 91b2c11 commit 7aa6660

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/client/interpreter/activation/terminalEnvVarCollectionService.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,8 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
127127
const workspaceFolder = this.getWorkspaceFolder(resource);
128128
const settings = this.configurationService.getSettings(resource);
129129
const envVarCollection = this.getEnvironmentVariableCollection({ workspaceFolder });
130-
// Clear any previously set env vars from collection
131-
envVarCollection.clear();
132130
if (!settings.terminal.activateEnvironment) {
131+
envVarCollection.clear();
133132
traceVerbose('Activating environments in terminal is disabled for', resource?.fsPath);
134133
return;
135134
}
@@ -150,6 +149,7 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
150149
return;
151150
}
152151
await this.trackTerminalPrompt(shell, resource, env);
152+
envVarCollection.clear();
153153
this.processEnvVars = undefined;
154154
return;
155155
}
@@ -164,6 +164,8 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
164164
// PS1 in some cases is a shell variable (not an env variable) so "env" might not contain it, calculate it in that case.
165165
env.PS1 = await this.getPS1(shell, resource, env);
166166

167+
// Clear any previously set env vars from collection
168+
envVarCollection.clear();
167169
Object.keys(env).forEach((key) => {
168170
if (shouldSkip(key)) {
169171
return;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ suite('Terminal Environment Variable Collection Service', () => {
570570
await terminalEnvVarCollectionService._applyCollection(undefined, customShell);
571571

572572
verify(collection.replace('CONDA_PREFIX', 'prefix/to/conda', anything())).once();
573-
verify(collection.clear()).twice();
573+
verify(collection.clear()).once();
574574
});
575575

576576
test('If no activated variables are returned for default shell, clear collection', async () => {

0 commit comments

Comments
 (0)