Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear environment collection only after all async operations are done #21975

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading