From f9a702905d3f6de271c3e8c1916deb75557f4906 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Thu, 11 May 2023 22:34:40 +0000 Subject: [PATCH 01/21] approach 1 --- .../api/common/extHostTerminalService.ts | 130 +++++++----------- ...scode.proposed.envCollectionWorkspace.d.ts | 37 +++-- 2 files changed, 69 insertions(+), 98 deletions(-) diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index c703131984652..5b556d50567e0 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -50,7 +50,7 @@ export interface IExtHostTerminalService extends ExtHostTerminalServiceShape, ID registerLinkProvider(provider: vscode.TerminalLinkProvider): vscode.Disposable; registerProfileProvider(extension: IExtensionDescription, id: string, provider: vscode.TerminalProfileProvider): vscode.Disposable; registerTerminalQuickFixProvider(id: string, extensionId: string, provider: vscode.TerminalQuickFixProvider): vscode.Disposable; - getEnvironmentVariableCollection(extension: IExtensionDescription, persistent?: boolean): vscode.EnvironmentVariableCollection; + getEnvironmentVariableCollection(extension: IExtensionDescription): vscode.EnvironmentVariableCollection & { getScopedEnvironmentVariableCollection(scope?: vscode.EnvironmentVariableScope): vscode.EnvironmentVariableCollection }; } export interface ITerminalInternalOptions { @@ -823,7 +823,7 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I return index; } - public getEnvironmentVariableCollection(extension: IExtensionDescription): vscode.EnvironmentVariableCollection { + public getEnvironmentVariableCollection(extension: IExtensionDescription): vscode.EnvironmentVariableCollection & { getScopedEnvironmentVariableCollection(scope?: vscode.EnvironmentVariableScope): vscode.EnvironmentVariableCollection } { let collection = this._environmentVariableCollections.get(extension.identifier.value); if (!collection) { collection = new EnvironmentVariableCollection(); @@ -868,18 +868,19 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I } class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollection { - readonly map: Map = new Map(); - readonly descriptionMap: Map = new Map(); + readonly scopedCollections: Map }> = new Map(); + readonly map: Map = new Map(); + private _description: string | vscode.MarkdownString | undefined; private _persistent: boolean = true; public get persistent(): boolean { return this._persistent; } public set persistent(value: boolean) { this._persistent = value; - this._onDidChangeCollection.fire(); + this._onDidChangeCollection.fire(undefined); } - protected readonly _onDidChangeCollection: Emitter = new Emitter(); - get onDidChangeCollection(): Event { return this._onDidChangeCollection && this._onDidChangeCollection.event; } + protected readonly _onDidChangeCollection = new Emitter(); + get onDidChangeCollection(): Event { return this._onDidChangeCollection && this._onDidChangeCollection.event; } constructor( serialized?: ISerializableEnvironmentVariableCollection @@ -891,104 +892,77 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect return this.map.size; } - replace(variable: string, value: string, scope?: vscode.EnvironmentVariableScope): void { - this._setIfDiffers(variable, { value, type: EnvironmentVariableMutatorType.Replace, scope }); + getScopedEnvironmentVariableCollection(scope?: vscode.EnvironmentVariableScope): vscode.EnvironmentVariableCollection { + const scopedCollectionKey = this.getScopeKey(scope); + let scopedCollection = this.scopedCollections.get(scopedCollectionKey); + if (!scopedCollection) { + scopedCollection = new EnvironmentVariableCollection(); + this.scopedCollections.set(scopedCollectionKey, scopedCollection); + scopedCollection.onDidChangeCollection(() => this._onDidChangeCollection.fire(scope)); + } + return scopedCollection; } - append(variable: string, value: string, scope?: vscode.EnvironmentVariableScope): void { - this._setIfDiffers(variable, { value, type: EnvironmentVariableMutatorType.Append, scope }); + replace(variable: string, value: string): void { + this._setIfDiffers(variable, { value, type: EnvironmentVariableMutatorType.Replace }); } - prepend(variable: string, value: string, scope?: vscode.EnvironmentVariableScope): void { - this._setIfDiffers(variable, { value, type: EnvironmentVariableMutatorType.Prepend, scope }); + append(variable: string, value: string): void { + this._setIfDiffers(variable, { value, type: EnvironmentVariableMutatorType.Append }); } - private _setIfDiffers(variable: string, mutator: vscode.EnvironmentVariableMutator): void { - if (!mutator.scope) { - delete (mutator as any).scope; // Convenient for tests - } - const key = this.getKey(variable, mutator.scope); - const current = this.map.get(key); - if (!current || current.value !== mutator.value || current.type !== mutator.type || current.scope?.workspaceFolder?.index !== mutator.scope?.workspaceFolder?.index) { - const key = this.getKey(variable, mutator.scope); - const value: IEnvironmentVariableMutator = { variable, ...mutator }; - this.map.set(key, value); - this._onDidChangeCollection.fire(); - } + prepend(variable: string, value: string): void { + this._setIfDiffers(variable, { value, type: EnvironmentVariableMutatorType.Prepend }); } - get(variable: string, scope?: vscode.EnvironmentVariableScope): vscode.EnvironmentVariableMutator | undefined { - const key = this.getKey(variable, scope); - const value = this.map.get(key); - return value ? convertMutator(value) : undefined; + private _setIfDiffers(variable: string, mutator: vscode.EnvironmentVariableMutator): void { + const current = this.map.get(variable); + if (!current || current.value !== mutator.value || current.type !== mutator.type) { + this.map.set(variable, mutator); + this._onDidChangeCollection.fire(undefined); + } } - private getKey(variable: string, scope: vscode.EnvironmentVariableScope | undefined) { - const workspaceKey = this.getWorkspaceKey(scope?.workspaceFolder); - return workspaceKey ? `${variable}:::${workspaceKey}` : variable; + private getScopeKey(scope?: vscode.EnvironmentVariableScope): string { + return this.getWorkspaceKey(scope?.workspaceFolder) ?? ''; } private getWorkspaceKey(workspaceFolder: vscode.WorkspaceFolder | undefined): string | undefined { return workspaceFolder ? workspaceFolder.uri.toString() : undefined; } + get(variable: string): vscode.EnvironmentVariableMutator | undefined { + return this.map.get(variable); + } + forEach(callback: (variable: string, mutator: vscode.EnvironmentVariableMutator, collection: vscode.EnvironmentVariableCollection) => any, thisArg?: any): void { - this.map.forEach((value, _) => callback.call(thisArg, value.variable, convertMutator(value), this)); + this.map.forEach((value, key) => callback.call(thisArg, key, value, this)); } [Symbol.iterator](): IterableIterator<[variable: string, mutator: vscode.EnvironmentVariableMutator]> { - const map: Map = new Map(); - this.map.forEach((mutator, _key) => { - if (mutator.scope) { - // Scoped mutators are not supported via this iterator, as it returns variable as the key which is supposed to be unique. - return; - } - map.set(mutator.variable, convertMutator(mutator)); - }); - return map.entries(); + return this.map.entries(); } - delete(variable: string, scope?: vscode.EnvironmentVariableScope): void { - const key = this.getKey(variable, scope); - this.map.delete(key); - this._onDidChangeCollection.fire(); + delete(variable: string): void { + this.map.delete(variable); + this._onDidChangeCollection.fire(undefined); } - clear(scope?: vscode.EnvironmentVariableScope): void { - if (scope?.workspaceFolder) { - for (const [key, mutator] of this.map) { - if (mutator.scope?.workspaceFolder?.index === scope.workspaceFolder.index) { - this.map.delete(key); - } - } - this.clearDescription(scope); - } else { - this.map.clear(); - this.descriptionMap.clear(); - } - this._onDidChangeCollection.fire(); - } - - setDescription(description: string | vscode.MarkdownString | undefined, scope?: vscode.EnvironmentVariableScope): void { - const key = this.getKey('', scope); - const current = this.descriptionMap.get(key); - if (!current || current.description !== description) { - let descriptionStr: string | undefined; - if (typeof description === 'string') { - descriptionStr = description; - } else { - // Only take the description before the first `\n\n`, so that the description doesn't mess up the UI - descriptionStr = description?.value.split('\n\n')[0]; - } - const value: IEnvironmentDescriptionMutator = { description: descriptionStr, scope }; - this.descriptionMap.set(key, value); - this._onDidChangeCollection.fire(); + clear(): void { + this.map.clear(); + this._onDidChangeCollection.fire(undefined); + } + + set description(description: string | vscode.MarkdownString | undefined) { + if (this._description === description) { + return; } + this._description = description; + this._onDidChangeCollection.fire(undefined); } - private clearDescription(scope?: vscode.EnvironmentVariableScope): void { - const key = this.getKey('', scope); - this.descriptionMap.delete(key); + get description(): string | vscode.MarkdownString | undefined { + return this._description; } } diff --git a/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts b/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts index b97e4afb28a4e..6b40fdd5c39dd 100644 --- a/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts +++ b/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts @@ -5,33 +5,30 @@ declare module 'vscode' { - // https://github.com/microsoft/vscode/issues/171173 + // https://github.com/microsoft/vscode/issues/182069 - export interface EnvironmentVariableMutator { - readonly type: EnvironmentVariableMutatorType; - readonly value: string; - readonly scope: EnvironmentVariableScope | undefined; - } - - export interface EnvironmentVariableCollection extends Iterable<[variable: string, mutator: EnvironmentVariableMutator]> { + export interface ExtensionContext { /** - * Sets a description for the environment variable collection, this will be used to describe the changes in the UI. - * @param description A description for the environment variable collection. - * @param scope Specific scope to which this description applies to. + * Gets the extension's environment variable collection for this workspace, enabling changes + * to be applied to terminal environment variables. + * + * @param scope The scope to which the environment variable collection applies to. */ - setDescription(description: string | MarkdownString | undefined, scope?: EnvironmentVariableScope): void; - replace(variable: string, value: string, scope?: EnvironmentVariableScope): void; - append(variable: string, value: string, scope?: EnvironmentVariableScope): void; - prepend(variable: string, value: string, scope?: EnvironmentVariableScope): void; - get(variable: string, scope?: EnvironmentVariableScope): EnvironmentVariableMutator | undefined; - delete(variable: string, scope?: EnvironmentVariableScope): void; - clear(scope?: EnvironmentVariableScope): void; + readonly environmentVariableCollection: EnvironmentVariableCollection & { getScopedEnvironmentVariableCollection(scope?: EnvironmentVariableScope): EnvironmentVariableCollection }; } export type EnvironmentVariableScope = { /** - * The workspace folder to which this collection applies to. If unspecified, collection applies to all workspace folders. - */ + * Any specific workspace folder to get collection for. If unspecified, collection applicable to all workspace folders is returned. + */ workspaceFolder?: WorkspaceFolder; }; + + export interface EnvironmentVariableCollection extends Iterable<[variable: string, mutator: EnvironmentVariableMutator]> { + /** + * A description for the environment variable collection, this will be used to describe the + * changes in the UI. + */ + description: string | MarkdownString | undefined; + } } From b90dd8280a3b55601b804de0391e714af16c255e Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Thu, 11 May 2023 23:23:34 +0000 Subject: [PATCH 02/21] approach 2 part 1 --- .../api/common/extHostTerminalService.ts | 170 +++++++++++++++--- 1 file changed, 149 insertions(+), 21 deletions(-) diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index 5b556d50567e0..96efea2978519 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -829,7 +829,24 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I collection = new EnvironmentVariableCollection(); this._setEnvironmentVariableCollection(extension.identifier.value, collection); } - return collection; + return { + ...collection, getScopedEnvironmentVariableCollection(scope) { + return this.getScopedEnvironmentVariableCollection(collection!, scope); + }, + }; + } + + private getScopedEnvironmentVariableCollection(collection: EnvironmentVariableCollection, scope?: vscode.EnvironmentVariableScope): vscode.EnvironmentVariableCollection { + if (scope === undefined) { + return collection; + } + const key = `${scope.scope}${scope.target}`; + let scopedCollection = this._scopedEnvironmentVariableCollections.get(key); + if (!scopedCollection) { + scopedCollection = new EnvironmentVariableCollection(); + this._scopedEnvironmentVariableCollections.set(key, scopedCollection); + } + return scopedCollection; } private _syncEnvironmentVariableCollection(extensionIdentifier: string, collection: EnvironmentVariableCollection): void { @@ -868,7 +885,135 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I } class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollection { - readonly scopedCollections: Map }> = new Map(); + readonly map: Map = new Map(); + readonly descriptionMap: Map = new Map(); + private _persistent: boolean = true; + + public get persistent(): boolean { return this._persistent; } + public set persistent(value: boolean) { + this._persistent = value; + this._onDidChangeCollection.fire(); + } + + protected readonly _onDidChangeCollection: Emitter = new Emitter(); + get onDidChangeCollection(): Event { return this._onDidChangeCollection && this._onDidChangeCollection.event; } + + constructor( + serialized?: ISerializableEnvironmentVariableCollection + ) { + this.map = new Map(serialized); + } + + get size(): number { + return this.map.size; + } + + replace(variable: string, value: string, scope?: vscode.EnvironmentVariableScope): void { + this._setIfDiffers(variable, { value, type: EnvironmentVariableMutatorType.Replace, scope }); + } + + append(variable: string, value: string, scope?: vscode.EnvironmentVariableScope): void { + this._setIfDiffers(variable, { value, type: EnvironmentVariableMutatorType.Append, scope }); + } + + prepend(variable: string, value: string, scope?: vscode.EnvironmentVariableScope): void { + this._setIfDiffers(variable, { value, type: EnvironmentVariableMutatorType.Prepend, scope }); + } + + private _setIfDiffers(variable: string, mutator: vscode.EnvironmentVariableMutator & { scope: vscode.EnvironmentVariableScope | undefined }): void { + if (!mutator.scope) { + delete (mutator as any).scope; // Convenient for tests + } + const key = this.getKey(variable, mutator.scope); + const current = this.map.get(key); + if (!current || current.value !== mutator.value || current.type !== mutator.type || current.scope?.workspaceFolder?.index !== mutator.scope?.workspaceFolder?.index) { + const key = this.getKey(variable, mutator.scope); + const value: IEnvironmentVariableMutator = { variable, ...mutator }; + this.map.set(key, value); + this._onDidChangeCollection.fire(); + } + } + + get(variable: string, scope?: vscode.EnvironmentVariableScope): vscode.EnvironmentVariableMutator | undefined { + const key = this.getKey(variable, scope); + const value = this.map.get(key); + return value ? convertMutator(value) : undefined; + } + + private getKey(variable: string, scope: vscode.EnvironmentVariableScope | undefined) { + const workspaceKey = this.getWorkspaceKey(scope?.workspaceFolder); + return workspaceKey ? `${variable}:::${workspaceKey}` : variable; + } + + private getWorkspaceKey(workspaceFolder: vscode.WorkspaceFolder | undefined): string | undefined { + return workspaceFolder ? workspaceFolder.uri.toString() : undefined; + } + + forEach(callback: (variable: string, mutator: vscode.EnvironmentVariableMutator, collection: vscode.EnvironmentVariableCollection) => any, thisArg?: any): void { + this.map.forEach((value, _) => callback.call(thisArg, value.variable, convertMutator(value), this)); + } + + [Symbol.iterator](): IterableIterator<[variable: string, mutator: vscode.EnvironmentVariableMutator]> { + const map: Map = new Map(); + this.map.forEach((mutator, _key) => { + if (mutator.scope) { + // Scoped mutators are not supported via this iterator, as it returns variable as the key which is supposed to be unique. + return; + } + map.set(mutator.variable, convertMutator(mutator)); + }); + return map.entries(); + } + + delete(variable: string, scope?: vscode.EnvironmentVariableScope): void { + const key = this.getKey(variable, scope); + this.map.delete(key); + this._onDidChangeCollection.fire(); + } + + clear(scope?: vscode.EnvironmentVariableScope): void { + if (scope?.workspaceFolder) { + for (const [key, mutator] of this.map) { + if (mutator.scope?.workspaceFolder?.index === scope.workspaceFolder.index) { + this.map.delete(key); + } + } + this.clearDescription(scope); + } else { + this.map.clear(); + this.descriptionMap.clear(); + } + this._onDidChangeCollection.fire(); + } + + set description(description: string | vscode.MarkdownString | undefined) { + const key = this.getKey('', scope); + const current = this.descriptionMap.get(key); + if (!current || current.description !== description) { + let descriptionStr: string | undefined; + if (typeof description === 'string') { + descriptionStr = description; + } else { + // Only take the description before the first `\n\n`, so that the description doesn't mess up the UI + descriptionStr = description?.value.split('\n\n')[0]; + } + const value: IEnvironmentDescriptionMutator = { description: descriptionStr, scope }; + this.descriptionMap.set(key, value); + this._onDidChangeCollection.fire(); + } + } + + get description(): string | vscode.MarkdownString | undefined { + return ''; + } + + private clearDescription(scope?: vscode.EnvironmentVariableScope): void { + const key = this.getKey('', scope); + this.descriptionMap.delete(key); + } +} + +class ScopedEnvironmentVariableCollection implements vscode.EnvironmentVariableCollection { readonly map: Map = new Map(); private _description: string | vscode.MarkdownString | undefined; private _persistent: boolean = true; @@ -892,17 +1037,6 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect return this.map.size; } - getScopedEnvironmentVariableCollection(scope?: vscode.EnvironmentVariableScope): vscode.EnvironmentVariableCollection { - const scopedCollectionKey = this.getScopeKey(scope); - let scopedCollection = this.scopedCollections.get(scopedCollectionKey); - if (!scopedCollection) { - scopedCollection = new EnvironmentVariableCollection(); - this.scopedCollections.set(scopedCollectionKey, scopedCollection); - scopedCollection.onDidChangeCollection(() => this._onDidChangeCollection.fire(scope)); - } - return scopedCollection; - } - replace(variable: string, value: string): void { this._setIfDiffers(variable, { value, type: EnvironmentVariableMutatorType.Replace }); } @@ -923,14 +1057,6 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect } } - private getScopeKey(scope?: vscode.EnvironmentVariableScope): string { - return this.getWorkspaceKey(scope?.workspaceFolder) ?? ''; - } - - private getWorkspaceKey(workspaceFolder: vscode.WorkspaceFolder | undefined): string | undefined { - return workspaceFolder ? workspaceFolder.uri.toString() : undefined; - } - get(variable: string): vscode.EnvironmentVariableMutator | undefined { return this.map.get(variable); } @@ -966,6 +1092,8 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect } } + + export class WorkerExtHostTerminalService extends BaseExtHostTerminalService { constructor( @IExtHostRpcService extHostRpc: IExtHostRpcService From 44ccada022dfe82ba7545dbedb1a20a4c2e8b73a Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Thu, 11 May 2023 23:29:27 +0000 Subject: [PATCH 03/21] part 2 --- .../api/common/extHostTerminalService.ts | 67 ++++++++++++------- ...scode.proposed.envCollectionWorkspace.d.ts | 2 +- 2 files changed, 42 insertions(+), 27 deletions(-) diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index 96efea2978519..103a5707e59f1 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -830,25 +830,12 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I this._setEnvironmentVariableCollection(extension.identifier.value, collection); } return { - ...collection, getScopedEnvironmentVariableCollection(scope) { - return this.getScopedEnvironmentVariableCollection(collection!, scope); + ...collection.getScopedEnvironmentVariableCollection(undefined), getScopedEnvironmentVariableCollection(scope) { + return collection!.getScopedEnvironmentVariableCollection(scope); }, }; } - private getScopedEnvironmentVariableCollection(collection: EnvironmentVariableCollection, scope?: vscode.EnvironmentVariableScope): vscode.EnvironmentVariableCollection { - if (scope === undefined) { - return collection; - } - const key = `${scope.scope}${scope.target}`; - let scopedCollection = this._scopedEnvironmentVariableCollections.get(key); - if (!scopedCollection) { - scopedCollection = new EnvironmentVariableCollection(); - this._scopedEnvironmentVariableCollections.set(key, scopedCollection); - } - return scopedCollection; - } - private _syncEnvironmentVariableCollection(extensionIdentifier: string, collection: EnvironmentVariableCollection): void { const serialized = serializeEnvironmentVariableCollection(collection.map); const serializedDescription = serializeEnvironmentDescriptionMap(collection.descriptionMap); @@ -884,9 +871,10 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I } } -class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollection { +class EnvironmentVariableCollection { readonly map: Map = new Map(); readonly descriptionMap: Map = new Map(); + readonly scopedCollections: Map }> = new Map(); private _persistent: boolean = true; public get persistent(): boolean { return this._persistent; } @@ -908,6 +896,17 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect return this.map.size; } + getScopedEnvironmentVariableCollection(scope?: vscode.EnvironmentVariableScope): vscode.EnvironmentVariableCollection { + const scopedCollectionKey = this.getScopeKey(scope); + let scopedCollection = this.scopedCollections.get(scopedCollectionKey); + if (!scopedCollection) { + scopedCollection = new ScopedEnvironmentVariableCollection(this.getScopedMap(scope), this.getDescription(scope)); + this.scopedCollections.set(scopedCollectionKey, scopedCollection); + scopedCollection.onDidChangeCollection(() => this._onDidChangeCollection.fire()); + } + return scopedCollection; + } + replace(variable: string, value: string, scope?: vscode.EnvironmentVariableScope): void { this._setIfDiffers(variable, { value, type: EnvironmentVariableMutatorType.Replace, scope }); } @@ -934,6 +933,21 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect } } + private getScopeKey(scope?: vscode.EnvironmentVariableScope): string { + return this.getWorkspaceKey(scope?.workspaceFolder) ?? ''; + } + + private getScopedMap(scope?: vscode.EnvironmentVariableScope): Map { + const scopedMap = new Map(); + const scopeKey = this.getScopeKey(scope); + for (const [key, value] of this.map.entries()) { + if (key.endsWith(scopeKey)) { + scopedMap.set(key, value); + } + } + return scopedMap; + } + get(variable: string, scope?: vscode.EnvironmentVariableScope): vscode.EnvironmentVariableMutator | undefined { const key = this.getKey(variable, scope); const value = this.map.get(key); @@ -950,7 +964,7 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect } forEach(callback: (variable: string, mutator: vscode.EnvironmentVariableMutator, collection: vscode.EnvironmentVariableCollection) => any, thisArg?: any): void { - this.map.forEach((value, _) => callback.call(thisArg, value.variable, convertMutator(value), this)); + this.map.forEach((value, _) => callback.call(thisArg, value.variable, convertMutator(value), this.getScopedEnvironmentVariableCollection(undefined))); } [Symbol.iterator](): IterableIterator<[variable: string, mutator: vscode.EnvironmentVariableMutator]> { @@ -986,7 +1000,7 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect this._onDidChangeCollection.fire(); } - set description(description: string | vscode.MarkdownString | undefined) { + setDescription(description: string | vscode.MarkdownString | undefined, scope?: vscode.EnvironmentVariableScope): void { const key = this.getKey('', scope); const current = this.descriptionMap.get(key); if (!current || current.description !== description) { @@ -1003,8 +1017,10 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect } } - get description(): string | vscode.MarkdownString | undefined { - return ''; + private getDescription(scope?: vscode.EnvironmentVariableScope): string | vscode.MarkdownString | undefined { + const key = this.getKey('', scope); + const value = this.descriptionMap.get(key); + return value?.description; } private clearDescription(scope?: vscode.EnvironmentVariableScope): void { @@ -1014,8 +1030,6 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect } class ScopedEnvironmentVariableCollection implements vscode.EnvironmentVariableCollection { - readonly map: Map = new Map(); - private _description: string | vscode.MarkdownString | undefined; private _persistent: boolean = true; public get persistent(): boolean { return this._persistent; } @@ -1024,13 +1038,13 @@ class ScopedEnvironmentVariableCollection implements vscode.EnvironmentVariableC this._onDidChangeCollection.fire(undefined); } - protected readonly _onDidChangeCollection = new Emitter(); - get onDidChangeCollection(): Event { return this._onDidChangeCollection && this._onDidChangeCollection.event; } + protected readonly _onDidChangeCollection = new Emitter(); + get onDidChangeCollection(): Event { return this._onDidChangeCollection && this._onDidChangeCollection.event; } constructor( - serialized?: ISerializableEnvironmentVariableCollection + private readonly map: Map, + private _description: string | vscode.MarkdownString | undefined, ) { - this.map = new Map(serialized); } get size(): number { @@ -1076,6 +1090,7 @@ class ScopedEnvironmentVariableCollection implements vscode.EnvironmentVariableC clear(): void { this.map.clear(); + this._description = undefined; this._onDidChangeCollection.fire(undefined); } diff --git a/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts b/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts index 6b40fdd5c39dd..a99175f5dbda9 100644 --- a/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts +++ b/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts @@ -14,7 +14,7 @@ declare module 'vscode' { * * @param scope The scope to which the environment variable collection applies to. */ - readonly environmentVariableCollection: EnvironmentVariableCollection & { getScopedEnvironmentVariableCollection(scope?: EnvironmentVariableScope): EnvironmentVariableCollection }; + readonly environmentVariableCollection: EnvironmentVariableCollection & { getScopedEnvironmentVariableCollection(scope: EnvironmentVariableScope): EnvironmentVariableCollection }; } export type EnvironmentVariableScope = { From df10286314f04ffab06c2fd86ad625f505c7829f Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Fri, 12 May 2023 19:46:31 +0000 Subject: [PATCH 04/21] approach 2 --- .../api/common/extHostTerminalService.ts | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index 103a5707e59f1..4e1fadc91f101 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -873,10 +873,25 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I class EnvironmentVariableCollection { readonly map: Map = new Map(); - readonly descriptionMap: Map = new Map(); readonly scopedCollections: Map }> = new Map(); + readonly keyToScope = new Map(); private _persistent: boolean = true; + public get descriptionMap(): Map { + const descriptionMap: Map = new Map(); + this.scopedCollections.forEach((collection, scopeKey) => { + const description = collection.description; + let descriptionStr: string | undefined; + if (typeof description === 'string') { + descriptionStr = description; + } else { + // Only take the description before the first `\n\n`, so that the description doesn't mess up the UI + descriptionStr = description?.value.split('\n\n')[0]; + } + descriptionMap.set(scopeKey, { description: descriptionStr, scope: this.keyToScope.get(scopeKey) }); + }); + return descriptionMap; + } public get persistent(): boolean { return this._persistent; } public set persistent(value: boolean) { this._persistent = value; @@ -902,6 +917,7 @@ class EnvironmentVariableCollection { if (!scopedCollection) { scopedCollection = new ScopedEnvironmentVariableCollection(this.getScopedMap(scope), this.getDescription(scope)); this.scopedCollections.set(scopedCollectionKey, scopedCollection); + this.keyToScope.set(scopedCollectionKey, scope); scopedCollection.onDidChangeCollection(() => this._onDidChangeCollection.fire()); } return scopedCollection; @@ -941,7 +957,7 @@ class EnvironmentVariableCollection { const scopedMap = new Map(); const scopeKey = this.getScopeKey(scope); for (const [key, value] of this.map.entries()) { - if (key.endsWith(scopeKey)) { + if (key === scopeKey) { scopedMap.set(key, value); } } @@ -1017,6 +1033,10 @@ class EnvironmentVariableCollection { } } + private getDescriptionMap(scope?: vscode.EnvironmentVariableScope): Map { + + } + private getDescription(scope?: vscode.EnvironmentVariableScope): string | vscode.MarkdownString | undefined { const key = this.getKey('', scope); const value = this.descriptionMap.get(key); From 69ce8fc5118db76d236a84a508df04b59c7d2776 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Fri, 12 May 2023 21:51:49 +0000 Subject: [PATCH 05/21] approach 3 --- .../api/common/extHostTerminalService.ts | 110 ++++-------------- 1 file changed, 25 insertions(+), 85 deletions(-) diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index 4e1fadc91f101..b491d282fd352 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -874,24 +874,9 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I class EnvironmentVariableCollection { readonly map: Map = new Map(); readonly scopedCollections: Map }> = new Map(); - readonly keyToScope = new Map(); + readonly descriptionMap: Map = new Map(); private _persistent: boolean = true; - public get descriptionMap(): Map { - const descriptionMap: Map = new Map(); - this.scopedCollections.forEach((collection, scopeKey) => { - const description = collection.description; - let descriptionStr: string | undefined; - if (typeof description === 'string') { - descriptionStr = description; - } else { - // Only take the description before the first `\n\n`, so that the description doesn't mess up the UI - descriptionStr = description?.value.split('\n\n')[0]; - } - descriptionMap.set(scopeKey, { description: descriptionStr, scope: this.keyToScope.get(scopeKey) }); - }); - return descriptionMap; - } public get persistent(): boolean { return this._persistent; } public set persistent(value: boolean) { this._persistent = value; @@ -907,17 +892,12 @@ class EnvironmentVariableCollection { this.map = new Map(serialized); } - get size(): number { - return this.map.size; - } - getScopedEnvironmentVariableCollection(scope?: vscode.EnvironmentVariableScope): vscode.EnvironmentVariableCollection { const scopedCollectionKey = this.getScopeKey(scope); let scopedCollection = this.scopedCollections.get(scopedCollectionKey); if (!scopedCollection) { - scopedCollection = new ScopedEnvironmentVariableCollection(this.getScopedMap(scope), this.getDescription(scope)); + scopedCollection = new ScopedEnvironmentVariableCollection(this, scope); this.scopedCollections.set(scopedCollectionKey, scopedCollection); - this.keyToScope.set(scopedCollectionKey, scope); scopedCollection.onDidChangeCollection(() => this._onDidChangeCollection.fire()); } return scopedCollection; @@ -949,21 +929,6 @@ class EnvironmentVariableCollection { } } - private getScopeKey(scope?: vscode.EnvironmentVariableScope): string { - return this.getWorkspaceKey(scope?.workspaceFolder) ?? ''; - } - - private getScopedMap(scope?: vscode.EnvironmentVariableScope): Map { - const scopedMap = new Map(); - const scopeKey = this.getScopeKey(scope); - for (const [key, value] of this.map.entries()) { - if (key === scopeKey) { - scopedMap.set(key, value); - } - } - return scopedMap; - } - get(variable: string, scope?: vscode.EnvironmentVariableScope): vscode.EnvironmentVariableMutator | undefined { const key = this.getKey(variable, scope); const value = this.map.get(key); @@ -979,20 +944,19 @@ class EnvironmentVariableCollection { return workspaceFolder ? workspaceFolder.uri.toString() : undefined; } - forEach(callback: (variable: string, mutator: vscode.EnvironmentVariableMutator, collection: vscode.EnvironmentVariableCollection) => any, thisArg?: any): void { - this.map.forEach((value, _) => callback.call(thisArg, value.variable, convertMutator(value), this.getScopedEnvironmentVariableCollection(undefined))); + private getScopeKey(scope?: vscode.EnvironmentVariableScope): string { + return this.getWorkspaceKey(scope?.workspaceFolder) ?? ''; } - [Symbol.iterator](): IterableIterator<[variable: string, mutator: vscode.EnvironmentVariableMutator]> { - const map: Map = new Map(); - this.map.forEach((mutator, _key) => { - if (mutator.scope) { - // Scoped mutators are not supported via this iterator, as it returns variable as the key which is supposed to be unique. - return; + public getVariableMap(scope?: vscode.EnvironmentVariableScope): Map { + const scopedMap = new Map(); + const scopeKey = this.getScopeKey(scope); + for (const [key, value] of this.map.entries()) { + if (key === scopeKey) { + scopedMap.set(value.variable, value); } - map.set(mutator.variable, convertMutator(mutator)); - }); - return map.entries(); + } + return scopedMap; } delete(variable: string, scope?: vscode.EnvironmentVariableScope): void { @@ -1033,11 +997,7 @@ class EnvironmentVariableCollection { } } - private getDescriptionMap(scope?: vscode.EnvironmentVariableScope): Map { - - } - - private getDescription(scope?: vscode.EnvironmentVariableScope): string | vscode.MarkdownString | undefined { + public getDescription(scope?: vscode.EnvironmentVariableScope): string | vscode.MarkdownString | undefined { const key = this.getKey('', scope); const value = this.descriptionMap.get(key); return value?.description; @@ -1062,73 +1022,53 @@ class ScopedEnvironmentVariableCollection implements vscode.EnvironmentVariableC get onDidChangeCollection(): Event { return this._onDidChangeCollection && this._onDidChangeCollection.event; } constructor( - private readonly map: Map, - private _description: string | vscode.MarkdownString | undefined, + private readonly collection: EnvironmentVariableCollection, + private readonly scope: vscode.EnvironmentVariableScope | undefined ) { } - get size(): number { - return this.map.size; - } - replace(variable: string, value: string): void { - this._setIfDiffers(variable, { value, type: EnvironmentVariableMutatorType.Replace }); + this.collection.replace(variable, value, this.scope); } append(variable: string, value: string): void { - this._setIfDiffers(variable, { value, type: EnvironmentVariableMutatorType.Append }); + this.collection.append(variable, value, this.scope); } prepend(variable: string, value: string): void { - this._setIfDiffers(variable, { value, type: EnvironmentVariableMutatorType.Prepend }); - } - - private _setIfDiffers(variable: string, mutator: vscode.EnvironmentVariableMutator): void { - const current = this.map.get(variable); - if (!current || current.value !== mutator.value || current.type !== mutator.type) { - this.map.set(variable, mutator); - this._onDidChangeCollection.fire(undefined); - } + this.collection.prepend(variable, value, this.scope); } get(variable: string): vscode.EnvironmentVariableMutator | undefined { - return this.map.get(variable); + return this.collection.get(variable, this.scope); } forEach(callback: (variable: string, mutator: vscode.EnvironmentVariableMutator, collection: vscode.EnvironmentVariableCollection) => any, thisArg?: any): void { - this.map.forEach((value, key) => callback.call(thisArg, key, value, this)); + this.collection.getVariableMap(this.scope).forEach((value, variable) => callback.call(thisArg, variable, convertMutator(value), this), this.scope); } [Symbol.iterator](): IterableIterator<[variable: string, mutator: vscode.EnvironmentVariableMutator]> { - return this.map.entries(); + return this.collection.getVariableMap(this.scope).entries(); } delete(variable: string): void { - this.map.delete(variable); + this.collection.delete(variable, this.scope); this._onDidChangeCollection.fire(undefined); } clear(): void { - this.map.clear(); - this._description = undefined; - this._onDidChangeCollection.fire(undefined); + this.collection.clear(this.scope); } set description(description: string | vscode.MarkdownString | undefined) { - if (this._description === description) { - return; - } - this._description = description; - this._onDidChangeCollection.fire(undefined); + this.collection.setDescription(description, this.scope); } get description(): string | vscode.MarkdownString | undefined { - return this._description; + return this.collection.getDescription(this.scope); } } - - export class WorkerExtHostTerminalService extends BaseExtHostTerminalService { constructor( @IExtHostRpcService extHostRpc: IExtHostRpcService From 436a8012c017a4477a2bfea519651e37e0fa6c9a Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Fri, 12 May 2023 21:59:53 +0000 Subject: [PATCH 06/21] Make scope mandatory so we dont miss to pass it --- .../api/common/extHostTerminalService.ts | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index b491d282fd352..56a90b6ffc8cc 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -50,7 +50,7 @@ export interface IExtHostTerminalService extends ExtHostTerminalServiceShape, ID registerLinkProvider(provider: vscode.TerminalLinkProvider): vscode.Disposable; registerProfileProvider(extension: IExtensionDescription, id: string, provider: vscode.TerminalProfileProvider): vscode.Disposable; registerTerminalQuickFixProvider(id: string, extensionId: string, provider: vscode.TerminalQuickFixProvider): vscode.Disposable; - getEnvironmentVariableCollection(extension: IExtensionDescription): vscode.EnvironmentVariableCollection & { getScopedEnvironmentVariableCollection(scope?: vscode.EnvironmentVariableScope): vscode.EnvironmentVariableCollection }; + getEnvironmentVariableCollection(extension: IExtensionDescription): vscode.EnvironmentVariableCollection & { getScopedEnvironmentVariableCollection(scope: vscode.EnvironmentVariableScope | undefined): vscode.EnvironmentVariableCollection }; } export interface ITerminalInternalOptions { @@ -823,7 +823,7 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I return index; } - public getEnvironmentVariableCollection(extension: IExtensionDescription): vscode.EnvironmentVariableCollection & { getScopedEnvironmentVariableCollection(scope?: vscode.EnvironmentVariableScope): vscode.EnvironmentVariableCollection } { + public getEnvironmentVariableCollection(extension: IExtensionDescription): vscode.EnvironmentVariableCollection & { getScopedEnvironmentVariableCollection(scope: vscode.EnvironmentVariableScope | undefined): vscode.EnvironmentVariableCollection } { let collection = this._environmentVariableCollections.get(extension.identifier.value); if (!collection) { collection = new EnvironmentVariableCollection(); @@ -892,7 +892,7 @@ class EnvironmentVariableCollection { this.map = new Map(serialized); } - getScopedEnvironmentVariableCollection(scope?: vscode.EnvironmentVariableScope): vscode.EnvironmentVariableCollection { + getScopedEnvironmentVariableCollection(scope: vscode.EnvironmentVariableScope | undefined): vscode.EnvironmentVariableCollection { const scopedCollectionKey = this.getScopeKey(scope); let scopedCollection = this.scopedCollections.get(scopedCollectionKey); if (!scopedCollection) { @@ -903,15 +903,15 @@ class EnvironmentVariableCollection { return scopedCollection; } - replace(variable: string, value: string, scope?: vscode.EnvironmentVariableScope): void { + replace(variable: string, value: string, scope: vscode.EnvironmentVariableScope | undefined): void { this._setIfDiffers(variable, { value, type: EnvironmentVariableMutatorType.Replace, scope }); } - append(variable: string, value: string, scope?: vscode.EnvironmentVariableScope): void { + append(variable: string, value: string, scope: vscode.EnvironmentVariableScope | undefined): void { this._setIfDiffers(variable, { value, type: EnvironmentVariableMutatorType.Append, scope }); } - prepend(variable: string, value: string, scope?: vscode.EnvironmentVariableScope): void { + prepend(variable: string, value: string, scope: vscode.EnvironmentVariableScope | undefined): void { this._setIfDiffers(variable, { value, type: EnvironmentVariableMutatorType.Prepend, scope }); } @@ -929,7 +929,7 @@ class EnvironmentVariableCollection { } } - get(variable: string, scope?: vscode.EnvironmentVariableScope): vscode.EnvironmentVariableMutator | undefined { + get(variable: string, scope: vscode.EnvironmentVariableScope | undefined): vscode.EnvironmentVariableMutator | undefined { const key = this.getKey(variable, scope); const value = this.map.get(key); return value ? convertMutator(value) : undefined; @@ -944,11 +944,11 @@ class EnvironmentVariableCollection { return workspaceFolder ? workspaceFolder.uri.toString() : undefined; } - private getScopeKey(scope?: vscode.EnvironmentVariableScope): string { + private getScopeKey(scope: vscode.EnvironmentVariableScope | undefined): string { return this.getWorkspaceKey(scope?.workspaceFolder) ?? ''; } - public getVariableMap(scope?: vscode.EnvironmentVariableScope): Map { + public getVariableMap(scope: vscode.EnvironmentVariableScope | undefined): Map { const scopedMap = new Map(); const scopeKey = this.getScopeKey(scope); for (const [key, value] of this.map.entries()) { @@ -959,13 +959,13 @@ class EnvironmentVariableCollection { return scopedMap; } - delete(variable: string, scope?: vscode.EnvironmentVariableScope): void { + delete(variable: string, scope: vscode.EnvironmentVariableScope | undefined): void { const key = this.getKey(variable, scope); this.map.delete(key); this._onDidChangeCollection.fire(); } - clear(scope?: vscode.EnvironmentVariableScope): void { + clear(scope: vscode.EnvironmentVariableScope | undefined): void { if (scope?.workspaceFolder) { for (const [key, mutator] of this.map) { if (mutator.scope?.workspaceFolder?.index === scope.workspaceFolder.index) { @@ -980,7 +980,7 @@ class EnvironmentVariableCollection { this._onDidChangeCollection.fire(); } - setDescription(description: string | vscode.MarkdownString | undefined, scope?: vscode.EnvironmentVariableScope): void { + setDescription(description: string | vscode.MarkdownString | undefined, scope: vscode.EnvironmentVariableScope | undefined): void { const key = this.getKey('', scope); const current = this.descriptionMap.get(key); if (!current || current.description !== description) { @@ -997,25 +997,22 @@ class EnvironmentVariableCollection { } } - public getDescription(scope?: vscode.EnvironmentVariableScope): string | vscode.MarkdownString | undefined { + public getDescription(scope: vscode.EnvironmentVariableScope | undefined): string | vscode.MarkdownString | undefined { const key = this.getKey('', scope); const value = this.descriptionMap.get(key); return value?.description; } - private clearDescription(scope?: vscode.EnvironmentVariableScope): void { + private clearDescription(scope: vscode.EnvironmentVariableScope | undefined): void { const key = this.getKey('', scope); this.descriptionMap.delete(key); } } class ScopedEnvironmentVariableCollection implements vscode.EnvironmentVariableCollection { - private _persistent: boolean = true; - - public get persistent(): boolean { return this._persistent; } + public get persistent(): boolean { return this.collection.persistent; } public set persistent(value: boolean) { - this._persistent = value; - this._onDidChangeCollection.fire(undefined); + this.collection.persistent = value; } protected readonly _onDidChangeCollection = new Emitter(); From a2b0106962037f883caaf3335155cd86404e9e65 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Fri, 12 May 2023 22:02:04 +0000 Subject: [PATCH 07/21] Remove redundant --- .../api/common/extHostTerminalService.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index 56a90b6ffc8cc..6870bab354e96 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -936,18 +936,18 @@ class EnvironmentVariableCollection { } private getKey(variable: string, scope: vscode.EnvironmentVariableScope | undefined) { - const workspaceKey = this.getWorkspaceKey(scope?.workspaceFolder); - return workspaceKey ? `${variable}:::${workspaceKey}` : variable; - } - - private getWorkspaceKey(workspaceFolder: vscode.WorkspaceFolder | undefined): string | undefined { - return workspaceFolder ? workspaceFolder.uri.toString() : undefined; + const scopeKey = this.getScopeKey(scope); + return scopeKey.length ? `${variable}:::${scopeKey}` : variable; } private getScopeKey(scope: vscode.EnvironmentVariableScope | undefined): string { return this.getWorkspaceKey(scope?.workspaceFolder) ?? ''; } + private getWorkspaceKey(workspaceFolder: vscode.WorkspaceFolder | undefined): string | undefined { + return workspaceFolder ? workspaceFolder.uri.toString() : undefined; + } + public getVariableMap(scope: vscode.EnvironmentVariableScope | undefined): Map { const scopedMap = new Map(); const scopeKey = this.getScopeKey(scope); @@ -981,7 +981,7 @@ class EnvironmentVariableCollection { } setDescription(description: string | vscode.MarkdownString | undefined, scope: vscode.EnvironmentVariableScope | undefined): void { - const key = this.getKey('', scope); + const key = this.getScopeKey(scope); const current = this.descriptionMap.get(key); if (!current || current.description !== description) { let descriptionStr: string | undefined; @@ -998,7 +998,7 @@ class EnvironmentVariableCollection { } public getDescription(scope: vscode.EnvironmentVariableScope | undefined): string | vscode.MarkdownString | undefined { - const key = this.getKey('', scope); + const key = this.getScopeKey(scope); const value = this.descriptionMap.get(key); return value?.description; } From 16a80939f3240b42175103c831bc50bd470801a1 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Fri, 12 May 2023 22:04:32 +0000 Subject: [PATCH 08/21] More --- src/vs/workbench/api/common/extHostTerminalService.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index 6870bab354e96..5acc0fd5240cf 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -999,12 +999,11 @@ class EnvironmentVariableCollection { public getDescription(scope: vscode.EnvironmentVariableScope | undefined): string | vscode.MarkdownString | undefined { const key = this.getScopeKey(scope); - const value = this.descriptionMap.get(key); - return value?.description; + return this.descriptionMap.get(key)?.description; } private clearDescription(scope: vscode.EnvironmentVariableScope | undefined): void { - const key = this.getKey('', scope); + const key = this.getScopeKey(scope); this.descriptionMap.delete(key); } } From 76f8b2cb337ac398e738353ba4f8d043bdbf3649 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Fri, 12 May 2023 22:40:49 +0000 Subject: [PATCH 09/21] Try to fix compile errors --- src/vs/workbench/api/common/extHostTerminalService.ts | 4 ++-- src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index 5acc0fd5240cf..3b80ee17492dd 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -50,7 +50,7 @@ export interface IExtHostTerminalService extends ExtHostTerminalServiceShape, ID registerLinkProvider(provider: vscode.TerminalLinkProvider): vscode.Disposable; registerProfileProvider(extension: IExtensionDescription, id: string, provider: vscode.TerminalProfileProvider): vscode.Disposable; registerTerminalQuickFixProvider(id: string, extensionId: string, provider: vscode.TerminalQuickFixProvider): vscode.Disposable; - getEnvironmentVariableCollection(extension: IExtensionDescription): vscode.EnvironmentVariableCollection & { getScopedEnvironmentVariableCollection(scope: vscode.EnvironmentVariableScope | undefined): vscode.EnvironmentVariableCollection }; + getEnvironmentVariableCollection(extension: IExtensionDescription): vscode.EnvironmentVariableCollection | { getScopedEnvironmentVariableCollection(scope: vscode.EnvironmentVariableScope | undefined): vscode.EnvironmentVariableCollection }; } export interface ITerminalInternalOptions { @@ -823,7 +823,7 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I return index; } - public getEnvironmentVariableCollection(extension: IExtensionDescription): vscode.EnvironmentVariableCollection & { getScopedEnvironmentVariableCollection(scope: vscode.EnvironmentVariableScope | undefined): vscode.EnvironmentVariableCollection } { + public getEnvironmentVariableCollection(extension: IExtensionDescription): vscode.EnvironmentVariableCollection | { getScopedEnvironmentVariableCollection(scope: vscode.EnvironmentVariableScope | undefined): vscode.EnvironmentVariableCollection } { let collection = this._environmentVariableCollections.get(extension.identifier.value); if (!collection) { collection = new EnvironmentVariableCollection(); diff --git a/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts b/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts index a99175f5dbda9..2c23fd3487aa0 100644 --- a/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts +++ b/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts @@ -14,7 +14,7 @@ declare module 'vscode' { * * @param scope The scope to which the environment variable collection applies to. */ - readonly environmentVariableCollection: EnvironmentVariableCollection & { getScopedEnvironmentVariableCollection(scope: EnvironmentVariableScope): EnvironmentVariableCollection }; + readonly environmentVariableCollection: EnvironmentVariableCollection | { getScopedEnvironmentVariableCollection(scope: EnvironmentVariableScope): EnvironmentVariableCollection }; } export type EnvironmentVariableScope = { From 4a0d85d769211660edee9845fa729de3afdccfbd Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Fri, 12 May 2023 23:21:02 +0000 Subject: [PATCH 10/21] Code review --- src/vs/workbench/api/common/extHostTerminalService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index 3b80ee17492dd..53189a935c46f 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -873,7 +873,7 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I class EnvironmentVariableCollection { readonly map: Map = new Map(); - readonly scopedCollections: Map }> = new Map(); + private readonly scopedCollections: Map = new Map(); readonly descriptionMap: Map = new Map(); private _persistent: boolean = true; From 0a521c6123b953b8d76e4e65a28279579606652a Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Fri, 12 May 2023 23:21:54 +0000 Subject: [PATCH 11/21] More --- src/vs/workbench/api/common/extHostTerminalService.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index 53189a935c46f..efc7e0e33f1a3 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -830,7 +830,8 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I this._setEnvironmentVariableCollection(extension.identifier.value, collection); } return { - ...collection.getScopedEnvironmentVariableCollection(undefined), getScopedEnvironmentVariableCollection(scope) { + ...collection.getScopedEnvironmentVariableCollection(undefined), + getScopedEnvironmentVariableCollection(scope) { return collection!.getScopedEnvironmentVariableCollection(scope); }, }; From 0185d27a7af45dabd2481e1d8eacdeb467cd7fba Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Fri, 12 May 2023 23:31:29 +0000 Subject: [PATCH 12/21] Add `IDefaultEnvironmentVariableCollection` --- src/vs/workbench/api/common/extHostTerminalService.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index efc7e0e33f1a3..323d39205d483 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -50,9 +50,9 @@ export interface IExtHostTerminalService extends ExtHostTerminalServiceShape, ID registerLinkProvider(provider: vscode.TerminalLinkProvider): vscode.Disposable; registerProfileProvider(extension: IExtensionDescription, id: string, provider: vscode.TerminalProfileProvider): vscode.Disposable; registerTerminalQuickFixProvider(id: string, extensionId: string, provider: vscode.TerminalQuickFixProvider): vscode.Disposable; - getEnvironmentVariableCollection(extension: IExtensionDescription): vscode.EnvironmentVariableCollection | { getScopedEnvironmentVariableCollection(scope: vscode.EnvironmentVariableScope | undefined): vscode.EnvironmentVariableCollection }; + getEnvironmentVariableCollection(extension: IExtensionDescription): IDefaultEnvironmentVariableCollection; } - +type IDefaultEnvironmentVariableCollection = vscode.EnvironmentVariableCollection | { getScopedEnvironmentVariableCollection(scope: vscode.EnvironmentVariableScope | undefined): vscode.EnvironmentVariableCollection }; export interface ITerminalInternalOptions { isFeatureTerminal?: boolean; useShellEnvironment?: boolean; @@ -823,7 +823,7 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I return index; } - public getEnvironmentVariableCollection(extension: IExtensionDescription): vscode.EnvironmentVariableCollection | { getScopedEnvironmentVariableCollection(scope: vscode.EnvironmentVariableScope | undefined): vscode.EnvironmentVariableCollection } { + public getEnvironmentVariableCollection(extension: IExtensionDescription): IDefaultEnvironmentVariableCollection { let collection = this._environmentVariableCollections.get(extension.identifier.value); if (!collection) { collection = new EnvironmentVariableCollection(); From 3a4c2b151a563c4c9f919923591437eb00882ff3 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Thu, 18 May 2023 17:54:22 +0000 Subject: [PATCH 13/21] Comment out the proposal to fix compile errors --- .../api/common/extHostExtensionService.ts | 5 ++++- ...vscode.proposed.envCollectionWorkspace.d.ts | 18 +++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/vs/workbench/api/common/extHostExtensionService.ts b/src/vs/workbench/api/common/extHostExtensionService.ts index afe2939e5b842..689b944b00af5 100644 --- a/src/vs/workbench/api/common/extHostExtensionService.ts +++ b/src/vs/workbench/api/common/extHostExtensionService.ts @@ -522,7 +522,10 @@ export abstract class AbstractExtHostExtensionService extends Disposable impleme checkProposedApiEnabled(extensionDescription, 'extensionRuntime'); return that.extensionRuntime; }, - get environmentVariableCollection() { return that._extHostTerminalService.getEnvironmentVariableCollection(extensionDescription); }, + get environmentVariableCollection() { + // TODO: Remove `as` cast once workspace collection proposal is finalized. + return (that._extHostTerminalService.getEnvironmentVariableCollection(extensionDescription) as vscode.EnvironmentVariableCollection); + }, get messagePassingProtocol() { if (!messagePassingProtocol) { if (!messagePort) { diff --git a/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts b/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts index 2c23fd3487aa0..089990eccef09 100644 --- a/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts +++ b/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts @@ -7,15 +7,15 @@ declare module 'vscode' { // https://github.com/microsoft/vscode/issues/182069 - export interface ExtensionContext { - /** - * Gets the extension's environment variable collection for this workspace, enabling changes - * to be applied to terminal environment variables. - * - * @param scope The scope to which the environment variable collection applies to. - */ - readonly environmentVariableCollection: EnvironmentVariableCollection | { getScopedEnvironmentVariableCollection(scope: EnvironmentVariableScope): EnvironmentVariableCollection }; - } + // export interface ExtensionContext { + // /** + // * Gets the extension's environment variable collection for this workspace, enabling changes + // * to be applied to terminal environment variables. + // * + // * @param scope The scope to which the environment variable collection applies to. + // */ + // readonly environmentVariableCollection: EnvironmentVariableCollection | { getScopedEnvironmentVariableCollection(scope: EnvironmentVariableScope): EnvironmentVariableCollection }; + // } export type EnvironmentVariableScope = { /** From 88799ca21520dda60c148c025924211f03862137 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Thu, 18 May 2023 18:05:47 +0000 Subject: [PATCH 14/21] Temporarily finalize `getScopedEnvironmentVariableCollection` --- .../api/common/extHostExtensionService.ts | 3 +-- .../api/common/extHostTerminalService.ts | 2 +- src/vscode-dts/vscode.d.ts | 2 +- ...vscode.proposed.envCollectionWorkspace.d.ts | 18 +++++++++--------- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/vs/workbench/api/common/extHostExtensionService.ts b/src/vs/workbench/api/common/extHostExtensionService.ts index 689b944b00af5..d91bb610381f5 100644 --- a/src/vs/workbench/api/common/extHostExtensionService.ts +++ b/src/vs/workbench/api/common/extHostExtensionService.ts @@ -523,8 +523,7 @@ export abstract class AbstractExtHostExtensionService extends Disposable impleme return that.extensionRuntime; }, get environmentVariableCollection() { - // TODO: Remove `as` cast once workspace collection proposal is finalized. - return (that._extHostTerminalService.getEnvironmentVariableCollection(extensionDescription) as vscode.EnvironmentVariableCollection); + return that._extHostTerminalService.getEnvironmentVariableCollection(extensionDescription); }, get messagePassingProtocol() { if (!messagePassingProtocol) { diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index 323d39205d483..7d4feecb0c23c 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -52,7 +52,7 @@ export interface IExtHostTerminalService extends ExtHostTerminalServiceShape, ID registerTerminalQuickFixProvider(id: string, extensionId: string, provider: vscode.TerminalQuickFixProvider): vscode.Disposable; getEnvironmentVariableCollection(extension: IExtensionDescription): IDefaultEnvironmentVariableCollection; } -type IDefaultEnvironmentVariableCollection = vscode.EnvironmentVariableCollection | { getScopedEnvironmentVariableCollection(scope: vscode.EnvironmentVariableScope | undefined): vscode.EnvironmentVariableCollection }; +type IDefaultEnvironmentVariableCollection = vscode.EnvironmentVariableCollection & { getScopedEnvironmentVariableCollection(scope: vscode.EnvironmentVariableScope | undefined): vscode.EnvironmentVariableCollection }; export interface ITerminalInternalOptions { isFeatureTerminal?: boolean; useShellEnvironment?: boolean; diff --git a/src/vscode-dts/vscode.d.ts b/src/vscode-dts/vscode.d.ts index 300a91280811f..931b93d798006 100644 --- a/src/vscode-dts/vscode.d.ts +++ b/src/vscode-dts/vscode.d.ts @@ -7163,7 +7163,7 @@ declare module 'vscode' { * Gets the extension's environment variable collection for this workspace, enabling changes * to be applied to terminal environment variables. */ - readonly environmentVariableCollection: EnvironmentVariableCollection; + readonly environmentVariableCollection: EnvironmentVariableCollection & { getScopedEnvironmentVariableCollection(scope: EnvironmentVariableScope): EnvironmentVariableCollection }; /** * Get the absolute path of a resource contained in the extension. diff --git a/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts b/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts index 089990eccef09..a99175f5dbda9 100644 --- a/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts +++ b/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts @@ -7,15 +7,15 @@ declare module 'vscode' { // https://github.com/microsoft/vscode/issues/182069 - // export interface ExtensionContext { - // /** - // * Gets the extension's environment variable collection for this workspace, enabling changes - // * to be applied to terminal environment variables. - // * - // * @param scope The scope to which the environment variable collection applies to. - // */ - // readonly environmentVariableCollection: EnvironmentVariableCollection | { getScopedEnvironmentVariableCollection(scope: EnvironmentVariableScope): EnvironmentVariableCollection }; - // } + export interface ExtensionContext { + /** + * Gets the extension's environment variable collection for this workspace, enabling changes + * to be applied to terminal environment variables. + * + * @param scope The scope to which the environment variable collection applies to. + */ + readonly environmentVariableCollection: EnvironmentVariableCollection & { getScopedEnvironmentVariableCollection(scope: EnvironmentVariableScope): EnvironmentVariableCollection }; + } export type EnvironmentVariableScope = { /** From affca3b3f17f044bb63d8e594f6e5c89d050eb81 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Thu, 18 May 2023 18:12:19 +0000 Subject: [PATCH 15/21] Fix error --- src/vscode-dts/vscode.d.ts | 7 +++++ ...scode.proposed.envCollectionWorkspace.d.ts | 30 +++++++++---------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/vscode-dts/vscode.d.ts b/src/vscode-dts/vscode.d.ts index 931b93d798006..3e0131f88f1a2 100644 --- a/src/vscode-dts/vscode.d.ts +++ b/src/vscode-dts/vscode.d.ts @@ -11319,6 +11319,13 @@ declare module 'vscode' { clear(): void; } + export type EnvironmentVariableScope = { + /** + * Any specific workspace folder to get collection for. If unspecified, collection applicable to all workspace folders is returned. + */ + workspaceFolder?: WorkspaceFolder; + }; + /** * A location in the editor at which progress information can be shown. It depends on the * location how progress is visually represented. diff --git a/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts b/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts index a99175f5dbda9..2cf032f648877 100644 --- a/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts +++ b/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts @@ -7,22 +7,22 @@ declare module 'vscode' { // https://github.com/microsoft/vscode/issues/182069 - export interface ExtensionContext { - /** - * Gets the extension's environment variable collection for this workspace, enabling changes - * to be applied to terminal environment variables. - * - * @param scope The scope to which the environment variable collection applies to. - */ - readonly environmentVariableCollection: EnvironmentVariableCollection & { getScopedEnvironmentVariableCollection(scope: EnvironmentVariableScope): EnvironmentVariableCollection }; - } + // export interface ExtensionContext { + // /** + // * Gets the extension's environment variable collection for this workspace, enabling changes + // * to be applied to terminal environment variables. + // * + // * @param scope The scope to which the environment variable collection applies to. + // */ + // readonly environmentVariableCollection: EnvironmentVariableCollection & { getScopedEnvironmentVariableCollection(scope: EnvironmentVariableScope): EnvironmentVariableCollection }; + // } - export type EnvironmentVariableScope = { - /** - * Any specific workspace folder to get collection for. If unspecified, collection applicable to all workspace folders is returned. - */ - workspaceFolder?: WorkspaceFolder; - }; + // export type EnvironmentVariableScope = { + // /** + // * Any specific workspace folder to get collection for. If unspecified, collection applicable to all workspace folders is returned. + // */ + // workspaceFolder?: WorkspaceFolder; + // }; export interface EnvironmentVariableCollection extends Iterable<[variable: string, mutator: EnvironmentVariableMutator]> { /** From 0874a6a7149967f2e8ea252d9d7583ef65f46785 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Thu, 18 May 2023 18:34:33 +0000 Subject: [PATCH 16/21] Do not use spread --- .../api/common/extHostTerminalService.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index 7d4feecb0c23c..56fa45ea89af3 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -829,12 +829,7 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I collection = new EnvironmentVariableCollection(); this._setEnvironmentVariableCollection(extension.identifier.value, collection); } - return { - ...collection.getScopedEnvironmentVariableCollection(undefined), - getScopedEnvironmentVariableCollection(scope) { - return collection!.getScopedEnvironmentVariableCollection(scope); - }, - }; + return collection.getScopedEnvironmentVariableCollection(undefined); } private _syncEnvironmentVariableCollection(extensionIdentifier: string, collection: EnvironmentVariableCollection): void { @@ -893,7 +888,7 @@ class EnvironmentVariableCollection { this.map = new Map(serialized); } - getScopedEnvironmentVariableCollection(scope: vscode.EnvironmentVariableScope | undefined): vscode.EnvironmentVariableCollection { + getScopedEnvironmentVariableCollection(scope: vscode.EnvironmentVariableScope | undefined): IDefaultEnvironmentVariableCollection { const scopedCollectionKey = this.getScopeKey(scope); let scopedCollection = this.scopedCollections.get(scopedCollectionKey); if (!scopedCollection) { @@ -1009,7 +1004,7 @@ class EnvironmentVariableCollection { } } -class ScopedEnvironmentVariableCollection implements vscode.EnvironmentVariableCollection { +class ScopedEnvironmentVariableCollection implements vscode.EnvironmentVariableCollection, IDefaultEnvironmentVariableCollection { public get persistent(): boolean { return this.collection.persistent; } public set persistent(value: boolean) { this.collection.persistent = value; @@ -1024,6 +1019,10 @@ class ScopedEnvironmentVariableCollection implements vscode.EnvironmentVariableC ) { } + getScopedEnvironmentVariableCollection() { + return this.collection.getScopedEnvironmentVariableCollection(this.scope); + } + replace(variable: string, value: string): void { this.collection.replace(variable, value, this.scope); } From 5749e3d9ff808fed0730b29589c8b45199dd3e93 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Thu, 18 May 2023 18:40:24 +0000 Subject: [PATCH 17/21] Revert "Fix error" This reverts commit affca3b3f17f044bb63d8e594f6e5c89d050eb81. --- src/vscode-dts/vscode.d.ts | 7 ----- ...scode.proposed.envCollectionWorkspace.d.ts | 30 +++++++++---------- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/vscode-dts/vscode.d.ts b/src/vscode-dts/vscode.d.ts index 3e0131f88f1a2..931b93d798006 100644 --- a/src/vscode-dts/vscode.d.ts +++ b/src/vscode-dts/vscode.d.ts @@ -11319,13 +11319,6 @@ declare module 'vscode' { clear(): void; } - export type EnvironmentVariableScope = { - /** - * Any specific workspace folder to get collection for. If unspecified, collection applicable to all workspace folders is returned. - */ - workspaceFolder?: WorkspaceFolder; - }; - /** * A location in the editor at which progress information can be shown. It depends on the * location how progress is visually represented. diff --git a/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts b/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts index 2cf032f648877..a99175f5dbda9 100644 --- a/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts +++ b/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts @@ -7,22 +7,22 @@ declare module 'vscode' { // https://github.com/microsoft/vscode/issues/182069 - // export interface ExtensionContext { - // /** - // * Gets the extension's environment variable collection for this workspace, enabling changes - // * to be applied to terminal environment variables. - // * - // * @param scope The scope to which the environment variable collection applies to. - // */ - // readonly environmentVariableCollection: EnvironmentVariableCollection & { getScopedEnvironmentVariableCollection(scope: EnvironmentVariableScope): EnvironmentVariableCollection }; - // } + export interface ExtensionContext { + /** + * Gets the extension's environment variable collection for this workspace, enabling changes + * to be applied to terminal environment variables. + * + * @param scope The scope to which the environment variable collection applies to. + */ + readonly environmentVariableCollection: EnvironmentVariableCollection & { getScopedEnvironmentVariableCollection(scope: EnvironmentVariableScope): EnvironmentVariableCollection }; + } - // export type EnvironmentVariableScope = { - // /** - // * Any specific workspace folder to get collection for. If unspecified, collection applicable to all workspace folders is returned. - // */ - // workspaceFolder?: WorkspaceFolder; - // }; + export type EnvironmentVariableScope = { + /** + * Any specific workspace folder to get collection for. If unspecified, collection applicable to all workspace folders is returned. + */ + workspaceFolder?: WorkspaceFolder; + }; export interface EnvironmentVariableCollection extends Iterable<[variable: string, mutator: EnvironmentVariableMutator]> { /** From 616fa578c861a8f0220653cae4f4846fc7641b2b Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Thu, 18 May 2023 18:40:29 +0000 Subject: [PATCH 18/21] Revert "Temporarily finalize `getScopedEnvironmentVariableCollection`" This reverts commit 88799ca21520dda60c148c025924211f03862137. --- .../api/common/extHostExtensionService.ts | 3 ++- .../api/common/extHostTerminalService.ts | 2 +- src/vscode-dts/vscode.d.ts | 2 +- ...vscode.proposed.envCollectionWorkspace.d.ts | 18 +++++++++--------- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/vs/workbench/api/common/extHostExtensionService.ts b/src/vs/workbench/api/common/extHostExtensionService.ts index d91bb610381f5..689b944b00af5 100644 --- a/src/vs/workbench/api/common/extHostExtensionService.ts +++ b/src/vs/workbench/api/common/extHostExtensionService.ts @@ -523,7 +523,8 @@ export abstract class AbstractExtHostExtensionService extends Disposable impleme return that.extensionRuntime; }, get environmentVariableCollection() { - return that._extHostTerminalService.getEnvironmentVariableCollection(extensionDescription); + // TODO: Remove `as` cast once workspace collection proposal is finalized. + return (that._extHostTerminalService.getEnvironmentVariableCollection(extensionDescription) as vscode.EnvironmentVariableCollection); }, get messagePassingProtocol() { if (!messagePassingProtocol) { diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index 56fa45ea89af3..e561cf6c822a8 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -52,7 +52,7 @@ export interface IExtHostTerminalService extends ExtHostTerminalServiceShape, ID registerTerminalQuickFixProvider(id: string, extensionId: string, provider: vscode.TerminalQuickFixProvider): vscode.Disposable; getEnvironmentVariableCollection(extension: IExtensionDescription): IDefaultEnvironmentVariableCollection; } -type IDefaultEnvironmentVariableCollection = vscode.EnvironmentVariableCollection & { getScopedEnvironmentVariableCollection(scope: vscode.EnvironmentVariableScope | undefined): vscode.EnvironmentVariableCollection }; +type IDefaultEnvironmentVariableCollection = vscode.EnvironmentVariableCollection | { getScopedEnvironmentVariableCollection(scope: vscode.EnvironmentVariableScope | undefined): vscode.EnvironmentVariableCollection }; export interface ITerminalInternalOptions { isFeatureTerminal?: boolean; useShellEnvironment?: boolean; diff --git a/src/vscode-dts/vscode.d.ts b/src/vscode-dts/vscode.d.ts index 931b93d798006..300a91280811f 100644 --- a/src/vscode-dts/vscode.d.ts +++ b/src/vscode-dts/vscode.d.ts @@ -7163,7 +7163,7 @@ declare module 'vscode' { * Gets the extension's environment variable collection for this workspace, enabling changes * to be applied to terminal environment variables. */ - readonly environmentVariableCollection: EnvironmentVariableCollection & { getScopedEnvironmentVariableCollection(scope: EnvironmentVariableScope): EnvironmentVariableCollection }; + readonly environmentVariableCollection: EnvironmentVariableCollection; /** * Get the absolute path of a resource contained in the extension. diff --git a/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts b/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts index a99175f5dbda9..089990eccef09 100644 --- a/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts +++ b/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts @@ -7,15 +7,15 @@ declare module 'vscode' { // https://github.com/microsoft/vscode/issues/182069 - export interface ExtensionContext { - /** - * Gets the extension's environment variable collection for this workspace, enabling changes - * to be applied to terminal environment variables. - * - * @param scope The scope to which the environment variable collection applies to. - */ - readonly environmentVariableCollection: EnvironmentVariableCollection & { getScopedEnvironmentVariableCollection(scope: EnvironmentVariableScope): EnvironmentVariableCollection }; - } + // export interface ExtensionContext { + // /** + // * Gets the extension's environment variable collection for this workspace, enabling changes + // * to be applied to terminal environment variables. + // * + // * @param scope The scope to which the environment variable collection applies to. + // */ + // readonly environmentVariableCollection: EnvironmentVariableCollection | { getScopedEnvironmentVariableCollection(scope: EnvironmentVariableScope): EnvironmentVariableCollection }; + // } export type EnvironmentVariableScope = { /** From db774adddd340323ff7ef196c39d3a0a0f1f67db Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Thu, 18 May 2023 18:54:02 +0000 Subject: [PATCH 19/21] Simplify --- src/vs/workbench/api/common/extHostTerminalService.ts | 10 +++++----- .../vscode.proposed.envCollectionWorkspace.d.ts | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index e561cf6c822a8..db0ea926adeab 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -50,9 +50,9 @@ export interface IExtHostTerminalService extends ExtHostTerminalServiceShape, ID registerLinkProvider(provider: vscode.TerminalLinkProvider): vscode.Disposable; registerProfileProvider(extension: IExtensionDescription, id: string, provider: vscode.TerminalProfileProvider): vscode.Disposable; registerTerminalQuickFixProvider(id: string, extensionId: string, provider: vscode.TerminalQuickFixProvider): vscode.Disposable; - getEnvironmentVariableCollection(extension: IExtensionDescription): IDefaultEnvironmentVariableCollection; + getEnvironmentVariableCollection(extension: IExtensionDescription): IEnvironmentVariableCollection; } -type IDefaultEnvironmentVariableCollection = vscode.EnvironmentVariableCollection | { getScopedEnvironmentVariableCollection(scope: vscode.EnvironmentVariableScope | undefined): vscode.EnvironmentVariableCollection }; +type IEnvironmentVariableCollection = vscode.EnvironmentVariableCollection & { getScopedEnvironmentVariableCollection(scope: vscode.EnvironmentVariableScope | undefined): vscode.EnvironmentVariableCollection }; export interface ITerminalInternalOptions { isFeatureTerminal?: boolean; useShellEnvironment?: boolean; @@ -823,7 +823,7 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I return index; } - public getEnvironmentVariableCollection(extension: IExtensionDescription): IDefaultEnvironmentVariableCollection { + public getEnvironmentVariableCollection(extension: IExtensionDescription): IEnvironmentVariableCollection { let collection = this._environmentVariableCollections.get(extension.identifier.value); if (!collection) { collection = new EnvironmentVariableCollection(); @@ -888,7 +888,7 @@ class EnvironmentVariableCollection { this.map = new Map(serialized); } - getScopedEnvironmentVariableCollection(scope: vscode.EnvironmentVariableScope | undefined): IDefaultEnvironmentVariableCollection { + getScopedEnvironmentVariableCollection(scope: vscode.EnvironmentVariableScope | undefined): IEnvironmentVariableCollection { const scopedCollectionKey = this.getScopeKey(scope); let scopedCollection = this.scopedCollections.get(scopedCollectionKey); if (!scopedCollection) { @@ -1004,7 +1004,7 @@ class EnvironmentVariableCollection { } } -class ScopedEnvironmentVariableCollection implements vscode.EnvironmentVariableCollection, IDefaultEnvironmentVariableCollection { +class ScopedEnvironmentVariableCollection implements vscode.EnvironmentVariableCollection, IEnvironmentVariableCollection { public get persistent(): boolean { return this.collection.persistent; } public set persistent(value: boolean) { this.collection.persistent = value; diff --git a/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts b/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts index 089990eccef09..d778e53e5086f 100644 --- a/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts +++ b/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts @@ -14,7 +14,7 @@ declare module 'vscode' { // * // * @param scope The scope to which the environment variable collection applies to. // */ - // readonly environmentVariableCollection: EnvironmentVariableCollection | { getScopedEnvironmentVariableCollection(scope: EnvironmentVariableScope): EnvironmentVariableCollection }; + // readonly environmentVariableCollection: EnvironmentVariableCollection & { getScopedEnvironmentVariableCollection(scope: EnvironmentVariableScope): EnvironmentVariableCollection }; // } export type EnvironmentVariableScope = { From 64ee37a32dc3c38fa0ed5559d109b42c2183276e Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Thu, 18 May 2023 18:56:05 +0000 Subject: [PATCH 20/21] Change how we get variable map --- src/vs/workbench/api/common/extHostTerminalService.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index db0ea926adeab..e20dfbd98e907 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -945,14 +945,13 @@ class EnvironmentVariableCollection { } public getVariableMap(scope: vscode.EnvironmentVariableScope | undefined): Map { - const scopedMap = new Map(); - const scopeKey = this.getScopeKey(scope); - for (const [key, value] of this.map.entries()) { - if (key === scopeKey) { - scopedMap.set(value.variable, value); + const map = new Map(); + for (const [key, value] of this.map) { + if (this.getScopeKey(value.scope) === this.getScopeKey(scope)) { + map.set(key, value); } } - return scopedMap; + return map; } delete(variable: string, scope: vscode.EnvironmentVariableScope | undefined): void { From c2df3b75a79ec9e907e351242ebd78fbce4b1dd1 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Thu, 18 May 2023 19:09:40 +0000 Subject: [PATCH 21/21] Undo unnecessary cast --- src/vs/workbench/api/common/extHostExtensionService.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/vs/workbench/api/common/extHostExtensionService.ts b/src/vs/workbench/api/common/extHostExtensionService.ts index 689b944b00af5..afe2939e5b842 100644 --- a/src/vs/workbench/api/common/extHostExtensionService.ts +++ b/src/vs/workbench/api/common/extHostExtensionService.ts @@ -522,10 +522,7 @@ export abstract class AbstractExtHostExtensionService extends Disposable impleme checkProposedApiEnabled(extensionDescription, 'extensionRuntime'); return that.extensionRuntime; }, - get environmentVariableCollection() { - // TODO: Remove `as` cast once workspace collection proposal is finalized. - return (that._extHostTerminalService.getEnvironmentVariableCollection(extensionDescription) as vscode.EnvironmentVariableCollection); - }, + get environmentVariableCollection() { return that._extHostTerminalService.getEnvironmentVariableCollection(extensionDescription); }, get messagePassingProtocol() { if (!messagePassingProtocol) { if (!messagePort) {