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

Finalize EnvironmentVariableMutatorOptions API #191082

Merged
merged 4 commits into from
Aug 24, 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
3 changes: 1 addition & 2 deletions extensions/vscode-api-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@
"workspaceTrust",
"telemetry",
"windowActivity",
"interactiveUserActions",
"envCollectionOptions"
"interactiveUserActions"
],
"private": true,
"activationEvents": [],
Expand Down
19 changes: 2 additions & 17 deletions src/vs/workbench/api/common/extHostTerminalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { ThemeColor } from 'vs/base/common/themables';
import { Promises } from 'vs/base/common/async';
import { EditorGroupColumn } from 'vs/workbench/services/editor/common/editorGroupColumn';
import { TerminalQuickFix, ViewColumn } from 'vs/workbench/api/common/extHostTypeConverters';
import { checkProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
import { IExtHostCommands } from 'vs/workbench/api/common/extHostCommands';

export interface IExtHostTerminalService extends ExtHostTerminalServiceShape, IDisposable {
Expand Down Expand Up @@ -858,7 +857,7 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I
public getEnvironmentVariableCollection(extension: IExtensionDescription): IEnvironmentVariableCollection {
let collection = this._environmentVariableCollections.get(extension.identifier.value);
if (!collection) {
collection = new UnifiedEnvironmentVariableCollection(extension);
collection = new UnifiedEnvironmentVariableCollection();
this._setEnvironmentVariableCollection(extension.identifier.value, collection);
}
return collection.getScopedEnvironmentVariableCollection(undefined);
Expand All @@ -873,7 +872,7 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I
public $initEnvironmentVariableCollections(collections: [string, ISerializableEnvironmentVariableCollection][]): void {
collections.forEach(entry => {
const extensionIdentifier = entry[0];
const collection = new UnifiedEnvironmentVariableCollection(undefined, entry[1]);
const collection = new UnifiedEnvironmentVariableCollection(entry[1]);
this._setEnvironmentVariableCollection(extensionIdentifier, collection);
});
}
Expand Down Expand Up @@ -918,11 +917,6 @@ class UnifiedEnvironmentVariableCollection {
get onDidChangeCollection(): Event<void> { return this._onDidChangeCollection && this._onDidChangeCollection.event; }

constructor(
// HACK: Only check proposed options if extension is set (when the collection is not
// restored by serialization). This saves us from getting the extension details and
// shouldn't ever happen since you can only set them initially via the proposed check.
// TODO: This should be removed when the env var extension API(s) are stabilized
private readonly _extension: IExtensionDescription | undefined,
serialized?: ISerializableEnvironmentVariableCollection
) {
this.map = new Map(serialized);
Expand All @@ -940,23 +934,14 @@ class UnifiedEnvironmentVariableCollection {
}

replace(variable: string, value: string, options: vscode.EnvironmentVariableMutatorOptions | undefined, scope: vscode.EnvironmentVariableScope | undefined): void {
if (this._extension && options) {
Tyriar marked this conversation as resolved.
Show resolved Hide resolved
checkProposedApiEnabled(this._extension, 'envCollectionOptions');
}
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 ?? { 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 ?? { applyAtProcessCreation: true }, scope });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export const allApiProposals = Object.freeze({
dropMetadata: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.dropMetadata.d.ts',
editSessionIdentityProvider: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.editSessionIdentityProvider.d.ts',
editorInsets: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.editorInsets.d.ts',
envCollectionOptions: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.envCollectionOptions.d.ts',
envShellEvent: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.envShellEvent.d.ts',
extensionRuntime: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.extensionRuntime.d.ts',
extensionsAny: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.extensionsAny.d.ts',
Expand Down
34 changes: 31 additions & 3 deletions src/vscode-dts/vscode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11334,6 +11334,23 @@ declare module 'vscode' {
Prepend = 3
}

/**
* Options applied to the mutator.
*/
export interface EnvironmentVariableMutatorOptions {
/**
* Apply to the environment just before the process is created. Defaults to false.
*/
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;
}

/**
* A type of mutation and its value to be applied to an environment variable.
*/
Expand All @@ -11347,6 +11364,11 @@ declare module 'vscode' {
* The value to use for the variable.
*/
readonly value: string;

/**
* Options applied to the mutator.
*/
readonly options: EnvironmentVariableMutatorOptions;
}

/**
Expand Down Expand Up @@ -11376,8 +11398,10 @@ declare module 'vscode' {
*
* @param variable The variable to replace.
* @param value The value to replace the variable with.
* @param options Options applied to the mutator, when no options are provided this will
* default to `{ applyAtProcessCreation: true }`.
Tyriar marked this conversation as resolved.
Show resolved Hide resolved
*/
replace(variable: string, value: string): void;
replace(variable: string, value: string, options?: EnvironmentVariableMutatorOptions): void;

/**
* Append a value to an environment variable.
Expand All @@ -11387,8 +11411,10 @@ declare module 'vscode' {
*
* @param variable The variable to append to.
* @param value The value to append to the variable.
* @param options Options applied to the mutator, when no options are provided this will
* default to `{ applyAtProcessCreation: true }`.
*/
append(variable: string, value: string): void;
append(variable: string, value: string, options?: EnvironmentVariableMutatorOptions): void;

/**
* Prepend a value to an environment variable.
Expand All @@ -11398,8 +11424,10 @@ declare module 'vscode' {
*
* @param variable The variable to prepend.
* @param value The value to prepend to the variable.
* @param options Options applied to the mutator, when no options are provided this will
* default to `{ applyAtProcessCreation: true }`.
*/
prepend(variable: string, value: string): void;
prepend(variable: string, value: string, options?: EnvironmentVariableMutatorOptions): void;

/**
* Gets the mutator that this collection applies to a variable, if any.
Expand Down
55 changes: 0 additions & 55 deletions src/vscode-dts/vscode.proposed.envCollectionOptions.d.ts

This file was deleted.