Skip to content

Commit 33d458b

Browse files
committed
fix: remove promise for env variables
1 parent 2695bea commit 33d458b

6 files changed

Lines changed: 43 additions & 53 deletions

File tree

src/features/terminal/shells/activateUsingShellStartup.ts renamed to src/features/terminal/activateUsingShellStartup.ts

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { ConfigurationChangeEvent, Disposable, GlobalEnvironmentVariableCollection } from 'vscode';
2-
import { DidChangeEnvironmentEventArgs } from '../../../api';
3-
import { ShellStartupActivationStrings } from '../../../common/localize';
4-
import { traceError, traceInfo } from '../../../common/logging';
5-
import { showErrorMessage, showInformationMessage } from '../../../common/window.apis';
6-
import { getWorkspaceFolder, getWorkspaceFolders, onDidChangeConfiguration } from '../../../common/workspace.apis';
7-
import { EnvironmentManagers } from '../../../internal.api';
8-
import { getAutoActivationType, setAutoActivationType } from '../utils';
9-
import { ShellEnvsProvider, ShellScriptEditState, ShellStartupScriptProvider } from './startupProvider';
2+
import { DidChangeEnvironmentEventArgs } from '../../api';
3+
import { ShellStartupActivationStrings } from '../../common/localize';
4+
import { traceError, traceInfo } from '../../common/logging';
5+
import { showErrorMessage, showInformationMessage } from '../../common/window.apis';
6+
import { getWorkspaceFolder, getWorkspaceFolders, onDidChangeConfiguration } from '../../common/workspace.apis';
7+
import { EnvironmentManagers } from '../../internal.api';
8+
import { ShellEnvsProvider, ShellScriptEditState, ShellStartupScriptProvider } from './shells/startupProvider';
9+
import { getAutoActivationType, setAutoActivationType } from './utils';
1010

1111
export interface ShellStartupActivationManager extends Disposable {
1212
initialize(): Promise<void>;
@@ -42,20 +42,12 @@ export class ShellStartupActivationManagerImpl implements ShellStartupActivation
4242
// remove any contributed environment variables
4343
const workspaces = getWorkspaceFolders() ?? [];
4444
if (workspaces.length > 0) {
45-
// User has one or more workspaces open
46-
const promises: Promise<void>[] = [];
4745
workspaces.forEach((workspace) => {
4846
const collection = this.envCollection.getScoped({ workspaceFolder: workspace });
49-
promises.push(
50-
...this.shellEnvsProviders.map((provider) => provider.removeEnvVariables(collection)),
51-
);
47+
this.shellEnvsProviders.forEach((provider) => provider.removeEnvVariables(collection));
5248
});
53-
await Promise.all(promises);
5449
} else {
55-
// User has no workspaces open
56-
await Promise.all(
57-
this.shellEnvsProviders.map((provider) => provider.removeEnvVariables(this.envCollection)),
58-
);
50+
this.shellEnvsProviders.forEach((provider) => provider.removeEnvVariables(this.envCollection));
5951
}
6052
}
6153
}
@@ -72,15 +64,13 @@ export class ShellStartupActivationManagerImpl implements ShellStartupActivation
7264
if (wf) {
7365
const envVars = this.envCollection.getScoped({ workspaceFolder: wf });
7466
if (envVars) {
75-
await Promise.all(
76-
this.shellEnvsProviders.map(async (provider) => {
77-
if (e.new) {
78-
await provider.updateEnvVariables(envVars, e.new);
79-
} else {
80-
await provider.removeEnvVariables(envVars);
81-
}
82-
}),
83-
);
67+
this.shellEnvsProviders.forEach((provider) => {
68+
if (e.new) {
69+
provider.updateEnvVariables(envVars, e.new);
70+
} else {
71+
provider.removeEnvVariables(envVars);
72+
}
73+
});
8474
}
8575
}
8676
}
@@ -132,9 +122,9 @@ export class ShellStartupActivationManagerImpl implements ShellStartupActivation
132122
...this.shellEnvsProviders.map(async (provider) => {
133123
const env = await this.em.getEnvironment(workspace.uri);
134124
if (env) {
135-
await provider.updateEnvVariables(collection, env);
125+
provider.updateEnvVariables(collection, env);
136126
} else {
137-
await provider.removeEnvVariables(collection);
127+
provider.removeEnvVariables(collection);
138128
}
139129
}),
140130
);
@@ -145,9 +135,9 @@ export class ShellStartupActivationManagerImpl implements ShellStartupActivation
145135
this.shellEnvsProviders.map(async (provider) => {
146136
const env = await this.em.getEnvironment(undefined);
147137
if (env) {
148-
await provider.updateEnvVariables(this.envCollection, env);
138+
provider.updateEnvVariables(this.envCollection, env);
149139
} else {
150-
await provider.removeEnvVariables(this.envCollection);
140+
provider.removeEnvVariables(this.envCollection);
151141
}
152142
}),
153143
);

src/features/terminal/shells/bash/bashEnvs.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { EnvironmentVariableCollection } from 'vscode';
22
import { PythonEnvironment } from '../../../../api';
33
import { traceError } from '../../../../common/logging';
44
import { ShellConstants } from '../../../common/shellConstants';
5+
import { getShellActivationCommand, getShellCommandAsString } from '../common/shellUtils';
56
import { ShellEnvsProvider } from '../startupProvider';
67
import { BASH_ENV_KEY, ZSH_ENV_KEY } from './bashConstants';
7-
import { getShellActivationCommand, getShellCommandAsString } from '../common/shellUtils';
88

99
export class BashEnvsProvider implements ShellEnvsProvider {
1010
constructor(public readonly shellType: 'bash' | 'gitbash') {}
1111

12-
async updateEnvVariables(collection: EnvironmentVariableCollection, env: PythonEnvironment): Promise<void> {
12+
updateEnvVariables(collection: EnvironmentVariableCollection, env: PythonEnvironment): void {
1313
try {
1414
const bashActivation = getShellActivationCommand(this.shellType, env);
1515
if (bashActivation) {
@@ -24,11 +24,11 @@ export class BashEnvsProvider implements ShellEnvsProvider {
2424
}
2525
}
2626

27-
async removeEnvVariables(envCollection: EnvironmentVariableCollection): Promise<void> {
27+
removeEnvVariables(envCollection: EnvironmentVariableCollection): void {
2828
envCollection.delete(BASH_ENV_KEY);
2929
}
3030

31-
async getEnvVariables(env?: PythonEnvironment): Promise<Map<string, string | undefined> | undefined> {
31+
getEnvVariables(env?: PythonEnvironment): Map<string, string | undefined> | undefined {
3232
if (!env) {
3333
return new Map([[BASH_ENV_KEY, undefined]]);
3434
}
@@ -49,7 +49,7 @@ export class BashEnvsProvider implements ShellEnvsProvider {
4949

5050
export class ZshEnvsProvider implements ShellEnvsProvider {
5151
public readonly shellType: string = ShellConstants.ZSH;
52-
async updateEnvVariables(envVars: EnvironmentVariableCollection, env: PythonEnvironment): Promise<void> {
52+
updateEnvVariables(envVars: EnvironmentVariableCollection, env: PythonEnvironment): void {
5353
try {
5454
const zshActivation = getShellActivationCommand(this.shellType, env);
5555
if (zshActivation) {
@@ -64,11 +64,11 @@ export class ZshEnvsProvider implements ShellEnvsProvider {
6464
}
6565
}
6666

67-
async removeEnvVariables(envVars: EnvironmentVariableCollection): Promise<void> {
67+
removeEnvVariables(envVars: EnvironmentVariableCollection): void {
6868
envVars.delete(ZSH_ENV_KEY);
6969
}
7070

71-
async getEnvVariables(env?: PythonEnvironment): Promise<Map<string, string | undefined> | undefined> {
71+
getEnvVariables(env?: PythonEnvironment): Map<string, string | undefined> | undefined {
7272
if (!env) {
7373
return new Map([[ZSH_ENV_KEY, undefined]]);
7474
}

src/features/terminal/shells/cmd/cmdEnvs.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { CMD_ENV_KEY } from './cmdConstants';
88

99
export class CmdEnvsProvider implements ShellEnvsProvider {
1010
readonly shellType: string = ShellConstants.CMD;
11-
async updateEnvVariables(collection: EnvironmentVariableCollection, env: PythonEnvironment): Promise<void> {
11+
updateEnvVariables(collection: EnvironmentVariableCollection, env: PythonEnvironment): void {
1212
try {
1313
const cmdActivation = getShellActivationCommand(this.shellType, env);
1414
if (cmdActivation) {
@@ -23,11 +23,11 @@ export class CmdEnvsProvider implements ShellEnvsProvider {
2323
}
2424
}
2525

26-
async removeEnvVariables(envCollection: EnvironmentVariableCollection): Promise<void> {
26+
removeEnvVariables(envCollection: EnvironmentVariableCollection): void {
2727
envCollection.delete(CMD_ENV_KEY);
2828
}
2929

30-
async getEnvVariables(env?: PythonEnvironment): Promise<Map<string, string | undefined> | undefined> {
30+
getEnvVariables(env?: PythonEnvironment): Map<string, string | undefined> | undefined {
3131
if (!env) {
3232
return new Map([[CMD_ENV_KEY, undefined]]);
3333
}

src/features/terminal/shells/fish/fishEnvs.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { FISH_ENV_KEY } from './fishConstants';
88

99
export class FishEnvsProvider implements ShellEnvsProvider {
1010
readonly shellType: string = ShellConstants.FISH;
11-
async updateEnvVariables(collection: EnvironmentVariableCollection, env: PythonEnvironment): Promise<void> {
11+
updateEnvVariables(collection: EnvironmentVariableCollection, env: PythonEnvironment): void {
1212
try {
1313
const fishActivation = getShellActivationCommand(this.shellType, env);
1414
if (fishActivation) {
@@ -23,11 +23,11 @@ export class FishEnvsProvider implements ShellEnvsProvider {
2323
}
2424
}
2525

26-
async removeEnvVariables(envCollection: EnvironmentVariableCollection): Promise<void> {
26+
removeEnvVariables(envCollection: EnvironmentVariableCollection): void {
2727
envCollection.delete(FISH_ENV_KEY);
2828
}
2929

30-
async getEnvVariables(env?: PythonEnvironment): Promise<Map<string, string | undefined> | undefined> {
30+
getEnvVariables(env?: PythonEnvironment): Map<string, string | undefined> | undefined {
3131
if (!env) {
3232
return new Map([[FISH_ENV_KEY, undefined]]);
3333
}

src/features/terminal/shells/pwsh/pwshEnvs.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { EnvironmentVariableCollection } from 'vscode';
2-
import { traceError } from '../../../../common/logging';
3-
import { ShellEnvsProvider } from '../startupProvider';
42
import { PythonEnvironment } from '../../../../api';
3+
import { traceError } from '../../../../common/logging';
54
import { ShellConstants } from '../../../common/shellConstants';
6-
import { POWERSHELL_ENV_KEY } from './pwshConstants';
75
import { getShellActivationCommand, getShellCommandAsString } from '../common/shellUtils';
6+
import { ShellEnvsProvider } from '../startupProvider';
7+
import { POWERSHELL_ENV_KEY } from './pwshConstants';
88

99
export class PowerShellEnvsProvider implements ShellEnvsProvider {
1010
public readonly shellType: string = ShellConstants.PWSH;
1111

12-
async updateEnvVariables(collection: EnvironmentVariableCollection, env: PythonEnvironment): Promise<void> {
12+
updateEnvVariables(collection: EnvironmentVariableCollection, env: PythonEnvironment): void {
1313
try {
1414
const pwshActivation = getShellActivationCommand(this.shellType, env);
1515
if (pwshActivation) {
@@ -24,11 +24,11 @@ export class PowerShellEnvsProvider implements ShellEnvsProvider {
2424
}
2525
}
2626

27-
async removeEnvVariables(envCollection: EnvironmentVariableCollection): Promise<void> {
27+
removeEnvVariables(envCollection: EnvironmentVariableCollection): void {
2828
envCollection.delete(POWERSHELL_ENV_KEY);
2929
}
3030

31-
async getEnvVariables(env?: PythonEnvironment): Promise<Map<string, string | undefined> | undefined> {
31+
getEnvVariables(env?: PythonEnvironment): Map<string, string | undefined> | undefined {
3232
if (!env) {
3333
return new Map([[POWERSHELL_ENV_KEY, undefined]]);
3434
}

src/features/terminal/shells/startupProvider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export interface ShellStartupScriptProvider {
2222

2323
export interface ShellEnvsProvider {
2424
readonly shellType: string;
25-
updateEnvVariables(envVars: EnvironmentVariableCollection, env: PythonEnvironment): Promise<void>;
26-
removeEnvVariables(envVars: EnvironmentVariableCollection): Promise<void>;
27-
getEnvVariables(env?: PythonEnvironment): Promise<Map<string, string | undefined> | undefined>;
25+
updateEnvVariables(envVars: EnvironmentVariableCollection, env: PythonEnvironment): void;
26+
removeEnvVariables(envVars: EnvironmentVariableCollection): void;
27+
getEnvVariables(env?: PythonEnvironment): Map<string, string | undefined> | undefined;
2828
}

0 commit comments

Comments
 (0)