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

Change applyAtProcessCreation behavior #190991

Merged
merged 3 commits into from
Aug 22, 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
21 changes: 12 additions & 9 deletions src/vs/workbench/api/common/extHostTerminalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -942,21 +942,21 @@ class UnifiedEnvironmentVariableCollection {
if (this._extension && options) {
checkProposedApiEnabled(this._extension, 'envCollectionOptions');
}
this._setIfDiffers(variable, { value, type: EnvironmentVariableMutatorType.Replace, options: options ?? {}, scope });
this._setIfDiffers(variable, { value, type: EnvironmentVariableMutatorType.Replace, options: options ?? { applyAtProcessCreation: true }, scope });
}

append(variable: string, value: string, options: vscode.EnvironmentVariableMutatorOptions | undefined, scope: vscode.EnvironmentVariableScope | undefined): void {
if (this._extension && options) {
checkProposedApiEnabled(this._extension, 'envCollectionOptions');
}
this._setIfDiffers(variable, { value, type: EnvironmentVariableMutatorType.Append, options: options ?? {}, scope });
this._setIfDiffers(variable, { value, type: EnvironmentVariableMutatorType.Append, options: options ?? { applyAtProcessCreation: true }, scope });
}

prepend(variable: string, value: string, options: vscode.EnvironmentVariableMutatorOptions | undefined, scope: vscode.EnvironmentVariableScope | undefined): void {
if (this._extension && options) {
checkProposedApiEnabled(this._extension, 'envCollectionOptions');
}
this._setIfDiffers(variable, { value, type: EnvironmentVariableMutatorType.Prepend, options: options ?? {}, scope });
this._setIfDiffers(variable, { value, type: EnvironmentVariableMutatorType.Prepend, options: options ?? { applyAtProcessCreation: true }, scope });
}

private _setIfDiffers(variable: string, mutator: vscode.EnvironmentVariableMutator & { scope: vscode.EnvironmentVariableScope | undefined }): void {
Expand All @@ -965,22 +965,25 @@ class UnifiedEnvironmentVariableCollection {
}
const key = this.getKey(variable, mutator.scope);
const current = this.map.get(key);
const newOptions = mutator.options ? {
applyAtProcessCreation: mutator.options.applyAtProcessCreation ?? false,
applyAtShellIntegration: mutator.options.applyAtShellIntegration ?? false,
} : {
applyAtProcessCreation: true
};
if (
!current ||
current.value !== mutator.value ||
current.type !== mutator.type ||
current.options?.applyAtProcessCreation !== (mutator.options.applyAtProcessCreation ?? true) ||
current.options?.applyAtShellIntegration !== (mutator.options.applyAtShellIntegration ?? false) ||
current.options?.applyAtProcessCreation !== newOptions.applyAtProcessCreation ||
current.options?.applyAtShellIntegration !== newOptions.applyAtShellIntegration ||
current.scope?.workspaceFolder?.index !== mutator.scope?.workspaceFolder?.index
) {
const key = this.getKey(variable, mutator.scope);
const value: IEnvironmentVariableMutator = {
variable,
...mutator,
options: {
applyAtProcessCreation: mutator.options.applyAtProcessCreation ?? true,
applyAtShellIntegration: mutator.options.applyAtShellIntegration ?? false,
}
options: newOptions
};
this.map.set(key, value);
this._onDidChangeCollection.fire();
Expand Down
13 changes: 6 additions & 7 deletions src/vscode-dts/vscode.proposed.envCollectionOptions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@ declare module 'vscode' {
export interface EnvironmentVariableMutatorOptions {
/**
* Apply to the environment just before the process is created.
*
* Defaults to true.
*/
applyAtProcessCreation?: boolean;

/**
* Apply to the environment in the shell integration script. Note that this _will not_ apply
* the mutator if shell integration is disabled or not working for some reason.
*
* Defaults to false.
*/
applyAtShellIntegration?: boolean;
}
Expand All @@ -39,17 +35,20 @@ declare module 'vscode' {

export interface EnvironmentVariableCollection extends Iterable<[variable: string, mutator: EnvironmentVariableMutator]> {
/**
* @param options Options applied to the mutator.
* @param options Options applied to the mutator, when not options are provided this will
* default to `{ applyAtProcessCreation: true }`
*/
replace(variable: string, value: string, options?: EnvironmentVariableMutatorOptions): void;

/**
* @param options Options applied to the mutator.
* @param options Options applied to the mutator, when not options are provided this will
* default to `{ applyAtProcessCreation: true }`
*/
append(variable: string, value: string, options?: EnvironmentVariableMutatorOptions): void;

/**
* @param options Options applied to the mutator.
* @param options Options applied to the mutator, when not options are provided this will
* default to `{ applyAtProcessCreation: true }`
*/
prepend(variable: string, value: string, options?: EnvironmentVariableMutatorOptions): void;
}
Expand Down