Skip to content

Commit af3c79e

Browse files
committed
Move ExtensionContext.environmentVariableCollection to stable
Fixes microsoft#46696
1 parent ed00093 commit af3c79e

4 files changed

Lines changed: 115 additions & 105 deletions

File tree

src/vs/vscode.d.ts

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5452,6 +5452,12 @@ declare module 'vscode' {
54525452
*/
54535453
readonly extensionPath: string;
54545454

5455+
/**
5456+
* Gets the extension's environment variable collection for this workspace, enabling changes
5457+
* to be applied to terminal environment variables.
5458+
*/
5459+
readonly environmentVariableCollection: EnvironmentVariableCollection;
5460+
54555461
/**
54565462
* Get the absolute path of a resource contained in the extension.
54575463
*
@@ -8257,6 +8263,113 @@ declare module 'vscode' {
82578263
readonly code: number | undefined;
82588264
}
82598265

8266+
/**
8267+
* A type of mutation that can be applied to an environment variable.
8268+
*/
8269+
export enum EnvironmentVariableMutatorType {
8270+
/**
8271+
* Replace the variable's existing value.
8272+
*/
8273+
Replace = 1,
8274+
/**
8275+
* Append to the end of the variable's existing value.
8276+
*/
8277+
Append = 2,
8278+
/**
8279+
* Prepend to the start of the variable's existing value.
8280+
*/
8281+
Prepend = 3
8282+
}
8283+
8284+
/**
8285+
* A type of mutation and its value to be applied to an environment variable.
8286+
*/
8287+
export interface EnvironmentVariableMutator {
8288+
/**
8289+
* The type of mutation that will occur to the variable.
8290+
*/
8291+
readonly type: EnvironmentVariableMutatorType;
8292+
8293+
/**
8294+
* The value to use for the variable.
8295+
*/
8296+
readonly value: string;
8297+
}
8298+
8299+
/**
8300+
* A collection of mutations that an extension can apply to a process environment.
8301+
*/
8302+
export interface EnvironmentVariableCollection {
8303+
/**
8304+
* Whether the collection should be cached for the workspace and applied to the terminal
8305+
* across window reloads. When true the collection will be active immediately such when the
8306+
* window reloads. Additionally, this API will return the cached version if it exists. The
8307+
* collection will be invalidated when the extension is uninstalled or when the collection
8308+
* is cleared. Defaults to true.
8309+
*/
8310+
persistent: boolean;
8311+
8312+
/**
8313+
* Replace an environment variable with a value.
8314+
*
8315+
* Note that an extension can only make a single change to any one variable, so this will
8316+
* overwrite any previous calls to replace, append or prepend.
8317+
*
8318+
* @param variable The variable to replace.
8319+
* @param value The value to replace the variable with.
8320+
*/
8321+
replace(variable: string, value: string): void;
8322+
8323+
/**
8324+
* Append a value to an environment variable.
8325+
*
8326+
* Note that an extension can only make a single change to any one variable, so this will
8327+
* overwrite any previous calls to replace, append or prepend.
8328+
*
8329+
* @param variable The variable to append to.
8330+
* @param value The value to append to the variable.
8331+
*/
8332+
append(variable: string, value: string): void;
8333+
8334+
/**
8335+
* Prepend a value to an environment variable.
8336+
*
8337+
* Note that an extension can only make a single change to any one variable, so this will
8338+
* overwrite any previous calls to replace, append or prepend.
8339+
*
8340+
* @param variable The variable to prepend.
8341+
* @param value The value to prepend to the variable.
8342+
*/
8343+
prepend(variable: string, value: string): void;
8344+
8345+
/**
8346+
* Gets the mutator that this collection applies to a variable, if any.
8347+
*
8348+
* @param variable The variable to get the mutator for.
8349+
*/
8350+
get(variable: string): EnvironmentVariableMutator | undefined;
8351+
8352+
/**
8353+
* Iterate over each mutator in this collection.
8354+
*
8355+
* @param callback Function to execute for each entry.
8356+
* @param thisArg The `this` context used when invoking the handler function.
8357+
*/
8358+
forEach(callback: (variable: string, mutator: EnvironmentVariableMutator, collection: EnvironmentVariableCollection) => any, thisArg?: any): void;
8359+
8360+
/**
8361+
* Deletes this collection's mutator for a variable.
8362+
*
8363+
* @param variable The variable to delete the mutator for.
8364+
*/
8365+
delete(variable: string): void;
8366+
8367+
/**
8368+
* Clears all mutators from this collection.
8369+
*/
8370+
clear(): void;
8371+
}
8372+
82608373
/**
82618374
* A location in the editor at which progress information can be shown. It depends on the
82628375
* location how progress is visually represented.

src/vs/vscode.proposed.d.ts

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -930,103 +930,6 @@ declare module 'vscode' {
930930

931931
//#endregion
932932

933-
//#region Contribute to terminal environment https://github.com/microsoft/vscode/issues/46696
934-
935-
export enum EnvironmentVariableMutatorType {
936-
/**
937-
* Replace the variable's existing value.
938-
*/
939-
Replace = 1,
940-
/**
941-
* Append to the end of the variable's existing value.
942-
*/
943-
Append = 2,
944-
/**
945-
* Prepend to the start of the variable's existing value.
946-
*/
947-
Prepend = 3
948-
}
949-
950-
export interface EnvironmentVariableMutator {
951-
/**
952-
* The type of mutation that will occur to the variable.
953-
*/
954-
readonly type: EnvironmentVariableMutatorType;
955-
956-
/**
957-
* The value to use for the variable.
958-
*/
959-
readonly value: string;
960-
}
961-
962-
/**
963-
* A collection of mutations that an extension can apply to a process environment.
964-
*/
965-
export interface EnvironmentVariableCollection {
966-
/**
967-
* Whether the collection should be cached for the workspace and applied to the terminal
968-
* across window reloads. When true the collection will be active immediately such when the
969-
* window reloads. Additionally, this API will return the cached version if it exists. The
970-
* collection will be invalidated when the extension is uninstalled or when the collection
971-
* is cleared. Defaults to true.
972-
*/
973-
persistent: boolean;
974-
975-
/**
976-
* Replace an environment variable with a value.
977-
*
978-
* Note that an extension can only make a single change to any one variable, so this will
979-
* overwrite any previous calls to replace, append or prepend.
980-
*/
981-
replace(variable: string, value: string): void;
982-
983-
/**
984-
* Append a value to an environment variable.
985-
*
986-
* Note that an extension can only make a single change to any one variable, so this will
987-
* overwrite any previous calls to replace, append or prepend.
988-
*/
989-
append(variable: string, value: string): void;
990-
991-
/**
992-
* Prepend a value to an environment variable.
993-
*
994-
* Note that an extension can only make a single change to any one variable, so this will
995-
* overwrite any previous calls to replace, append or prepend.
996-
*/
997-
prepend(variable: string, value: string): void;
998-
999-
/**
1000-
* Gets the mutator that this collection applies to a variable, if any.
1001-
*/
1002-
get(variable: string): EnvironmentVariableMutator | undefined;
1003-
1004-
/**
1005-
* Iterate over each mutator in this collection.
1006-
*/
1007-
forEach(callback: (variable: string, mutator: EnvironmentVariableMutator, collection: EnvironmentVariableCollection) => any, thisArg?: any): void;
1008-
1009-
/**
1010-
* Deletes this collection's mutator for a variable.
1011-
*/
1012-
delete(variable: string): void;
1013-
1014-
/**
1015-
* Clears all mutators from this collection.
1016-
*/
1017-
clear(): void;
1018-
}
1019-
1020-
export interface ExtensionContext {
1021-
/**
1022-
* Gets the extension's environment variable collection for this workspace, enabling changes
1023-
* to be applied to terminal environment variables.
1024-
*/
1025-
readonly environmentVariableCollection: EnvironmentVariableCollection;
1026-
}
1027-
1028-
//#endregion
1029-
1030933
//#region @jrieken -> exclusive document filters
1031934

1032935
export interface DocumentFilter {

src/vs/workbench/api/common/extHostExtensionService.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { ExtHostConfiguration, IExtHostConfiguration } from 'vs/workbench/api/co
1616
import { ActivatedExtension, EmptyExtension, ExtensionActivationReason, ExtensionActivationTimes, ExtensionActivationTimesBuilder, ExtensionsActivator, IExtensionAPI, IExtensionModule, HostExtension, ExtensionActivationTimesFragment } from 'vs/workbench/api/common/extHostExtensionActivator';
1717
import { ExtHostStorage, IExtHostStorage } from 'vs/workbench/api/common/extHostStorage';
1818
import { ExtHostWorkspace, IExtHostWorkspace } from 'vs/workbench/api/common/extHostWorkspace';
19-
import { ExtensionActivationError, checkProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
19+
import { ExtensionActivationError } from 'vs/workbench/services/extensions/common/extensions';
2020
import { ExtensionDescriptionRegistry } from 'vs/workbench/services/extensions/common/extensionDescriptionRegistry';
2121
import { CancellationTokenSource } from 'vs/base/common/cancellation';
2222
import * as errors from 'vs/base/common/errors';
@@ -376,10 +376,7 @@ export abstract class AbstractExtHostExtensionService implements ExtHostExtensio
376376
get globalStoragePath() { return that._storagePath.globalValue(extensionDescription); },
377377
asAbsolutePath(relativePath: string) { return path.join(extensionDescription.extensionLocation.fsPath, relativePath); },
378378
get logPath() { return path.join(that._initData.logsLocation.fsPath, extensionDescription.identifier.value); },
379-
get environmentVariableCollection() {
380-
checkProposedApiEnabled(extensionDescription);
381-
return that._extHostTerminalService.getEnvironmentVariableCollection(extensionDescription);
382-
}
379+
get environmentVariableCollection() { return that._extHostTerminalService.getEnvironmentVariableCollection(extensionDescription); }
383380
});
384381
});
385382
}

src/vs/workbench/api/node/extHostTerminalService.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,10 @@ export class ExtHostTerminalService extends BaseExtHostTerminalService {
230230

231231
public getEnvironmentVariableCollection(extension: IExtensionDescription): vscode.EnvironmentVariableCollection {
232232
let collection = this._environmentVariableCollections.get(extension.identifier.value);
233-
234233
if (!collection) {
235-
// TODO: Disable dispose
236234
collection = new EnvironmentVariableCollection();
237235
this._setEnvironmentVariableCollection(extension.identifier.value, collection);
238236
}
239-
240237
return collection;
241238
}
242239

0 commit comments

Comments
 (0)