Skip to content

Commit

Permalink
Clear environment collection only after all async operations are done (
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartik Raj authored Sep 12, 2023
1 parent 91b2c11 commit 7aa6660
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,8 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
const workspaceFolder = this.getWorkspaceFolder(resource);
const settings = this.configurationService.getSettings(resource);
const envVarCollection = this.getEnvironmentVariableCollection({ workspaceFolder });
// Clear any previously set env vars from collection
envVarCollection.clear();
if (!settings.terminal.activateEnvironment) {
envVarCollection.clear();
traceVerbose('Activating environments in terminal is disabled for', resource?.fsPath);
return;
}
Expand All @@ -150,6 +149,7 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
return;
}
await this.trackTerminalPrompt(shell, resource, env);
envVarCollection.clear();
this.processEnvVars = undefined;
return;
}
Expand All @@ -164,6 +164,8 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
// PS1 in some cases is a shell variable (not an env variable) so "env" might not contain it, calculate it in that case.
env.PS1 = await this.getPS1(shell, resource, env);

// Clear any previously set env vars from collection
envVarCollection.clear();
Object.keys(env).forEach((key) => {
if (shouldSkip(key)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ suite('Terminal Environment Variable Collection Service', () => {
await terminalEnvVarCollectionService._applyCollection(undefined, customShell);

verify(collection.replace('CONDA_PREFIX', 'prefix/to/conda', anything())).once();
verify(collection.clear()).twice();
verify(collection.clear()).once();
});

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

0 comments on commit 7aa6660

Please sign in to comment.