From 76a7d034b9194c01ba4fa1a2725bc48fd0b21348 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Wed, 5 Apr 2023 20:57:54 +0000 Subject: [PATCH 01/68] Add proposed API --- .../common/extensionsApiProposals.ts | 1 + ...scode.proposed.envCollectionWorkspace.d.ts | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts diff --git a/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts b/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts index c7422d3e8cb..dc816bca8e6 100644 --- a/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts +++ b/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts @@ -30,6 +30,7 @@ export const allApiProposals = Object.freeze({ dropMetadata: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.dropMetadata.d.ts', editSessionIdentityProvider: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.editSessionIdentityProvider.d.ts', editorInsets: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.editorInsets.d.ts', + envCollectionWorkspace: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts', envShellEvent: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.envShellEvent.d.ts', extensionRuntime: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.extensionRuntime.d.ts', extensionsAny: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.extensionsAny.d.ts', diff --git a/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts b/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts new file mode 100644 index 00000000000..27fd37d2b38 --- /dev/null +++ b/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts @@ -0,0 +1,29 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +declare module 'vscode' { + + // https://github.com/microsoft/vscode/issues/171173 + + export interface EnvironmentVariableMutator { + readonly type: EnvironmentVariableMutatorType; + readonly value: string; + readonly scope: EnvironmentVariableScope | undefined; + } + + export interface EnvironmentVariableCollection extends Iterable<[variable: string, mutator: EnvironmentVariableMutator]> { + replace(variable: string, value: string, scope?: EnvironmentVariableScope): void; + append(variable: string, value: string, scope?: EnvironmentVariableScope): void; + prepend(variable: string, value: string, scope?: EnvironmentVariableScope): void; + } + + export type EnvironmentVariableScope = { + /** + * The workspace folder to which this environment variable collection applies to. + * If unspecified, the collection applies to all workspace folders. + */ + workspaceFolder?: WorkspaceFolder; + }; +} From 72d1a8e24430b37d2b4a720960c656a33b6c4f76 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Wed, 5 Apr 2023 20:59:46 +0000 Subject: [PATCH 02/68] Add scope parameter --- .../terminal/common/environmentVariable.ts | 6 ++ .../common/environmentVariableCollection.ts | 3 +- .../api/common/extHostTerminalService.ts | 12 +-- .../environmentVariableCollection.test.ts | 102 +++++++++--------- .../common/environmentVariableService.test.ts | 24 ++--- .../common/environmentVariableShared.test.ts | 16 +-- 6 files changed, 85 insertions(+), 78 deletions(-) diff --git a/src/vs/platform/terminal/common/environmentVariable.ts b/src/vs/platform/terminal/common/environmentVariable.ts index f61231e92d1..35ead1e3f40 100644 --- a/src/vs/platform/terminal/common/environmentVariable.ts +++ b/src/vs/platform/terminal/common/environmentVariable.ts @@ -4,6 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { IProcessEnvironment } from 'vs/base/common/platform'; +import { IWorkspaceFolderData } from 'vs/platform/workspace/common/workspace'; export enum EnvironmentVariableMutatorType { Replace = 1, @@ -18,9 +19,14 @@ export enum EnvironmentVariableMutatorType { export interface IEnvironmentVariableMutator { readonly value: string; readonly type: EnvironmentVariableMutatorType; + readonly scope: EnvironmentVariableScope | undefined; // readonly timing?: EnvironmentVariableMutatorTiming; } +export type EnvironmentVariableScope = { + workspaceFolder?: IWorkspaceFolderData; +}; + export interface IEnvironmentVariableCollection { readonly map: ReadonlyMap; } diff --git a/src/vs/platform/terminal/common/environmentVariableCollection.ts b/src/vs/platform/terminal/common/environmentVariableCollection.ts index 29fb4b721fb..03a29c81fc7 100644 --- a/src/vs/platform/terminal/common/environmentVariableCollection.ts +++ b/src/vs/platform/terminal/common/environmentVariableCollection.ts @@ -43,7 +43,8 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa entry.unshift({ extensionIdentifier, value: mutator.value, - type: mutator.type + type: mutator.type, + scope: mutator.scope }); next = it.next(); diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index e9f3d90d605..91e4e689e49 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -889,16 +889,16 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect return this.map.size; } - replace(variable: string, value: string): void { - this._setIfDiffers(variable, { value, type: EnvironmentVariableMutatorType.Replace }); + replace(variable: string, value: string, scope?: vscode.EnvironmentVariableScope): void { + this._setIfDiffers(variable, { value, type: EnvironmentVariableMutatorType.Replace, scope }); } - append(variable: string, value: string): void { - this._setIfDiffers(variable, { value, type: EnvironmentVariableMutatorType.Append }); + append(variable: string, value: string, scope?: vscode.EnvironmentVariableScope): void { + this._setIfDiffers(variable, { value, type: EnvironmentVariableMutatorType.Append, scope }); } - prepend(variable: string, value: string): void { - this._setIfDiffers(variable, { value, type: EnvironmentVariableMutatorType.Prepend }); + prepend(variable: string, value: string, scope?: vscode.EnvironmentVariableScope): void { + this._setIfDiffers(variable, { value, type: EnvironmentVariableMutatorType.Prepend, scope }); } private _setIfDiffers(variable: string, mutator: vscode.EnvironmentVariableMutator): void { diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts index 3ecd9b962e7..7c869e10281 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts @@ -15,22 +15,22 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend }] + ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }] ]) }], ['ext2', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Append }] + ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined }] ]) }], ['ext3', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a3', type: EnvironmentVariableMutatorType.Prepend }] + ['A', { value: 'a3', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }] ]) }], ['ext4', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a4', type: EnvironmentVariableMutatorType.Append }] + ['A', { value: 'a4', type: EnvironmentVariableMutatorType.Append, scope: undefined }] ]) }] ])); @@ -48,22 +48,22 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend }] + ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }] ]) }], ['ext2', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Append }] + ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined }] ]) }], ['ext3', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a3', type: EnvironmentVariableMutatorType.Replace }] + ['A', { value: 'a3', type: EnvironmentVariableMutatorType.Replace, scope: undefined }] ]) }], ['ext4', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a4', type: EnvironmentVariableMutatorType.Append }] + ['A', { value: 'a4', type: EnvironmentVariableMutatorType.Append, scope: undefined }] ]) }] ])); @@ -82,9 +82,9 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged = new MergedEnvironmentVariableCollection(new Map([ ['ext', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace }], - ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append }], - ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend }] + ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }], + ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined }], + ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }] ]) }] ])); @@ -105,9 +105,9 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged = new MergedEnvironmentVariableCollection(new Map([ ['ext', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace }], - ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append }], - ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend }] + ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }], + ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined }], + ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }] ]) }] ])); @@ -124,9 +124,9 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged = new MergedEnvironmentVariableCollection(new Map([ ['ext', { map: deserializeEnvironmentVariableCollection([ - ['a', { value: 'a', type: EnvironmentVariableMutatorType.Replace }], - ['b', { value: 'b', type: EnvironmentVariableMutatorType.Append }], - ['c', { value: 'c', type: EnvironmentVariableMutatorType.Prepend }] + ['a', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }], + ['b', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined }], + ['c', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }] ]) }] ])); @@ -160,14 +160,14 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged1 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace }] + ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }] ]) }] ])); const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace }] + ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }] ]) }] ])); @@ -179,7 +179,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace }] + ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }] ]) }] ])); @@ -188,7 +188,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { strictEqual(diff.removed.size, 0); const entries = [...diff.added.entries()]; deepStrictEqual(entries, [ - ['A', [{ extensionIdentifier: 'ext1', value: 'a', type: EnvironmentVariableMutatorType.Replace }]] + ['A', [{ extensionIdentifier: 'ext1', value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }]] ]); }); @@ -196,15 +196,15 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged1 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace }] + ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }] ]) }] ])); const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace }], - ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append }] + ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }], + ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined }] ]) }] ])); @@ -213,7 +213,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { strictEqual(diff.removed.size, 0); const entries = [...diff.added.entries()]; deepStrictEqual(entries, [ - ['B', [{ extensionIdentifier: 'ext1', value: 'b', type: EnvironmentVariableMutatorType.Append }]] + ['B', [{ extensionIdentifier: 'ext1', value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined }]] ]); }); @@ -221,7 +221,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged1 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend }] + ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }] ]) }] ])); @@ -229,12 +229,12 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext2', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Append }] + ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined }] ]) }], ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend }] + ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }] ]) }] ])); @@ -242,19 +242,19 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { strictEqual(diff.changed.size, 0); strictEqual(diff.removed.size, 0); deepStrictEqual([...diff.added.entries()], [ - ['A', [{ extensionIdentifier: 'ext2', value: 'a2', type: EnvironmentVariableMutatorType.Append }]] + ['A', [{ extensionIdentifier: 'ext2', value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined }]] ]); const merged3 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend }] + ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }] ]) }], // This entry should get removed ['ext2', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Append }] + ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined }] ]) }] ])); @@ -268,20 +268,20 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged1 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Replace }] + ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, scope: undefined }] ]) }] ])); const merged4 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Replace }] + ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, scope: undefined }] ]) }], // This entry should get removed as it comes after a replace ['ext2', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Append }] + ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined }] ]) }] ])); @@ -293,15 +293,15 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged1 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace }], - ['B', { value: 'b', type: EnvironmentVariableMutatorType.Replace }] + ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }], + ['B', { value: 'b', type: EnvironmentVariableMutatorType.Replace, scope: undefined }] ]) }] ])); const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace }] + ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }] ]) }] ])); @@ -309,7 +309,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { strictEqual(diff.changed.size, 0); strictEqual(diff.added.size, 0); deepStrictEqual([...diff.removed.entries()], [ - ['B', [{ extensionIdentifier: 'ext1', value: 'b', type: EnvironmentVariableMutatorType.Replace }]] + ['B', [{ extensionIdentifier: 'ext1', value: 'b', type: EnvironmentVariableMutatorType.Replace, scope: undefined }]] ]); }); @@ -317,16 +317,16 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged1 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Replace }], - ['B', { value: 'b', type: EnvironmentVariableMutatorType.Replace }] + ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, scope: undefined }], + ['B', { value: 'b', type: EnvironmentVariableMutatorType.Replace, scope: undefined }] ]) }] ])); const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Replace }], - ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append }] + ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: undefined }], + ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined }] ]) }] ])); @@ -334,8 +334,8 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { strictEqual(diff.added.size, 0); strictEqual(diff.removed.size, 0); deepStrictEqual([...diff.changed.entries()], [ - ['A', [{ extensionIdentifier: 'ext1', value: 'a2', type: EnvironmentVariableMutatorType.Replace }]], - ['B', [{ extensionIdentifier: 'ext1', value: 'b', type: EnvironmentVariableMutatorType.Append }]] + ['A', [{ extensionIdentifier: 'ext1', value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: undefined }]], + ['B', [{ extensionIdentifier: 'ext1', value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined }]] ]); }); @@ -343,28 +343,28 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged1 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Replace }], - ['B', { value: 'b', type: EnvironmentVariableMutatorType.Prepend }] + ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, scope: undefined }], + ['B', { value: 'b', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }] ]) }] ])); const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Replace }], - ['C', { value: 'c', type: EnvironmentVariableMutatorType.Append }] + ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: undefined }], + ['C', { value: 'c', type: EnvironmentVariableMutatorType.Append, scope: undefined }] ]) }] ])); const diff = merged1.diff(merged2)!; deepStrictEqual([...diff.added.entries()], [ - ['C', [{ extensionIdentifier: 'ext1', value: 'c', type: EnvironmentVariableMutatorType.Append }]], + ['C', [{ extensionIdentifier: 'ext1', value: 'c', type: EnvironmentVariableMutatorType.Append, scope: undefined }]], ]); deepStrictEqual([...diff.removed.entries()], [ - ['B', [{ extensionIdentifier: 'ext1', value: 'b', type: EnvironmentVariableMutatorType.Prepend }]] + ['B', [{ extensionIdentifier: 'ext1', value: 'b', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }]] ]); deepStrictEqual([...diff.changed.entries()], [ - ['A', [{ extensionIdentifier: 'ext1', value: 'a2', type: EnvironmentVariableMutatorType.Replace }]] + ['A', [{ extensionIdentifier: 'ext1', value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: undefined }]] ]); }); }); diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts index e3ac05202f8..c5ff189c5c2 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts @@ -44,9 +44,9 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { test('should persist collections to the storage service and be able to restore from them', () => { const collection = new Map(); - collection.set('A', { value: 'a', type: EnvironmentVariableMutatorType.Replace }); - collection.set('B', { value: 'b', type: EnvironmentVariableMutatorType.Append }); - collection.set('C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend }); + collection.set('A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }); + collection.set('B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined }); + collection.set('C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }); environmentVariableService.set('ext1', { map: collection, persistent: true }); deepStrictEqual([...environmentVariableService.mergedCollection.map.entries()], [ ['A', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Replace, value: 'a' }]], @@ -69,12 +69,12 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { const collection1 = new Map(); const collection2 = new Map(); const collection3 = new Map(); - collection1.set('A', { value: 'a1', type: EnvironmentVariableMutatorType.Append }); - collection1.set('B', { value: 'b1', type: EnvironmentVariableMutatorType.Replace }); - collection2.set('A', { value: 'a2', type: EnvironmentVariableMutatorType.Replace }); - collection2.set('B', { value: 'b2', type: EnvironmentVariableMutatorType.Append }); - collection3.set('A', { value: 'a3', type: EnvironmentVariableMutatorType.Prepend }); - collection3.set('B', { value: 'b3', type: EnvironmentVariableMutatorType.Replace }); + collection1.set('A', { value: 'a1', type: EnvironmentVariableMutatorType.Append, scope: undefined }); + collection1.set('B', { value: 'b1', type: EnvironmentVariableMutatorType.Replace, scope: undefined }); + collection2.set('A', { value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: undefined }); + collection2.set('B', { value: 'b2', type: EnvironmentVariableMutatorType.Append, scope: undefined }); + collection3.set('A', { value: 'a3', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }); + collection3.set('B', { value: 'b3', type: EnvironmentVariableMutatorType.Replace, scope: undefined }); environmentVariableService.set('ext1', { map: collection1, persistent: true }); environmentVariableService.set('ext2', { map: collection2, persistent: true }); environmentVariableService.set('ext3', { map: collection3, persistent: true }); @@ -91,9 +91,9 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { const collection1 = new Map(); const collection2 = new Map(); const collection3 = new Map(); - collection1.set('A', { value: ':a1', type: EnvironmentVariableMutatorType.Append }); - collection2.set('A', { value: 'a2:', type: EnvironmentVariableMutatorType.Prepend }); - collection3.set('A', { value: 'a3', type: EnvironmentVariableMutatorType.Replace }); + collection1.set('A', { value: ':a1', type: EnvironmentVariableMutatorType.Append, scope: undefined }); + collection2.set('A', { value: 'a2:', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }); + collection3.set('A', { value: 'a3', type: EnvironmentVariableMutatorType.Replace, scope: undefined }); environmentVariableService.set('ext1', { map: collection1, persistent: true }); environmentVariableService.set('ext2', { map: collection2, persistent: true }); environmentVariableService.set('ext3', { map: collection3, persistent: true }); diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableShared.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableShared.test.ts index cb96b0b8bb6..59cef9da7d0 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableShared.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableShared.test.ts @@ -10,13 +10,13 @@ import { EnvironmentVariableMutatorType, IEnvironmentVariableMutator } from 'vs/ suite('EnvironmentVariable - deserializeEnvironmentVariableCollection', () => { test('should construct correctly with 3 arguments', () => { const c = deserializeEnvironmentVariableCollection([ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace }], - ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append }], - ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend }] + ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }], + ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined }], + ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }] ]); const keys = [...c.keys()]; deepStrictEqual(keys, ['A', 'B', 'C']); - deepStrictEqual(c.get('A'), { value: 'a', type: EnvironmentVariableMutatorType.Replace }); + deepStrictEqual(c.get('A'), { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }); deepStrictEqual(c.get('B'), { value: 'b', type: EnvironmentVariableMutatorType.Append }); deepStrictEqual(c.get('C'), { value: 'c', type: EnvironmentVariableMutatorType.Prepend }); }); @@ -26,11 +26,11 @@ suite('EnvironmentVariable - serializeEnvironmentVariableCollection', () => { test('should correctly serialize the object', () => { const collection = new Map(); deepStrictEqual(serializeEnvironmentVariableCollection(collection), []); - collection.set('A', { value: 'a', type: EnvironmentVariableMutatorType.Replace }); - collection.set('B', { value: 'b', type: EnvironmentVariableMutatorType.Append }); - collection.set('C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend }); + collection.set('A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }); + collection.set('B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined }); + collection.set('C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }); deepStrictEqual(serializeEnvironmentVariableCollection(collection), [ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace }], + ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }], ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append }], ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend }] ]); From c92e48e2687f299222e734c949fcc9025c0fb300 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Wed, 5 Apr 2023 21:33:39 +0000 Subject: [PATCH 03/68] If workspace scope does not match, do not apply collection --- .../terminal/common/environmentVariableCollection.ts | 12 +++++++++++- .../terminal/browser/terminalProcessManager.ts | 4 +++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/vs/platform/terminal/common/environmentVariableCollection.ts b/src/vs/platform/terminal/common/environmentVariableCollection.ts index 03a29c81fc7..5f59dced9fc 100644 --- a/src/vs/platform/terminal/common/environmentVariableCollection.ts +++ b/src/vs/platform/terminal/common/environmentVariableCollection.ts @@ -5,6 +5,7 @@ import { IProcessEnvironment, isWindows } from 'vs/base/common/platform'; import { EnvironmentVariableMutatorType, IEnvironmentVariableCollection, IExtensionOwnedEnvironmentVariableMutator, IMergedEnvironmentVariableCollection, IMergedEnvironmentVariableCollectionDiff } from 'vs/platform/terminal/common/environmentVariable'; +import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace'; type VariableResolver = (str: string) => Promise; @@ -18,7 +19,8 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa readonly map: Map = new Map(); constructor( - readonly collections: ReadonlyMap + readonly collections: ReadonlyMap, + readonly workspaceFolder?: IWorkspaceFolder ) { collections.forEach((collection, extensionIdentifier) => { const it = collection.map.entries(); @@ -26,6 +28,14 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa while (!next.done) { const variable = next.value[0]; let entry = this.map.get(variable); + if (this.workspaceFolder) { + // If the entry is scoped to a workspace folder, only apply it if the workspace + // folder matches. + if (entry && entry[0].scope?.workspaceFolder && entry[0].scope.workspaceFolder.uri.fsPath !== this.workspaceFolder.uri.fsPath) { + next = it.next(); + continue; + } + } if (!entry) { entry = []; this.map.set(variable, entry); diff --git a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts index 9cb4d00bd79..162548a372e 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts @@ -171,7 +171,9 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce } if (environmentVariableCollections) { - this._extEnvironmentVariableCollection = new MergedEnvironmentVariableCollection(environmentVariableCollections); + const activeWorkspaceRootUri = this._historyService.getLastActiveWorkspaceRoot(); + const lastActiveWorkspace = activeWorkspaceRootUri ? withNullAsUndefined(this._workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri)) : undefined; + this._extEnvironmentVariableCollection = new MergedEnvironmentVariableCollection(environmentVariableCollections, lastActiveWorkspace); this._register(this._environmentVariableService.onDidChangeCollections(newCollection => this._onEnvironmentVariableCollectionChange(newCollection))); this.environmentVariableInfo = this._instantiationService.createInstance(EnvironmentVariableInfoChangesActive, this._extEnvironmentVariableCollection); this._onEnvironmentVariableInfoChange.fire(this.environmentVariableInfo); From 6d93a72c5c10fad4ae285b792af8ffa2343bcb5a Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Thu, 6 Apr 2023 21:04:41 +0000 Subject: [PATCH 04/68] Pass workspace to addEnvMixinPathPrefix --- .../common/environmentVariableCollection.ts | 6 +++--- src/vs/platform/terminal/common/terminal.ts | 2 ++ .../terminal/node/terminalEnvironment.ts | 2 +- .../test/node/terminalEnvironment.test.ts | 6 +++--- .../browser/terminalProcessManager.ts | 19 ++++++++++--------- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/vs/platform/terminal/common/environmentVariableCollection.ts b/src/vs/platform/terminal/common/environmentVariableCollection.ts index 5f59dced9fc..f9d3d5c1b3e 100644 --- a/src/vs/platform/terminal/common/environmentVariableCollection.ts +++ b/src/vs/platform/terminal/common/environmentVariableCollection.ts @@ -20,7 +20,7 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa constructor( readonly collections: ReadonlyMap, - readonly workspaceFolder?: IWorkspaceFolder + private readonly owningWorkspace?: IWorkspaceFolder ) { collections.forEach((collection, extensionIdentifier) => { const it = collection.map.entries(); @@ -28,10 +28,10 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa while (!next.done) { const variable = next.value[0]; let entry = this.map.get(variable); - if (this.workspaceFolder) { + if (this.owningWorkspace) { // If the entry is scoped to a workspace folder, only apply it if the workspace // folder matches. - if (entry && entry[0].scope?.workspaceFolder && entry[0].scope.workspaceFolder.uri.fsPath !== this.workspaceFolder.uri.fsPath) { + if (entry && entry[0].scope?.workspaceFolder && entry[0].scope.workspaceFolder.uri.fsPath !== this.owningWorkspace.uri.fsPath) { next = it.next(); continue; } diff --git a/src/vs/platform/terminal/common/terminal.ts b/src/vs/platform/terminal/common/terminal.ts index 16c4d7dee9f..3b63a459209 100644 --- a/src/vs/platform/terminal/common/terminal.ts +++ b/src/vs/platform/terminal/common/terminal.ts @@ -12,6 +12,7 @@ import { IGetTerminalLayoutInfoArgs, IProcessDetails, ISetTerminalLayoutInfoArgs import { ThemeIcon } from 'vs/base/common/themables'; import { ISerializableEnvironmentVariableCollections } from 'vs/platform/terminal/common/environmentVariable'; import { RawContextKey } from 'vs/platform/contextkey/common/contextkey'; +import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace'; export const terminalTabFocusContextKey = new RawContextKey('terminalTabFocusMode', false, true); @@ -600,6 +601,7 @@ export interface ITerminalProcessOptions { }; windowsEnableConpty: boolean; environmentVariableCollections: ISerializableEnvironmentVariableCollections | undefined; + workspaceFolder: IWorkspaceFolder | undefined; } export interface ITerminalEnvironment { diff --git a/src/vs/platform/terminal/node/terminalEnvironment.ts b/src/vs/platform/terminal/node/terminalEnvironment.ts index 10278268668..a7d3c739b51 100644 --- a/src/vs/platform/terminal/node/terminalEnvironment.ts +++ b/src/vs/platform/terminal/node/terminalEnvironment.ts @@ -256,7 +256,7 @@ function addEnvMixinPathPrefix(options: ITerminalProcessOptions, envMixin: IProc if (isMacintosh && options.environmentVariableCollections) { // Deserialize and merge const deserialized = deserializeEnvironmentVariableCollections(options.environmentVariableCollections); - const merged = new MergedEnvironmentVariableCollection(deserialized); + const merged = new MergedEnvironmentVariableCollection(deserialized, options.workspaceFolder); // Get all prepend PATH entries const pathEntry = merged.map.get('PATH'); diff --git a/src/vs/platform/terminal/test/node/terminalEnvironment.test.ts b/src/vs/platform/terminal/test/node/terminalEnvironment.test.ts index 101a48aeed2..b25548fbfc1 100644 --- a/src/vs/platform/terminal/test/node/terminalEnvironment.test.ts +++ b/src/vs/platform/terminal/test/node/terminalEnvironment.test.ts @@ -11,9 +11,9 @@ import { IProductService } from 'vs/platform/product/common/productService'; import { ITerminalProcessOptions } from 'vs/platform/terminal/common/terminal'; import { getShellIntegrationInjection, getWindowsBuildNumber, IShellIntegrationConfigInjection } from 'vs/platform/terminal/node/terminalEnvironment'; -const enabledProcessOptions: ITerminalProcessOptions = { shellIntegration: { enabled: true, suggestEnabled: false }, windowsEnableConpty: true, environmentVariableCollections: undefined }; -const disabledProcessOptions: ITerminalProcessOptions = { shellIntegration: { enabled: false, suggestEnabled: false }, windowsEnableConpty: true, environmentVariableCollections: undefined }; -const winptyProcessOptions: ITerminalProcessOptions = { shellIntegration: { enabled: true, suggestEnabled: false }, windowsEnableConpty: false, environmentVariableCollections: undefined }; +const enabledProcessOptions: ITerminalProcessOptions = { shellIntegration: { enabled: true, suggestEnabled: false }, windowsEnableConpty: true, environmentVariableCollections: undefined, workspaceFolder: undefined }; +const disabledProcessOptions: ITerminalProcessOptions = { shellIntegration: { enabled: false, suggestEnabled: false }, windowsEnableConpty: true, environmentVariableCollections: undefined, workspaceFolder: undefined }; +const winptyProcessOptions: ITerminalProcessOptions = { shellIntegration: { enabled: true, suggestEnabled: false }, windowsEnableConpty: false, environmentVariableCollections: undefined, workspaceFolder: undefined }; const pwshExe = process.platform === 'win32' ? 'pwsh.exe' : 'pwsh'; const repoRoot = process.platform === 'win32' ? process.cwd()[0].toLowerCase() + process.cwd().substring(1) : process.cwd(); const logService = new NullLogService(); diff --git a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts index 162548a372e..a0bb1e28f51 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts @@ -22,7 +22,7 @@ import { NaiveCwdDetectionCapability } from 'vs/platform/terminal/common/capabil import { TerminalCapabilityStore } from 'vs/platform/terminal/common/capabilities/terminalCapabilityStore'; import { FlowControlConstants, IProcessDataEvent, IProcessProperty, IProcessPropertyMap, IProcessReadyEvent, IReconnectionProperties, IShellLaunchConfig, ITerminalChildProcess, ITerminalDimensions, ITerminalEnvironment, ITerminalLaunchError, ITerminalProcessOptions, ProcessPropertyType, TerminalSettingId } from 'vs/platform/terminal/common/terminal'; import { TerminalRecorder } from 'vs/platform/terminal/common/terminalRecorder'; -import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; +import { IWorkspaceContextService, IWorkspaceFolder } from 'vs/platform/workspace/common/workspace'; import { EnvironmentVariableInfoChangesActive, EnvironmentVariableInfoStale } from 'vs/workbench/contrib/terminal/browser/environmentVariableInfo'; import { ITerminalInstanceService } from 'vs/workbench/contrib/terminal/browser/terminal'; import { IEnvironmentVariableInfo, IEnvironmentVariableService } from 'vs/workbench/contrib/terminal/common/environmentVariable'; @@ -116,6 +116,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce readonly onProcessExit = this._onProcessExit.event; private readonly _onRestoreCommands = this._register(new Emitter()); readonly onRestoreCommands = this._onRestoreCommands.event; + private _lastActiveWorkspace: IWorkspaceFolder | undefined; get persistentProcessId(): number | undefined { return this._process?.id; } get shouldPersist(): boolean { return !!this.reconnectionProperties || (this._process ? this._process.shouldPersist : false); } @@ -169,11 +170,11 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce } else { this.remoteAuthority = this._workbenchEnvironmentService.remoteAuthority; } + const activeWorkspaceRootUri = this._historyService.getLastActiveWorkspaceRoot(); + this._lastActiveWorkspace = activeWorkspaceRootUri ? withNullAsUndefined(this._workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri)) : undefined; if (environmentVariableCollections) { - const activeWorkspaceRootUri = this._historyService.getLastActiveWorkspaceRoot(); - const lastActiveWorkspace = activeWorkspaceRootUri ? withNullAsUndefined(this._workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri)) : undefined; - this._extEnvironmentVariableCollection = new MergedEnvironmentVariableCollection(environmentVariableCollections, lastActiveWorkspace); + this._extEnvironmentVariableCollection = new MergedEnvironmentVariableCollection(environmentVariableCollections, this._lastActiveWorkspace); this._register(this._environmentVariableService.onDidChangeCollections(newCollection => this._onEnvironmentVariableCollectionChange(newCollection))); this.environmentVariableInfo = this._instantiationService.createInstance(EnvironmentVariableInfoChangesActive, this._extEnvironmentVariableCollection); this._onEnvironmentVariableInfoChange.fire(this.environmentVariableInfo); @@ -241,9 +242,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce this.backend = backend; // Create variable resolver - const activeWorkspaceRootUri = this._historyService.getLastActiveWorkspaceRoot(); - const lastActiveWorkspace = activeWorkspaceRootUri ? withNullAsUndefined(this._workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri)) : undefined; - const variableResolver = terminalEnvironment.createVariableResolver(lastActiveWorkspace, await this._terminalProfileResolverService.getEnvironment(this.remoteAuthority), this._configurationResolverService); + const variableResolver = terminalEnvironment.createVariableResolver(this._lastActiveWorkspace, await this._terminalProfileResolverService.getEnvironment(this.remoteAuthority), this._configurationResolverService); // resolvedUserHome is needed here as remote resolvers can launch local terminals before // they're connected to the remote. @@ -284,7 +283,8 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce suggestEnabled: this._configurationService.getValue(TerminalSettingId.ShellIntegrationSuggestEnabled), }, windowsEnableConpty: this._configHelper.config.windowsEnableConpty, - environmentVariableCollections: this._extEnvironmentVariableCollection?.collections ? serializeEnvironmentVariableCollections(this._extEnvironmentVariableCollection.collections) : undefined + environmentVariableCollections: this._extEnvironmentVariableCollection?.collections ? serializeEnvironmentVariableCollections(this._extEnvironmentVariableCollection.collections) : undefined, + workspaceFolder: this._lastActiveWorkspace, }; try { newProcess = await backend.createProcess( @@ -473,7 +473,8 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce suggestEnabled: this._configurationService.getValue(TerminalSettingId.ShellIntegrationSuggestEnabled), }, windowsEnableConpty: this._configHelper.config.windowsEnableConpty, - environmentVariableCollections: this._extEnvironmentVariableCollection ? serializeEnvironmentVariableCollections(this._extEnvironmentVariableCollection.collections) : undefined + environmentVariableCollections: this._extEnvironmentVariableCollection ? serializeEnvironmentVariableCollections(this._extEnvironmentVariableCollection.collections) : undefined, + workspaceFolder: this._lastActiveWorkspace, }; const shouldPersist = ((this._configurationService.getValue(TaskSettingId.Reconnection) && shellLaunchConfig.reconnectionProperties) || !shellLaunchConfig.isFeatureTerminal) && this._configHelper.config.enablePersistentSessions && !shellLaunchConfig.isTransient; return await backend.createProcess(shellLaunchConfig, initialCwd, cols, rows, this._configHelper.config.unicodeVersion, env, options, shouldPersist); From 69b6e83f8d4740ed1bd5cbf00ceed14dd700844a Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Thu, 6 Apr 2023 21:08:40 +0000 Subject: [PATCH 05/68] Pass it in other places --- src/vs/server/node/remoteTerminalChannel.ts | 4 ++-- .../terminal/common/environmentVariableService.ts | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/vs/server/node/remoteTerminalChannel.ts b/src/vs/server/node/remoteTerminalChannel.ts index 753ca363fff..8038185bee4 100644 --- a/src/vs/server/node/remoteTerminalChannel.ts +++ b/src/vs/server/node/remoteTerminalChannel.ts @@ -236,7 +236,7 @@ export class RemoteTerminalChannel extends Disposable implements IServerChannel< entries.push([k, { map: deserializeEnvironmentVariableCollection(v) }]); } const envVariableCollections = new Map(entries); - const mergedCollection = new MergedEnvironmentVariableCollection(envVariableCollections); + const mergedCollection = new MergedEnvironmentVariableCollection(envVariableCollections, activeWorkspaceFolder); await mergedCollection.applyToProcessEnvironment(env, variableResolver); } @@ -247,7 +247,7 @@ export class RemoteTerminalChannel extends Disposable implements IServerChannel< const ipcHandlePath = createRandomIPCHandle(); env.VSCODE_IPC_HOOK_CLI = ipcHandlePath; - const persistentProcessId = await this._ptyService.createProcess(shellLaunchConfig, initialCwd, args.cols, args.rows, args.unicodeVersion, env, baseEnv, args.options, args.shouldPersistTerminal, args.workspaceId, args.workspaceName); + const persistentProcessId = await this._ptyService.createProcess(shellLaunchConfig, initialCwd, args.cols, args.rows, args.unicodeVersion, env, baseEnv, args.options, args.shouldPersistTerminal, args.workspaceId, args.workspaceName, activeWorkspaceFolder); const commandsExecuter: ICommandsExecuter = { executeCommand: (id: string, ...args: any[]): Promise => this._executeCommand(persistentProcessId, id, args, uriTransformer) }; diff --git a/src/vs/workbench/contrib/terminal/common/environmentVariableService.ts b/src/vs/workbench/contrib/terminal/common/environmentVariableService.ts index 9f68db1d984..675deceda4e 100644 --- a/src/vs/workbench/contrib/terminal/common/environmentVariableService.ts +++ b/src/vs/workbench/contrib/terminal/common/environmentVariableService.ts @@ -12,6 +12,9 @@ import { deserializeEnvironmentVariableCollection, serializeEnvironmentVariableC import { IEnvironmentVariableCollectionWithPersistence, IEnvironmentVariableService } from 'vs/workbench/contrib/terminal/common/environmentVariable'; import { TerminalStorageKeys } from 'vs/workbench/contrib/terminal/common/terminalStorageKeys'; import { IMergedEnvironmentVariableCollection, ISerializableEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; +import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; +import { IHistoryService } from 'vs/workbench/services/history/common/history'; +import { withNullAsUndefined } from 'vs/base/common/types'; interface ISerializableExtensionEnvironmentVariableCollection { extensionIdentifier: string; @@ -32,7 +35,9 @@ export class EnvironmentVariableService implements IEnvironmentVariableService { constructor( @IExtensionService private readonly _extensionService: IExtensionService, - @IStorageService private readonly _storageService: IStorageService + @IStorageService private readonly _storageService: IStorageService, + @IWorkspaceContextService private readonly _workspaceContextService: IWorkspaceContextService, + @IHistoryService private readonly _historyService: IHistoryService, ) { const serializedPersistedCollections = this._storageService.get(TerminalStorageKeys.EnvironmentVariableCollections, StorageScope.WORKSPACE); if (serializedPersistedCollections) { @@ -98,7 +103,9 @@ export class EnvironmentVariableService implements IEnvironmentVariableService { } private _resolveMergedCollection(): IMergedEnvironmentVariableCollection { - return new MergedEnvironmentVariableCollection(this.collections); + const activeWorkspaceRootUri = this._historyService.getLastActiveWorkspaceRoot(); + const lastActiveWorkspace = activeWorkspaceRootUri ? withNullAsUndefined(this._workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri)) : undefined; + return new MergedEnvironmentVariableCollection(this.collections, lastActiveWorkspace); } private async _invalidateExtensionCollections(): Promise { From aa8c15314932aa30ab605d7dc507053b5365d8d5 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Thu, 6 Apr 2023 21:11:39 +0000 Subject: [PATCH 06/68] Fix compile errors --- .../common/environmentVariableCollection.ts | 2 +- src/vs/server/node/remoteTerminalChannel.ts | 2 +- .../environmentVariableCollection.test.ts | 44 +++++++++---------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/vs/platform/terminal/common/environmentVariableCollection.ts b/src/vs/platform/terminal/common/environmentVariableCollection.ts index f9d3d5c1b3e..306aa14d962 100644 --- a/src/vs/platform/terminal/common/environmentVariableCollection.ts +++ b/src/vs/platform/terminal/common/environmentVariableCollection.ts @@ -20,7 +20,7 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa constructor( readonly collections: ReadonlyMap, - private readonly owningWorkspace?: IWorkspaceFolder + private readonly owningWorkspace: IWorkspaceFolder | undefined ) { collections.forEach((collection, extensionIdentifier) => { const it = collection.map.entries(); diff --git a/src/vs/server/node/remoteTerminalChannel.ts b/src/vs/server/node/remoteTerminalChannel.ts index 8038185bee4..e8386d82f98 100644 --- a/src/vs/server/node/remoteTerminalChannel.ts +++ b/src/vs/server/node/remoteTerminalChannel.ts @@ -247,7 +247,7 @@ export class RemoteTerminalChannel extends Disposable implements IServerChannel< const ipcHandlePath = createRandomIPCHandle(); env.VSCODE_IPC_HOOK_CLI = ipcHandlePath; - const persistentProcessId = await this._ptyService.createProcess(shellLaunchConfig, initialCwd, args.cols, args.rows, args.unicodeVersion, env, baseEnv, args.options, args.shouldPersistTerminal, args.workspaceId, args.workspaceName, activeWorkspaceFolder); + const persistentProcessId = await this._ptyService.createProcess(shellLaunchConfig, initialCwd, args.cols, args.rows, args.unicodeVersion, env, baseEnv, args.options, args.shouldPersistTerminal, args.workspaceId, args.workspaceName); const commandsExecuter: ICommandsExecuter = { executeCommand: (id: string, ...args: any[]): Promise => this._executeCommand(persistentProcessId, id, args, uriTransformer) }; diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts index 7c869e10281..1d8d816f37f 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts @@ -33,7 +33,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['A', { value: 'a4', type: EnvironmentVariableMutatorType.Append, scope: undefined }] ]) }] - ])); + ]), undefined); deepStrictEqual([...merged.map.entries()], [ ['A', [ { extensionIdentifier: 'ext4', type: EnvironmentVariableMutatorType.Append, value: 'a4' }, @@ -66,7 +66,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['A', { value: 'a4', type: EnvironmentVariableMutatorType.Append, scope: undefined }] ]) }] - ])); + ]), undefined); deepStrictEqual([...merged.map.entries()], [ ['A', [ { extensionIdentifier: 'ext3', type: EnvironmentVariableMutatorType.Replace, value: 'a3' }, @@ -87,7 +87,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }] ]) }] - ])); + ]), undefined); const env: IProcessEnvironment = { A: 'foo', B: 'bar', @@ -110,7 +110,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }] ]) }] - ])); + ]), undefined); const env: IProcessEnvironment = {}; await merged.applyToProcessEnvironment(env); deepStrictEqual(env, { @@ -129,7 +129,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['c', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }] ]) }] - ])); + ]), undefined); const env: IProcessEnvironment = { A: 'A', B: 'B', @@ -163,26 +163,26 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }] ]) }] - ])); + ]), undefined); const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }] ]) }] - ])); + ]), undefined); const diff = merged1.diff(merged2); strictEqual(diff, undefined); }); test('should generate added diffs from when the first entry is added', () => { - const merged1 = new MergedEnvironmentVariableCollection(new Map([])); + const merged1 = new MergedEnvironmentVariableCollection(new Map([]), undefined); const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }] ]) }] - ])); + ]), undefined); const diff = merged1.diff(merged2)!; strictEqual(diff.changed.size, 0); strictEqual(diff.removed.size, 0); @@ -199,7 +199,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }] ]) }] - ])); + ]), undefined); const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ @@ -207,7 +207,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined }] ]) }] - ])); + ]), undefined); const diff = merged1.diff(merged2)!; strictEqual(diff.changed.size, 0); strictEqual(diff.removed.size, 0); @@ -224,7 +224,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }] ]) }] - ])); + ]), undefined); const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext2', { @@ -237,7 +237,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }] ]) }] - ])); + ]), undefined); const diff = merged1.diff(merged2)!; strictEqual(diff.changed.size, 0); strictEqual(diff.removed.size, 0); @@ -257,7 +257,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined }] ]) }] - ])); + ]), undefined); const diff2 = merged1.diff(merged3)!; strictEqual(diff2.changed.size, 0); strictEqual(diff2.removed.size, 0); @@ -271,7 +271,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, scope: undefined }] ]) }] - ])); + ]), undefined); const merged4 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ @@ -284,7 +284,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined }] ]) }] - ])); + ]), undefined); const diff = merged1.diff(merged4); strictEqual(diff, undefined, 'Replace should ignore any entries after it'); }); @@ -297,14 +297,14 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['B', { value: 'b', type: EnvironmentVariableMutatorType.Replace, scope: undefined }] ]) }] - ])); + ]), undefined); const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }] ]) }] - ])); + ]), undefined); const diff = merged1.diff(merged2)!; strictEqual(diff.changed.size, 0); strictEqual(diff.added.size, 0); @@ -321,7 +321,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['B', { value: 'b', type: EnvironmentVariableMutatorType.Replace, scope: undefined }] ]) }] - ])); + ]), undefined); const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ @@ -329,7 +329,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined }] ]) }] - ])); + ]), undefined); const diff = merged1.diff(merged2)!; strictEqual(diff.added.size, 0); strictEqual(diff.removed.size, 0); @@ -347,7 +347,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['B', { value: 'b', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }] ]) }] - ])); + ]), undefined); const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ @@ -355,7 +355,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['C', { value: 'c', type: EnvironmentVariableMutatorType.Append, scope: undefined }] ]) }] - ])); + ]), undefined); const diff = merged1.diff(merged2)!; deepStrictEqual([...diff.added.entries()], [ ['C', [{ extensionIdentifier: 'ext1', value: 'c', type: EnvironmentVariableMutatorType.Append, scope: undefined }]], From b02d273338c83a79cd3e283021025126c5546813 Mon Sep 17 00:00:00 2001 From: First Date: Tue, 11 Apr 2023 15:12:03 -0700 Subject: [PATCH 07/68] Do basic key change --- .../api/common/extHostTerminalService.ts | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index 91e4e689e49..eadaa9f6a26 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -17,7 +17,7 @@ import { NotSupportedError } from 'vs/base/common/errors'; import { serializeEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableShared'; import { CancellationTokenSource } from 'vs/base/common/cancellation'; import { generateUuid } from 'vs/base/common/uuid'; -import { ISerializableEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; +import { IEnvironmentVariableMutator, ISerializableEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; import { ICreateContributedTerminalProfileOptions, IProcessReadyEvent, IShellLaunchConfigDto, ITerminalChildProcess, ITerminalLaunchError, ITerminalProfile, TerminalIcon, TerminalLocation, IProcessProperty, ProcessPropertyType, IProcessPropertyMap } from 'vs/platform/terminal/common/terminal'; import { TerminalDataBufferer } from 'vs/platform/terminal/common/terminalDataBuffering'; import { ThemeColor } from 'vs/base/common/themables'; @@ -867,7 +867,7 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I } class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollection { - readonly map: Map = new Map(); + readonly map: Map = new Map(); private _persistent: boolean = true; public get persistent(): boolean { return this._persistent; } @@ -902,15 +902,23 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect } private _setIfDiffers(variable: string, mutator: vscode.EnvironmentVariableMutator): void { - const current = this.map.get(variable); + const key = this.getKey(variable, mutator.scope); + const current = this.map.get(key); if (!current || current.value !== mutator.value || current.type !== mutator.type) { - this.map.set(variable, mutator); + const key = this.getKey(variable, mutator.scope); + this.map.set(key, mutator); this._onDidChangeCollection.fire(); } } - get(variable: string): vscode.EnvironmentVariableMutator | undefined { - return this.map.get(variable); + get(variable: string, scope?: vscode.EnvironmentVariableScope): vscode.EnvironmentVariableMutator | undefined { + const key = this.getKey(variable, scope); + return this.map.get(key); + } + + private getKey(variable: string, scope: vscode.EnvironmentVariableScope | undefined) { + // TODO: Create key using workspace + return variable; } forEach(callback: (variable: string, mutator: vscode.EnvironmentVariableMutator, collection: vscode.EnvironmentVariableCollection) => any, thisArg?: any): void { @@ -921,8 +929,9 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect return this.map.entries(); } - delete(variable: string): void { - this.map.delete(variable); + delete(variable: string, scope?: vscode.EnvironmentVariableScope): void { + const key = this.getKey(variable, scope); + this.map.delete(key); this._onDidChangeCollection.fire(); } From 422a0f34539df0855ff845bd1acc8fd2614549ae Mon Sep 17 00:00:00 2001 From: First Date: Tue, 11 Apr 2023 15:16:28 -0700 Subject: [PATCH 08/68] Add it to IMutator --- src/vs/platform/terminal/common/environmentVariable.ts | 1 + .../terminal/common/environmentVariableCollection.ts | 3 ++- src/vs/workbench/api/common/extHostTerminalService.ts | 5 +++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/vs/platform/terminal/common/environmentVariable.ts b/src/vs/platform/terminal/common/environmentVariable.ts index 35ead1e3f40..8d1c7c0aad5 100644 --- a/src/vs/platform/terminal/common/environmentVariable.ts +++ b/src/vs/platform/terminal/common/environmentVariable.ts @@ -17,6 +17,7 @@ export enum EnvironmentVariableMutatorType { // // TODO: Do we need a both? // } export interface IEnvironmentVariableMutator { + readonly variable: string; readonly value: string; readonly type: EnvironmentVariableMutatorType; readonly scope: EnvironmentVariableScope | undefined; diff --git a/src/vs/platform/terminal/common/environmentVariableCollection.ts b/src/vs/platform/terminal/common/environmentVariableCollection.ts index 306aa14d962..ec3fb4f44f3 100644 --- a/src/vs/platform/terminal/common/environmentVariableCollection.ts +++ b/src/vs/platform/terminal/common/environmentVariableCollection.ts @@ -54,7 +54,8 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa extensionIdentifier, value: mutator.value, type: mutator.type, - scope: mutator.scope + scope: mutator.scope, + variable: mutator.variable }); next = it.next(); diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index eadaa9f6a26..c2d8ce15f83 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -906,7 +906,8 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect const current = this.map.get(key); if (!current || current.value !== mutator.value || current.type !== mutator.type) { const key = this.getKey(variable, mutator.scope); - this.map.set(key, mutator); + const value: IEnvironmentVariableMutator = { variable, ...mutator }; + this.map.set(key, value); this._onDidChangeCollection.fire(); } } @@ -922,7 +923,7 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect } 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.map.forEach((value, key) => callback.call(thisArg, value.variable, value, this)); } [Symbol.iterator](): IterableIterator<[variable: string, mutator: vscode.EnvironmentVariableMutator]> { From 1ada81653488fbb929fbb08d0687fce5bbe5adc9 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Tue, 11 Apr 2023 23:09:10 +0000 Subject: [PATCH 09/68] yo --- 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 c2d8ce15f83..ff1d0c2d8db 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -926,7 +926,7 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect this.map.forEach((value, key) => callback.call(thisArg, value.variable, value, this)); } - [Symbol.iterator](): IterableIterator<[variable: string, mutator: vscode.EnvironmentVariableMutator]> { + [Symbol.iterator](): IterableIterator<[key: string, mutator: IEnvironmentVariableMutator]> { return this.map.entries(); } From 7a91afcaafb50addfc707abcd4e15a32feda056f Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Tue, 11 Apr 2023 23:18:05 +0000 Subject: [PATCH 10/68] Rename map to variableMap to distinguish it from collection map --- .../terminal/common/environmentVariable.ts | 2 +- .../common/environmentVariableCollection.ts | 24 +++++++++++-------- .../terminal/node/terminalEnvironment.ts | 2 +- .../api/common/extHostTerminalService.ts | 2 +- .../browser/environmentVariableInfo.ts | 2 +- .../browser/terminalProcessManager.ts | 2 +- .../environmentVariableCollection.test.ts | 4 ++-- .../common/environmentVariableService.test.ts | 8 +++---- 8 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/vs/platform/terminal/common/environmentVariable.ts b/src/vs/platform/terminal/common/environmentVariable.ts index 8d1c7c0aad5..1d3b8319fbf 100644 --- a/src/vs/platform/terminal/common/environmentVariable.ts +++ b/src/vs/platform/terminal/common/environmentVariable.ts @@ -56,7 +56,7 @@ type VariableResolver = (str: string) => Promise; */ export interface IMergedEnvironmentVariableCollection { readonly collections: ReadonlyMap; - readonly map: ReadonlyMap; + readonly variableMap: ReadonlyMap; /** * Applies this collection to a process environment. diff --git a/src/vs/platform/terminal/common/environmentVariableCollection.ts b/src/vs/platform/terminal/common/environmentVariableCollection.ts index ec3fb4f44f3..34571133ae2 100644 --- a/src/vs/platform/terminal/common/environmentVariableCollection.ts +++ b/src/vs/platform/terminal/common/environmentVariableCollection.ts @@ -16,7 +16,11 @@ type VariableResolver = (str: string) => Promise; // ]); export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVariableCollection { - readonly map: Map = new Map(); + /** + * Using variable as keys is okay here because each terminal instance has its own set of variables. + * @karrtikr TODO: Rename it back to map. + */ + readonly variableMap: Map = new Map(); constructor( readonly collections: ReadonlyMap, @@ -27,7 +31,7 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa let next = it.next(); while (!next.done) { const variable = next.value[0]; - let entry = this.map.get(variable); + let entry = this.variableMap.get(variable); if (this.owningWorkspace) { // If the entry is scoped to a workspace folder, only apply it if the workspace // folder matches. @@ -38,7 +42,7 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa } if (!entry) { entry = []; - this.map.set(variable, entry); + this.variableMap.set(variable, entry); } // If the first item in the entry is replace ignore any other entries as they would @@ -69,7 +73,7 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa lowerToActualVariableNames = {}; Object.keys(env).forEach(e => lowerToActualVariableNames![e.toLowerCase()] = e); } - for (const [variable, mutators] of this.map) { + for (const [variable, mutators] of this.variableMap) { const actualVariable = isWindows ? lowerToActualVariableNames![variable.toLowerCase()] || variable : variable; for (const mutator of mutators) { const value = variableResolver ? await variableResolver(mutator.value) : mutator.value; @@ -99,8 +103,8 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa const removed: Map = new Map(); // Find added - other.map.forEach((otherMutators, variable) => { - const currentMutators = this.map.get(variable); + other.variableMap.forEach((otherMutators, variable) => { + const currentMutators = this.variableMap.get(variable); const result = getMissingMutatorsFromArray(otherMutators, currentMutators); if (result) { added.set(variable, result); @@ -108,8 +112,8 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa }); // Find removed - this.map.forEach((currentMutators, variable) => { - const otherMutators = other.map.get(variable); + this.variableMap.forEach((currentMutators, variable) => { + const otherMutators = other.variableMap.get(variable); const result = getMissingMutatorsFromArray(currentMutators, otherMutators); if (result) { removed.set(variable, result); @@ -117,8 +121,8 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa }); // Find changed - this.map.forEach((currentMutators, variable) => { - const otherMutators = other.map.get(variable); + this.variableMap.forEach((currentMutators, variable) => { + const otherMutators = other.variableMap.get(variable); const result = getChangedMutatorsFromArray(currentMutators, otherMutators); if (result) { changed.set(variable, result); diff --git a/src/vs/platform/terminal/node/terminalEnvironment.ts b/src/vs/platform/terminal/node/terminalEnvironment.ts index a7d3c739b51..fb642bd2c94 100644 --- a/src/vs/platform/terminal/node/terminalEnvironment.ts +++ b/src/vs/platform/terminal/node/terminalEnvironment.ts @@ -259,7 +259,7 @@ function addEnvMixinPathPrefix(options: ITerminalProcessOptions, envMixin: IProc const merged = new MergedEnvironmentVariableCollection(deserialized, options.workspaceFolder); // Get all prepend PATH entries - const pathEntry = merged.map.get('PATH'); + const pathEntry = merged.variableMap.get('PATH'); const prependToPath: string[] = []; if (pathEntry) { for (const mutator of pathEntry) { diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index ff1d0c2d8db..30cb50ff347 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -918,7 +918,7 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect } private getKey(variable: string, scope: vscode.EnvironmentVariableScope | undefined) { - // TODO: Create key using workspace + // @karrtikr TODO: Create key using workspace return variable; } diff --git a/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts b/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts index 6d3ae4e867f..240a0d4a32d 100644 --- a/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts +++ b/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts @@ -70,7 +70,7 @@ export class EnvironmentVariableInfoChangesActive implements IEnvironmentVariabl private _getInfo(): string { const extSet: Set = new Set(); - addExtensionIdentifiers(extSet, this._collection.map.values()); + addExtensionIdentifiers(extSet, this._collection.variableMap.values()); let message = localize('extensionEnvironmentContributionInfoActive', "The following extensions have contributed to this terminal's environment:"); message += '\n'; diff --git a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts index a0bb1e28f51..0223a98df21 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts @@ -434,7 +434,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce // condition, the chance is minimal plus the impact on the user is also not that great // if it happens - it's not worth adding plumbing to sync back the resolved collection. await this._extEnvironmentVariableCollection.applyToProcessEnvironment(env, variableResolver); - if (this._extEnvironmentVariableCollection.map.size > 0) { + if (this._extEnvironmentVariableCollection.variableMap.size > 0) { this.environmentVariableInfo = this._instantiationService.createInstance(EnvironmentVariableInfoChangesActive, this._extEnvironmentVariableCollection); this._onEnvironmentVariableInfoChange.fire(this.environmentVariableInfo); } diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts index 1d8d816f37f..cbb4c3d8e78 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts @@ -34,7 +34,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ]) }] ]), undefined); - deepStrictEqual([...merged.map.entries()], [ + deepStrictEqual([...merged.variableMap.entries()], [ ['A', [ { extensionIdentifier: 'ext4', type: EnvironmentVariableMutatorType.Append, value: 'a4' }, { extensionIdentifier: 'ext3', type: EnvironmentVariableMutatorType.Prepend, value: 'a3' }, @@ -67,7 +67,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ]) }] ]), undefined); - deepStrictEqual([...merged.map.entries()], [ + deepStrictEqual([...merged.variableMap.entries()], [ ['A', [ { extensionIdentifier: 'ext3', type: EnvironmentVariableMutatorType.Replace, value: 'a3' }, { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Append, value: 'a2' }, diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts index c5ff189c5c2..55c0c05c032 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts @@ -48,7 +48,7 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { collection.set('B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined }); collection.set('C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }); environmentVariableService.set('ext1', { map: collection, persistent: true }); - deepStrictEqual([...environmentVariableService.mergedCollection.map.entries()], [ + deepStrictEqual([...environmentVariableService.mergedCollection.variableMap.entries()], [ ['A', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Replace, value: 'a' }]], ['B', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Append, value: 'b' }]], ['C', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Prepend, value: 'c' }]] @@ -57,7 +57,7 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { // Persist with old service, create a new service with the same storage service to verify restore environmentVariableService.persistCollections(); const service2: TestEnvironmentVariableService = instantiationService.createInstance(TestEnvironmentVariableService); - deepStrictEqual([...service2.mergedCollection.map.entries()], [ + deepStrictEqual([...service2.mergedCollection.variableMap.entries()], [ ['A', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Replace, value: 'a' }]], ['B', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Append, value: 'b' }]], ['C', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Prepend, value: 'c' }]] @@ -78,7 +78,7 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { environmentVariableService.set('ext1', { map: collection1, persistent: true }); environmentVariableService.set('ext2', { map: collection2, persistent: true }); environmentVariableService.set('ext3', { map: collection3, persistent: true }); - deepStrictEqual([...environmentVariableService.mergedCollection.map.entries()], [ + deepStrictEqual([...environmentVariableService.mergedCollection.variableMap.entries()], [ ['A', [ { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Replace, value: 'a2' }, { extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Append, value: 'a1' } @@ -99,7 +99,7 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { environmentVariableService.set('ext3', { map: collection3, persistent: true }); // The entries should be ordered in the order they are applied - deepStrictEqual([...environmentVariableService.mergedCollection.map.entries()], [ + deepStrictEqual([...environmentVariableService.mergedCollection.variableMap.entries()], [ ['A', [ { extensionIdentifier: 'ext3', type: EnvironmentVariableMutatorType.Replace, value: 'a3' }, { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Prepend, value: 'a2:' }, From 251e624c389c661f4b6e3b6a69e25033f80e8f45 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Tue, 11 Apr 2023 23:37:44 +0000 Subject: [PATCH 11/68] Fix --- .../platform/terminal/common/environmentVariableCollection.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vs/platform/terminal/common/environmentVariableCollection.ts b/src/vs/platform/terminal/common/environmentVariableCollection.ts index 34571133ae2..e663f566a2e 100644 --- a/src/vs/platform/terminal/common/environmentVariableCollection.ts +++ b/src/vs/platform/terminal/common/environmentVariableCollection.ts @@ -30,7 +30,8 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa const it = collection.map.entries(); let next = it.next(); while (!next.done) { - const variable = next.value[0]; + const mutator = next.value[1]; + const variable = mutator.variable; let entry = this.variableMap.get(variable); if (this.owningWorkspace) { // If the entry is scoped to a workspace folder, only apply it if the workspace @@ -53,7 +54,6 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa } // Mutators get applied in the reverse order than they are created - const mutator = next.value[1]; entry.unshift({ extensionIdentifier, value: mutator.value, From 6500583bd21797abc88f9aa0aa7d6d999c59b492 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Tue, 11 Apr 2023 23:42:29 +0000 Subject: [PATCH 12/68] Fix env var collection tests" --- .../environmentVariableCollection.test.ts | 84 +++++++++---------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts index cbb4c3d8e78..2ebaa7ef6f2 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts @@ -15,22 +15,22 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }] + ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }] ]) }], ['ext2', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined }] + ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] ]) }], ['ext3', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a3', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }] + ['A', { value: 'a3', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }] ]) }], ['ext4', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a4', type: EnvironmentVariableMutatorType.Append, scope: undefined }] + ['A', { value: 'a4', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] ]) }] ]), undefined); @@ -48,22 +48,22 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }] + ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }] ]) }], ['ext2', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined }] + ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] ]) }], ['ext3', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a3', type: EnvironmentVariableMutatorType.Replace, scope: undefined }] + ['A', { value: 'a3', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] ]) }], ['ext4', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a4', type: EnvironmentVariableMutatorType.Append, scope: undefined }] + ['A', { value: 'a4', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] ]) }] ]), undefined); @@ -82,9 +82,9 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged = new MergedEnvironmentVariableCollection(new Map([ ['ext', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }], - ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined }], - ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }] + ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], + ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }], + ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'C' }] ]) }] ]), undefined); @@ -105,9 +105,9 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged = new MergedEnvironmentVariableCollection(new Map([ ['ext', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }], - ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined }], - ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }] + ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], + ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }], + ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'C' }] ]) }] ]), undefined); @@ -124,9 +124,9 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged = new MergedEnvironmentVariableCollection(new Map([ ['ext', { map: deserializeEnvironmentVariableCollection([ - ['a', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }], - ['b', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined }], - ['c', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }] + ['a', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'a' }], + ['b', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'b' }], + ['c', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'c' }] ]) }] ]), undefined); @@ -160,14 +160,14 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged1 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }] + ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] ]) }] ]), undefined); const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }] + ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] ]) }] ]), undefined); @@ -179,7 +179,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }] + ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] ]) }] ]), undefined); @@ -196,15 +196,15 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged1 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }] + ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] ]) }] ]), undefined); const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }], - ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined }] + ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], + ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }] ]) }] ]), undefined); @@ -221,7 +221,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged1 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }] + ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }] ]) }] ]), undefined); @@ -229,12 +229,12 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext2', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined }] + ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] ]) }], ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }] + ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }] ]) }] ]), undefined); @@ -248,13 +248,13 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged3 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }] + ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }] ]) }], // This entry should get removed ['ext2', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined }] + ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] ]) }] ]), undefined); @@ -268,20 +268,20 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged1 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, scope: undefined }] + ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] ]) }] ]), undefined); const merged4 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, scope: undefined }] + ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] ]) }], // This entry should get removed as it comes after a replace ['ext2', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined }] + ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] ]) }] ]), undefined); @@ -293,15 +293,15 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged1 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }], - ['B', { value: 'b', type: EnvironmentVariableMutatorType.Replace, scope: undefined }] + ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], + ['B', { value: 'b', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'B' }] ]) }] ]), undefined); const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }] + ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] ]) }] ]), undefined); @@ -317,16 +317,16 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged1 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, scope: undefined }], - ['B', { value: 'b', type: EnvironmentVariableMutatorType.Replace, scope: undefined }] + ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], + ['B', { value: 'b', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'B' }] ]) }] ]), undefined); const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: undefined }], - ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined }] + ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], + ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }] ]) }] ]), undefined); @@ -343,16 +343,16 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged1 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, scope: undefined }], - ['B', { value: 'b', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }] + ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], + ['B', { value: 'b', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'B' }] ]) }] ]), undefined); const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: undefined }], - ['C', { value: 'c', type: EnvironmentVariableMutatorType.Append, scope: undefined }] + ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], + ['C', { value: 'c', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'C' }] ]) }] ]), undefined); From 1f3fdad86960d3e930b5329389ad12d8f126ef4b Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Tue, 11 Apr 2023 23:43:42 +0000 Subject: [PATCH 13/68] Fix env var service tests --- .../common/environmentVariableService.test.ts | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts index 55c0c05c032..c8dc7768aeb 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts @@ -44,9 +44,9 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { test('should persist collections to the storage service and be able to restore from them', () => { const collection = new Map(); - collection.set('A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }); - collection.set('B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined }); - collection.set('C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }); + collection.set('A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }); + collection.set('B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }); + collection.set('C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'C' }); environmentVariableService.set('ext1', { map: collection, persistent: true }); deepStrictEqual([...environmentVariableService.mergedCollection.variableMap.entries()], [ ['A', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Replace, value: 'a' }]], @@ -69,12 +69,12 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { const collection1 = new Map(); const collection2 = new Map(); const collection3 = new Map(); - collection1.set('A', { value: 'a1', type: EnvironmentVariableMutatorType.Append, scope: undefined }); - collection1.set('B', { value: 'b1', type: EnvironmentVariableMutatorType.Replace, scope: undefined }); - collection2.set('A', { value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: undefined }); - collection2.set('B', { value: 'b2', type: EnvironmentVariableMutatorType.Append, scope: undefined }); - collection3.set('A', { value: 'a3', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }); - collection3.set('B', { value: 'b3', type: EnvironmentVariableMutatorType.Replace, scope: undefined }); + collection1.set('A', { value: 'a1', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }); + collection1.set('B', { value: 'b1', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'B' }); + collection2.set('A', { value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }); + collection2.set('B', { value: 'b2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }); + collection3.set('A', { value: 'a3', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }); + collection3.set('B', { value: 'b3', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'B' }); environmentVariableService.set('ext1', { map: collection1, persistent: true }); environmentVariableService.set('ext2', { map: collection2, persistent: true }); environmentVariableService.set('ext3', { map: collection3, persistent: true }); @@ -91,9 +91,9 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { const collection1 = new Map(); const collection2 = new Map(); const collection3 = new Map(); - collection1.set('A', { value: ':a1', type: EnvironmentVariableMutatorType.Append, scope: undefined }); - collection2.set('A', { value: 'a2:', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }); - collection3.set('A', { value: 'a3', type: EnvironmentVariableMutatorType.Replace, scope: undefined }); + collection1.set('A', { value: ':a1', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }); + collection2.set('A', { value: 'a2:', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }); + collection3.set('A', { value: 'a3', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }); environmentVariableService.set('ext1', { map: collection1, persistent: true }); environmentVariableService.set('ext2', { map: collection2, persistent: true }); environmentVariableService.set('ext3', { map: collection3, persistent: true }); From b95214ad3974fa5beda06339f2241246e4a9ba8e Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Wed, 12 Apr 2023 00:22:09 +0000 Subject: [PATCH 14/68] Fix env var shared tests --- .../test/common/environmentVariableShared.test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableShared.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableShared.test.ts index 59cef9da7d0..4482758a457 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableShared.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableShared.test.ts @@ -10,9 +10,9 @@ import { EnvironmentVariableMutatorType, IEnvironmentVariableMutator } from 'vs/ suite('EnvironmentVariable - deserializeEnvironmentVariableCollection', () => { test('should construct correctly with 3 arguments', () => { const c = deserializeEnvironmentVariableCollection([ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }], - ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined }], - ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }] + ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], + ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }], + ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'C' }] ]); const keys = [...c.keys()]; deepStrictEqual(keys, ['A', 'B', 'C']); @@ -26,9 +26,9 @@ suite('EnvironmentVariable - serializeEnvironmentVariableCollection', () => { test('should correctly serialize the object', () => { const collection = new Map(); deepStrictEqual(serializeEnvironmentVariableCollection(collection), []); - collection.set('A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }); - collection.set('B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined }); - collection.set('C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }); + collection.set('A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }); + collection.set('B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }); + collection.set('C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'C' }); deepStrictEqual(serializeEnvironmentVariableCollection(collection), [ ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }], ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append }], From 8c3884bed5e5a11662c7aee4aa652986d1123b84 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Wed, 12 Apr 2023 03:28:13 +0000 Subject: [PATCH 15/68] Fix terminal integration test --- .../src/singlefolder-tests/terminal.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/terminal.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/terminal.test.ts index b76e348e02e..33fa688c997 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/terminal.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/terminal.test.ts @@ -858,9 +858,9 @@ import { assertNoRpc, poll } from '../utils'; const entries: [string, EnvironmentVariableMutator][] = []; collection.forEach((v, m) => entries.push([v, m])); deepStrictEqual(entries, [ - ['A', { value: '~a2~', type: EnvironmentVariableMutatorType.Replace }], - ['B', { value: '~b2~', type: EnvironmentVariableMutatorType.Append }], - ['C', { value: '~c2~', type: EnvironmentVariableMutatorType.Prepend }] + ['A', { value: '~a2~', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], + ['B', { value: '~b2~', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }], + ['C', { value: '~c2~', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'C' }] ]); }); }); From ecfcc3039e62f22a106f4b4f7b2091e31d24b134 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Wed, 12 Apr 2023 17:17:34 +0000 Subject: [PATCH 16/68] Add scope for get and delete --- src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts b/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts index 27fd37d2b38..cdabc7764e5 100644 --- a/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts +++ b/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts @@ -17,6 +17,8 @@ declare module 'vscode' { 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; } export type EnvironmentVariableScope = { From 22631c1bdc9a91c33ac2cdbc27b7e2fd6856057f Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Wed, 12 Apr 2023 17:40:00 +0000 Subject: [PATCH 17/68] Do not return variable property --- .../src/singlefolder-tests/terminal.test.ts | 12 ++++++------ .../workbench/api/common/extHostTerminalService.ts | 11 +++++++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/terminal.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/terminal.test.ts index 33fa688c997..36c1e66c852 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/terminal.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/terminal.test.ts @@ -850,17 +850,17 @@ import { assertNoRpc, poll } from '../utils'; collection.prepend('C', '~c2~'); // Verify get - deepStrictEqual(collection.get('A'), { value: '~a2~', type: EnvironmentVariableMutatorType.Replace }); - deepStrictEqual(collection.get('B'), { value: '~b2~', type: EnvironmentVariableMutatorType.Append }); - deepStrictEqual(collection.get('C'), { value: '~c2~', type: EnvironmentVariableMutatorType.Prepend }); + deepStrictEqual(collection.get('A'), { value: '~a2~', type: EnvironmentVariableMutatorType.Replace, scope: undefined }); + deepStrictEqual(collection.get('B'), { value: '~b2~', type: EnvironmentVariableMutatorType.Append, scope: undefined }); + deepStrictEqual(collection.get('C'), { value: '~c2~', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }); // Verify forEach const entries: [string, EnvironmentVariableMutator][] = []; collection.forEach((v, m) => entries.push([v, m])); deepStrictEqual(entries, [ - ['A', { value: '~a2~', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], - ['B', { value: '~b2~', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }], - ['C', { value: '~c2~', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'C' }] + ['A', { value: '~a2~', type: EnvironmentVariableMutatorType.Replace, scope: undefined }], + ['B', { value: '~b2~', type: EnvironmentVariableMutatorType.Append, scope: undefined }], + ['C', { value: '~c2~', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }] ]); }); }); diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index 30cb50ff347..29df9c6953f 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -914,7 +914,8 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect get(variable: string, scope?: vscode.EnvironmentVariableScope): vscode.EnvironmentVariableMutator | undefined { const key = this.getKey(variable, scope); - return this.map.get(key); + const value = this.map.get(key); + return value ? convertMutator(value) : undefined; } private getKey(variable: string, scope: vscode.EnvironmentVariableScope | undefined) { @@ -923,7 +924,7 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect } forEach(callback: (variable: string, mutator: vscode.EnvironmentVariableMutator, collection: vscode.EnvironmentVariableCollection) => any, thisArg?: any): void { - this.map.forEach((value, key) => callback.call(thisArg, value.variable, value, this)); + this.map.forEach((value, key) => callback.call(thisArg, value.variable, convertMutator(value), this)); } [Symbol.iterator](): IterableIterator<[key: string, mutator: IEnvironmentVariableMutator]> { @@ -976,3 +977,9 @@ function asTerminalIcon(iconPath?: vscode.Uri | { light: vscode.Uri; dark: vscod function asTerminalColor(color?: vscode.ThemeColor): ThemeColor | undefined { return ThemeColor.isThemeColor(color) ? color as ThemeColor : undefined; } + +function convertMutator(mutator: IEnvironmentVariableMutator): vscode.EnvironmentVariableMutator { + const newMutator: vscode.EnvironmentVariableMutator = { ...mutator }; + delete (newMutator as any).variable; + return newMutator; +} From ba757244d42a30bb5d418d97a521e0f23037a856 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Wed, 12 Apr 2023 17:41:16 +0000 Subject: [PATCH 18/68] Do not use key --- 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 29df9c6953f..f70a827f1e4 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -924,7 +924,7 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect } forEach(callback: (variable: string, mutator: vscode.EnvironmentVariableMutator, collection: vscode.EnvironmentVariableCollection) => any, thisArg?: any): void { - this.map.forEach((value, key) => callback.call(thisArg, value.variable, convertMutator(value), this)); + this.map.forEach((value, _) => callback.call(thisArg, value.variable, convertMutator(value), this)); } [Symbol.iterator](): IterableIterator<[key: string, mutator: IEnvironmentVariableMutator]> { From 83f9805d5680043e9eee358a8bef766179586639 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Wed, 12 Apr 2023 17:53:25 +0000 Subject: [PATCH 19/68] Fix merge collection unit tests --- .../environmentVariableCollection.test.ts | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts index 2ebaa7ef6f2..5724424c375 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts @@ -36,10 +36,10 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ]), undefined); deepStrictEqual([...merged.variableMap.entries()], [ ['A', [ - { extensionIdentifier: 'ext4', type: EnvironmentVariableMutatorType.Append, value: 'a4' }, - { extensionIdentifier: 'ext3', type: EnvironmentVariableMutatorType.Prepend, value: 'a3' }, - { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Append, value: 'a2' }, - { extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Prepend, value: 'a1' } + { extensionIdentifier: 'ext4', type: EnvironmentVariableMutatorType.Append, value: 'a4', scope: undefined, variable: 'A' }, + { extensionIdentifier: 'ext3', type: EnvironmentVariableMutatorType.Prepend, value: 'a3', scope: undefined, variable: 'A' }, + { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Append, value: 'a2', scope: undefined, variable: 'A' }, + { extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Prepend, value: 'a1', scope: undefined, variable: 'A' } ]] ]); }); @@ -69,9 +69,9 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ]), undefined); deepStrictEqual([...merged.variableMap.entries()], [ ['A', [ - { extensionIdentifier: 'ext3', type: EnvironmentVariableMutatorType.Replace, value: 'a3' }, - { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Append, value: 'a2' }, - { extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Prepend, value: 'a1' } + { extensionIdentifier: 'ext3', type: EnvironmentVariableMutatorType.Replace, value: 'a3', scope: undefined, variable: 'A' }, + { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Append, value: 'a2', scope: undefined, variable: 'A' }, + { extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Prepend, value: 'a1', scope: undefined, variable: 'A' } ]] ], 'The ext4 entry should be removed as it comes after a Replace'); }); @@ -188,7 +188,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { strictEqual(diff.removed.size, 0); const entries = [...diff.added.entries()]; deepStrictEqual(entries, [ - ['A', [{ extensionIdentifier: 'ext1', value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }]] + ['A', [{ extensionIdentifier: 'ext1', value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }]] ]); }); @@ -213,7 +213,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { strictEqual(diff.removed.size, 0); const entries = [...diff.added.entries()]; deepStrictEqual(entries, [ - ['B', [{ extensionIdentifier: 'ext1', value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined }]] + ['B', [{ extensionIdentifier: 'ext1', value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }]] ]); }); @@ -242,7 +242,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { strictEqual(diff.changed.size, 0); strictEqual(diff.removed.size, 0); deepStrictEqual([...diff.added.entries()], [ - ['A', [{ extensionIdentifier: 'ext2', value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined }]] + ['A', [{ extensionIdentifier: 'ext2', value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }]] ]); const merged3 = new MergedEnvironmentVariableCollection(new Map([ @@ -309,7 +309,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { strictEqual(diff.changed.size, 0); strictEqual(diff.added.size, 0); deepStrictEqual([...diff.removed.entries()], [ - ['B', [{ extensionIdentifier: 'ext1', value: 'b', type: EnvironmentVariableMutatorType.Replace, scope: undefined }]] + ['B', [{ extensionIdentifier: 'ext1', value: 'b', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'B' }]] ]); }); @@ -334,8 +334,8 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { strictEqual(diff.added.size, 0); strictEqual(diff.removed.size, 0); deepStrictEqual([...diff.changed.entries()], [ - ['A', [{ extensionIdentifier: 'ext1', value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: undefined }]], - ['B', [{ extensionIdentifier: 'ext1', value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined }]] + ['A', [{ extensionIdentifier: 'ext1', value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }]], + ['B', [{ extensionIdentifier: 'ext1', value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }]] ]); }); @@ -358,13 +358,13 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ]), undefined); const diff = merged1.diff(merged2)!; deepStrictEqual([...diff.added.entries()], [ - ['C', [{ extensionIdentifier: 'ext1', value: 'c', type: EnvironmentVariableMutatorType.Append, scope: undefined }]], + ['C', [{ extensionIdentifier: 'ext1', value: 'c', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'C' }]], ]); deepStrictEqual([...diff.removed.entries()], [ - ['B', [{ extensionIdentifier: 'ext1', value: 'b', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }]] + ['B', [{ extensionIdentifier: 'ext1', value: 'b', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'B' }]] ]); deepStrictEqual([...diff.changed.entries()], [ - ['A', [{ extensionIdentifier: 'ext1', value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: undefined }]] + ['A', [{ extensionIdentifier: 'ext1', value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }]] ]); }); }); From 5a24e05407466a82cfee8ffe43743b14ca644336 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Wed, 12 Apr 2023 17:55:16 +0000 Subject: [PATCH 20/68] Fix env shared unit tests --- .../test/common/environmentVariableShared.test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableShared.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableShared.test.ts index 4482758a457..6ccf1005e6c 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableShared.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableShared.test.ts @@ -16,9 +16,9 @@ suite('EnvironmentVariable - deserializeEnvironmentVariableCollection', () => { ]); const keys = [...c.keys()]; deepStrictEqual(keys, ['A', 'B', 'C']); - deepStrictEqual(c.get('A'), { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }); - deepStrictEqual(c.get('B'), { value: 'b', type: EnvironmentVariableMutatorType.Append }); - deepStrictEqual(c.get('C'), { value: 'c', type: EnvironmentVariableMutatorType.Prepend }); + deepStrictEqual(c.get('A'), { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }); + deepStrictEqual(c.get('B'), { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }); + deepStrictEqual(c.get('C'), { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'C' }); }); }); @@ -30,9 +30,9 @@ suite('EnvironmentVariable - serializeEnvironmentVariableCollection', () => { collection.set('B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }); collection.set('C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'C' }); deepStrictEqual(serializeEnvironmentVariableCollection(collection), [ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined }], - ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append }], - ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend }] + ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], + ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }], + ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'C' }] ]); }); }); From c6e7611f4a688723a884321a60694b8c08179be7 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Wed, 12 Apr 2023 18:09:08 +0000 Subject: [PATCH 21/68] Try to fix env var tests --- .../common/environmentVariableService.test.ts | 6 ++++- .../test/common/workbenchTestServices.ts | 26 ++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts index c8dc7768aeb..03b26821f07 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { deepStrictEqual } from 'assert'; -import { TestExtensionService, TestStorageService } from 'vs/workbench/test/common/workbenchTestServices'; +import { TestExtensionService, TestHistoryService, TestStorageService } from 'vs/workbench/test/common/workbenchTestServices'; import { EnvironmentVariableService } from 'vs/workbench/contrib/terminal/common/environmentVariableService'; import { EnvironmentVariableMutatorType, IEnvironmentVariableMutator } from 'vs/platform/terminal/common/environmentVariable'; import { IStorageService } from 'vs/platform/storage/common/storage'; @@ -12,6 +12,7 @@ import { TestInstantiationService } from 'vs/platform/instantiation/test/common/ import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions'; import { Emitter } from 'vs/base/common/event'; import { IProcessEnvironment } from 'vs/base/common/platform'; +import { IHistoryService } from 'vs/workbench/services/history/common/history'; class TestEnvironmentVariableService extends EnvironmentVariableService { persistCollections(): void { this._persistCollections(); } @@ -22,6 +23,7 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { let instantiationService: TestInstantiationService; let environmentVariableService: TestEnvironmentVariableService; let storageService: TestStorageService; + let historyService: TestHistoryService; let changeExtensionsEvent: Emitter; setup(() => { @@ -30,6 +32,7 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { instantiationService = new TestInstantiationService(); instantiationService.stub(IExtensionService, TestExtensionService); storageService = new TestStorageService(); + historyService = new TestHistoryService(); instantiationService.stub(IStorageService, storageService); instantiationService.stub(IExtensionService, TestExtensionService); instantiationService.stub(IExtensionService, 'onDidChangeExtensions', changeExtensionsEvent.event); @@ -38,6 +41,7 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { { identifier: { value: 'ext2' } }, { identifier: { value: 'ext3' } } ]); + instantiationService.stub(IHistoryService, historyService); environmentVariableService = instantiationService.createInstance(TestEnvironmentVariableService); }); diff --git a/src/vs/workbench/test/common/workbenchTestServices.ts b/src/vs/workbench/test/common/workbenchTestServices.ts index e1398daa91d..d1e44f9fbce 100644 --- a/src/vs/workbench/test/common/workbenchTestServices.ts +++ b/src/vs/workbench/test/common/workbenchTestServices.ts @@ -18,12 +18,15 @@ import { NullExtensionService } from 'vs/workbench/services/extensions/common/ex import { IWorkingCopyFileService, IWorkingCopyFileOperationParticipant, WorkingCopyFileEvent, IDeleteOperation, ICopyOperation, IMoveOperation, IFileOperationUndoRedoInfo, ICreateFileOperation, ICreateOperation, IStoredFileWorkingCopySaveParticipant } from 'vs/workbench/services/workingCopy/common/workingCopyFileService'; import { IDisposable, Disposable } from 'vs/base/common/lifecycle'; import { IFileStatWithMetadata } from 'vs/platform/files/common/files'; -import { ISaveOptions, IRevertOptions, SaveReason } from 'vs/workbench/common/editor'; +import { ISaveOptions, IRevertOptions, SaveReason, GroupIdentifier } from 'vs/workbench/common/editor'; import { CancellationToken } from 'vs/base/common/cancellation'; import product from 'vs/platform/product/common/product'; import { IActivity, IActivityService } from 'vs/workbench/services/activity/common/activity'; import { IStoredFileWorkingCopySaveEvent } from 'vs/workbench/services/workingCopy/common/storedFileWorkingCopy'; import { AbstractLoggerService, ILogger, LogLevel, NullLogger } from 'vs/platform/log/common/log'; +import { IResourceEditorInput } from 'vs/platform/editor/common/editor'; +import { EditorInput } from 'vs/workbench/common/editor/editorInput'; +import { IHistoryService } from 'vs/workbench/services/history/common/history'; export class TestLoggerService extends AbstractLoggerService { constructor(logsHome?: URI) { @@ -140,6 +143,27 @@ export class TestStorageService extends InMemoryStorageService { } } +export class TestHistoryService implements IHistoryService { + + declare readonly _serviceBrand: undefined; + + constructor(private root?: URI) { } + + async reopenLastClosedEditor(): Promise { } + async goForward(): Promise { } + async goBack(): Promise { } + async goPrevious(): Promise { } + async goLast(): Promise { } + removeFromHistory(_input: EditorInput | IResourceEditorInput): void { } + clear(): void { } + clearRecentlyOpened(): void { } + getHistory(): readonly (EditorInput | IResourceEditorInput)[] { return []; } + async openNextRecentlyUsedEditor(group?: GroupIdentifier): Promise { } + async openPreviouslyUsedEditor(group?: GroupIdentifier): Promise { } + getLastActiveWorkspaceRoot(_schemeFilter: string): URI | undefined { return this.root; } + getLastActiveFile(_schemeFilter: string): URI | undefined { return undefined; } +} + export class TestWorkingCopy extends Disposable implements IWorkingCopy { private readonly _onDidChangeDirty = this._register(new Emitter()); From 145362108565f8aee67d07633d113fbcb7255096 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Wed, 12 Apr 2023 18:16:24 +0000 Subject: [PATCH 22/68] Fix more tests --- .../common/environmentVariableService.test.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts index 03b26821f07..a872b8b1832 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts @@ -53,9 +53,9 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { collection.set('C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'C' }); environmentVariableService.set('ext1', { map: collection, persistent: true }); deepStrictEqual([...environmentVariableService.mergedCollection.variableMap.entries()], [ - ['A', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Replace, value: 'a' }]], - ['B', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Append, value: 'b' }]], - ['C', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Prepend, value: 'c' }]] + ['A', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Replace, value: 'a', scope: undefined, variable: 'A' }]], + ['B', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Append, value: 'b', scope: undefined, variable: 'B' }]], + ['C', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Prepend, value: 'c', scope: undefined, variable: 'C' }]] ]); // Persist with old service, create a new service with the same storage service to verify restore @@ -84,10 +84,10 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { environmentVariableService.set('ext3', { map: collection3, persistent: true }); deepStrictEqual([...environmentVariableService.mergedCollection.variableMap.entries()], [ ['A', [ - { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Replace, value: 'a2' }, - { extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Append, value: 'a1' } + { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Replace, value: 'a2', scope: undefined, variable: 'A' }, + { extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Append, value: 'a1', scope: undefined, variable: 'A' } ]], - ['B', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Replace, value: 'b1' }]] + ['B', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Replace, value: 'b1', scope: undefined, variable: 'B' }]] ]); }); @@ -105,9 +105,9 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { // The entries should be ordered in the order they are applied deepStrictEqual([...environmentVariableService.mergedCollection.variableMap.entries()], [ ['A', [ - { extensionIdentifier: 'ext3', type: EnvironmentVariableMutatorType.Replace, value: 'a3' }, - { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Prepend, value: 'a2:' }, - { extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Append, value: ':a1' } + { extensionIdentifier: 'ext3', type: EnvironmentVariableMutatorType.Replace, value: 'a3', scope: undefined, variable: 'A' }, + { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Prepend, value: 'a2:', scope: undefined, variable: 'A' }, + { extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Append, value: ':a1', scope: undefined, variable: 'A' } ]] ]); From 53d6c18da81442d682c411ecd2c33edb9b67d7df Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Wed, 12 Apr 2023 19:10:39 +0000 Subject: [PATCH 23/68] Oops --- .../terminal/test/common/environmentVariableService.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts index a872b8b1832..1c465156126 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts @@ -62,9 +62,9 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { environmentVariableService.persistCollections(); const service2: TestEnvironmentVariableService = instantiationService.createInstance(TestEnvironmentVariableService); deepStrictEqual([...service2.mergedCollection.variableMap.entries()], [ - ['A', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Replace, value: 'a' }]], - ['B', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Append, value: 'b' }]], - ['C', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Prepend, value: 'c' }]] + ['A', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Replace, value: 'a', scope: undefined, variable: 'A' }]], + ['B', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Append, value: 'b', scope: undefined, variable: 'B' }]], + ['C', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Prepend, value: 'c', scope: undefined, variable: 'C' }]] ]); }); From f60a941432e52b70c260637bef5b5fb3719dfe91 Mon Sep 17 00:00:00 2001 From: First Date: Thu, 13 Apr 2023 17:46:21 -0700 Subject: [PATCH 24/68] More fixes --- .../platform/terminal/common/environmentVariable.ts | 1 + .../terminal/common/environmentVariableCollection.ts | 10 ++++++++-- .../workbench/api/common/extHostTerminalService.ts | 12 +++++++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/vs/platform/terminal/common/environmentVariable.ts b/src/vs/platform/terminal/common/environmentVariable.ts index 1d3b8319fbf..0e3c814ecb7 100644 --- a/src/vs/platform/terminal/common/environmentVariable.ts +++ b/src/vs/platform/terminal/common/environmentVariable.ts @@ -55,6 +55,7 @@ type VariableResolver = (str: string) => Promise; * together. */ export interface IMergedEnvironmentVariableCollection { + readonly owningWorkspace: IWorkspaceFolderData | undefined; readonly collections: ReadonlyMap; readonly variableMap: ReadonlyMap; diff --git a/src/vs/platform/terminal/common/environmentVariableCollection.ts b/src/vs/platform/terminal/common/environmentVariableCollection.ts index e663f566a2e..2cbd2823f9f 100644 --- a/src/vs/platform/terminal/common/environmentVariableCollection.ts +++ b/src/vs/platform/terminal/common/environmentVariableCollection.ts @@ -24,7 +24,10 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa constructor( readonly collections: ReadonlyMap, - private readonly owningWorkspace: IWorkspaceFolder | undefined + /** + * @karrtikr TODO: Change it back to private. + */ + public readonly owningWorkspace: IWorkspaceFolder | undefined ) { collections.forEach((collection, extensionIdentifier) => { const it = collection.map.entries(); @@ -36,7 +39,7 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa if (this.owningWorkspace) { // If the entry is scoped to a workspace folder, only apply it if the workspace // folder matches. - if (entry && entry[0].scope?.workspaceFolder && entry[0].scope.workspaceFolder.uri.fsPath !== this.owningWorkspace.uri.fsPath) { + if (mutator.scope?.workspaceFolder && mutator.scope.workspaceFolder.uri.fsPath !== this.owningWorkspace.uri.fsPath) { next = it.next(); continue; } @@ -65,6 +68,7 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa next = it.next(); } }); + const x = 'hey brother'; } async applyToProcessEnvironment(env: IProcessEnvironment, variableResolver?: VariableResolver): Promise { @@ -101,6 +105,8 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa const added: Map = new Map(); const changed: Map = new Map(); const removed: Map = new Map(); + const workspaceName = this.owningWorkspace?.name; + const x = 2; // Find added other.variableMap.forEach((otherMutators, variable) => { diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index f70a827f1e4..1236cdc8a3f 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -902,9 +902,12 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect } private _setIfDiffers(variable: string, mutator: vscode.EnvironmentVariableMutator): void { + if (variable === 'VIRTUAL_ENV') { + console.log('Set variable to mutator', JSON.stringify(mutator)); + } const key = this.getKey(variable, mutator.scope); const current = this.map.get(key); - if (!current || current.value !== mutator.value || current.type !== mutator.type) { + 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); @@ -919,8 +922,11 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect } private getKey(variable: string, scope: vscode.EnvironmentVariableScope | undefined) { - // @karrtikr TODO: Create key using workspace - return variable; + return variable.concat(this.getWorkspaceKey(scope?.workspaceFolder)); + } + + private getWorkspaceKey(workspaceFolder: vscode.WorkspaceFolder | undefined): string { + return workspaceFolder ? workspaceFolder.uri.toString() : ''; } forEach(callback: (variable: string, mutator: vscode.EnvironmentVariableMutator, collection: vscode.EnvironmentVariableCollection) => any, thisArg?: any): void { From 653cafb8387ab662a86ac89052c3c904f8f337f4 Mon Sep 17 00:00:00 2001 From: First Date: Thu, 13 Apr 2023 18:33:46 -0700 Subject: [PATCH 25/68] Few more fixes --- .../terminal/common/environmentVariableCollection.ts | 7 ++----- .../terminal.environmentChanges.contribution.ts | 10 ++++++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/vs/platform/terminal/common/environmentVariableCollection.ts b/src/vs/platform/terminal/common/environmentVariableCollection.ts index 2cbd2823f9f..d5c96193d58 100644 --- a/src/vs/platform/terminal/common/environmentVariableCollection.ts +++ b/src/vs/platform/terminal/common/environmentVariableCollection.ts @@ -37,7 +37,7 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa const variable = mutator.variable; let entry = this.variableMap.get(variable); if (this.owningWorkspace) { - // If the entry is scoped to a workspace folder, only apply it if the workspace + // If a mutator is scoped to a workspace folder, only apply it if the workspace // folder matches. if (mutator.scope?.workspaceFolder && mutator.scope.workspaceFolder.uri.fsPath !== this.owningWorkspace.uri.fsPath) { next = it.next(); @@ -68,7 +68,6 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa next = it.next(); } }); - const x = 'hey brother'; } async applyToProcessEnvironment(env: IProcessEnvironment, variableResolver?: VariableResolver): Promise { @@ -105,8 +104,6 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa const added: Map = new Map(); const changed: Map = new Map(); const removed: Map = new Map(); - const workspaceName = this.owningWorkspace?.name; - const x = 2; // Find added other.variableMap.forEach((otherMutators, variable) => { @@ -184,7 +181,7 @@ function getChangedMutatorsFromArray( const result: IExtensionOwnedEnvironmentVariableMutator[] = []; current.forEach(mutator => { const otherMutator = otherMutatorExtensions.get(mutator.extensionIdentifier); - if (otherMutator && (mutator.type !== otherMutator.type || mutator.value !== otherMutator.value)) { + if (otherMutator && (mutator.type !== otherMutator.type || mutator.value !== otherMutator.value || mutator.scope?.workspaceFolder?.index !== otherMutator.scope?.workspaceFolder?.index)) { // Return the new result, not the old one result.push(otherMutator); } diff --git a/src/vs/workbench/contrib/terminalContrib/environmentChanges/browser/terminal.environmentChanges.contribution.ts b/src/vs/workbench/contrib/terminalContrib/environmentChanges/browser/terminal.environmentChanges.contribution.ts index 89767e2bbdc..1bd219cd475 100644 --- a/src/vs/workbench/contrib/terminalContrib/environmentChanges/browser/terminal.environmentChanges.contribution.ts +++ b/src/vs/workbench/contrib/terminalContrib/environmentChanges/browser/terminal.environmentChanges.contribution.ts @@ -37,8 +37,14 @@ function describeEnvironmentChanges(collection: IMergedEnvironmentVariableCollec for (const [ext, coll] of collection.collections) { content += `\n\n## ${localize('extension', 'Extension: {0}', ext)}`; content += '\n'; - for (const [variable, mutator] of coll.map.entries()) { - content += `\n- \`${mutatorTypeLabel(mutator.type, mutator.value, variable)}\``; + for (const [_, mutator] of coll.map.entries()) { + if (collection.owningWorkspace) { + // Only mutators which are applicable on the relevant workspace should be shown. + if (mutator.scope?.workspaceFolder && mutator.scope.workspaceFolder.index !== collection.owningWorkspace.index) { + continue; + } + } + content += `\n- \`${mutatorTypeLabel(mutator.type, mutator.value, mutator.variable)}\``; } } return content; From 03de27d94cf04d18b427cbe3c9f9d4ed95384520 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Fri, 14 Apr 2023 07:18:58 +0000 Subject: [PATCH 26/68] Pass workspace folder via apply method instead --- .../terminal/common/environmentVariable.ts | 3 +- .../common/environmentVariableCollection.ts | 39 ++++++++++++------- src/vs/server/node/remoteTerminalChannel.ts | 8 +++- .../browser/terminalProcessManager.ts | 6 ++- .../common/environmentVariableService.ts | 9 +---- .../electron-sandbox/localTerminalBackend.ts | 4 +- 6 files changed, 39 insertions(+), 30 deletions(-) diff --git a/src/vs/platform/terminal/common/environmentVariable.ts b/src/vs/platform/terminal/common/environmentVariable.ts index 0e3c814ecb7..0471c6ff1ce 100644 --- a/src/vs/platform/terminal/common/environmentVariable.ts +++ b/src/vs/platform/terminal/common/environmentVariable.ts @@ -55,7 +55,6 @@ type VariableResolver = (str: string) => Promise; * together. */ export interface IMergedEnvironmentVariableCollection { - readonly owningWorkspace: IWorkspaceFolderData | undefined; readonly collections: ReadonlyMap; readonly variableMap: ReadonlyMap; @@ -64,7 +63,7 @@ export interface IMergedEnvironmentVariableCollection { * @param variableResolver An optional function to use to resolve variables within the * environment values. */ - applyToProcessEnvironment(env: IProcessEnvironment, variableResolver?: VariableResolver): Promise; + applyToProcessEnvironment(env: IProcessEnvironment, scope: EnvironmentVariableScope | undefined, variableResolver?: VariableResolver): Promise; /** * Generates a diff of this collection against another. Returns undefined if the collections are diff --git a/src/vs/platform/terminal/common/environmentVariableCollection.ts b/src/vs/platform/terminal/common/environmentVariableCollection.ts index d5c96193d58..26b73a178cb 100644 --- a/src/vs/platform/terminal/common/environmentVariableCollection.ts +++ b/src/vs/platform/terminal/common/environmentVariableCollection.ts @@ -4,8 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { IProcessEnvironment, isWindows } from 'vs/base/common/platform'; -import { EnvironmentVariableMutatorType, IEnvironmentVariableCollection, IExtensionOwnedEnvironmentVariableMutator, IMergedEnvironmentVariableCollection, IMergedEnvironmentVariableCollectionDiff } from 'vs/platform/terminal/common/environmentVariable'; -import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace'; +import { EnvironmentVariableMutatorType, EnvironmentVariableScope, IEnvironmentVariableCollection, IExtensionOwnedEnvironmentVariableMutator, IMergedEnvironmentVariableCollection, IMergedEnvironmentVariableCollectionDiff } from 'vs/platform/terminal/common/environmentVariable'; type VariableResolver = (str: string) => Promise; @@ -19,15 +18,12 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa /** * Using variable as keys is okay here because each terminal instance has its own set of variables. * @karrtikr TODO: Rename it back to map. + * @karrtikr TODO: Check all references of variableMap. */ readonly variableMap: Map = new Map(); constructor( readonly collections: ReadonlyMap, - /** - * @karrtikr TODO: Change it back to private. - */ - public readonly owningWorkspace: IWorkspaceFolder | undefined ) { collections.forEach((collection, extensionIdentifier) => { const it = collection.map.entries(); @@ -36,14 +32,6 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa const mutator = next.value[1]; const variable = mutator.variable; let entry = this.variableMap.get(variable); - if (this.owningWorkspace) { - // If a mutator is scoped to a workspace folder, only apply it if the workspace - // folder matches. - if (mutator.scope?.workspaceFolder && mutator.scope.workspaceFolder.uri.fsPath !== this.owningWorkspace.uri.fsPath) { - next = it.next(); - continue; - } - } if (!entry) { entry = []; this.variableMap.set(variable, entry); @@ -70,7 +58,7 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa }); } - async applyToProcessEnvironment(env: IProcessEnvironment, variableResolver?: VariableResolver): Promise { + async applyToProcessEnvironment(env: IProcessEnvironment, scope: EnvironmentVariableScope | undefined, variableResolver?: VariableResolver): Promise { let lowerToActualVariableNames: { [lowerKey: string]: string | undefined } | undefined; if (isWindows) { lowerToActualVariableNames = {}; @@ -79,6 +67,9 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa for (const [variable, mutators] of this.variableMap) { const actualVariable = isWindows ? lowerToActualVariableNames![variable.toLowerCase()] || variable : variable; for (const mutator of mutators) { + if (filterScope(mutator, scope) === false) { + continue; + } const value = variableResolver ? await variableResolver(mutator.value) : mutator.value; // if (mutator.timing === EnvironmentVariableMutatorTiming.AfterShellIntegration) { // const key = `VSCODE_ENV_${mutatorTypeToLabelMap.get(mutator.type)!}`; @@ -140,6 +131,24 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa } } +function filterScope( + mutator: IExtensionOwnedEnvironmentVariableMutator, + scope: EnvironmentVariableScope | undefined +): boolean { + if (!scope) { + return true; + } + if (!mutator.scope) { + return true; + } + // If a mutator is scoped to a workspace folder, only apply it if the workspace + // folder matches. + if (mutator.scope.workspaceFolder && scope.workspaceFolder && mutator.scope.workspaceFolder.index === scope.workspaceFolder.index) { + return true; + } + return false; +} + function getMissingMutatorsFromArray( current: IExtensionOwnedEnvironmentVariableMutator[], other: IExtensionOwnedEnvironmentVariableMutator[] | undefined diff --git a/src/vs/server/node/remoteTerminalChannel.ts b/src/vs/server/node/remoteTerminalChannel.ts index e8386d82f98..b34889cddec 100644 --- a/src/vs/server/node/remoteTerminalChannel.ts +++ b/src/vs/server/node/remoteTerminalChannel.ts @@ -31,6 +31,7 @@ import { IServerEnvironmentService } from 'vs/server/node/serverEnvironmentServi import { IProductService } from 'vs/platform/product/common/productService'; import { IExtensionManagementService } from 'vs/platform/extensionManagement/common/extensionManagement'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; +import { withNullAsUndefined } from 'vs/base/common/types'; class CustomVariableResolver extends AbstractVariableResolverService { constructor( @@ -236,8 +237,11 @@ export class RemoteTerminalChannel extends Disposable implements IServerChannel< entries.push([k, { map: deserializeEnvironmentVariableCollection(v) }]); } const envVariableCollections = new Map(entries); - const mergedCollection = new MergedEnvironmentVariableCollection(envVariableCollections, activeWorkspaceFolder); - await mergedCollection.applyToProcessEnvironment(env, variableResolver); + const mergedCollection = new MergedEnvironmentVariableCollection(envVariableCollections); + const cwdUri = typeof shellLaunchConfig.cwd === 'string' ? URI.parse(shellLaunchConfig.cwd) : shellLaunchConfig.cwd; + const workspaceFolder = cwdUri ? withNullAsUndefined(activeWorkspaceFolder) : undefined; + // @karrtikr TODO: Pass workspace folder to applyToProcessEnvironment + await mergedCollection.applyToProcessEnvironment(env, { workspaceFolder }, variableResolver); } // Fork the process and listen for messages diff --git a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts index 0223a98df21..68fc6fa2bb3 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts @@ -174,7 +174,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce this._lastActiveWorkspace = activeWorkspaceRootUri ? withNullAsUndefined(this._workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri)) : undefined; if (environmentVariableCollections) { - this._extEnvironmentVariableCollection = new MergedEnvironmentVariableCollection(environmentVariableCollections, this._lastActiveWorkspace); + this._extEnvironmentVariableCollection = new MergedEnvironmentVariableCollection(environmentVariableCollections); this._register(this._environmentVariableService.onDidChangeCollections(newCollection => this._onEnvironmentVariableCollectionChange(newCollection))); this.environmentVariableInfo = this._instantiationService.createInstance(EnvironmentVariableInfoChangesActive, this._extEnvironmentVariableCollection); this._onEnvironmentVariableInfoChange.fire(this.environmentVariableInfo); @@ -411,6 +411,8 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce // Fetch any extension environment additions and apply them private async _resolveEnvironment(backend: ITerminalBackend, variableResolver: terminalEnvironment.VariableResolver | undefined, shellLaunchConfig: IShellLaunchConfig): Promise { + const cwdUri = typeof shellLaunchConfig.cwd === 'string' ? URI.parse(shellLaunchConfig.cwd) : shellLaunchConfig.cwd; + const workspaceFolder = cwdUri ? withNullAsUndefined(this._workspaceContextService.getWorkspaceFolder(cwdUri)) : undefined; const platformKey = isWindows ? 'windows' : (isMacintosh ? 'osx' : 'linux'); const envFromConfigValue = this._configurationService.getValue(`terminal.integrated.env.${platformKey}`); this._configHelper.showRecommendations(shellLaunchConfig); @@ -433,7 +435,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce // info widget. While technically these could differ due to the slight change of a race // condition, the chance is minimal plus the impact on the user is also not that great // if it happens - it's not worth adding plumbing to sync back the resolved collection. - await this._extEnvironmentVariableCollection.applyToProcessEnvironment(env, variableResolver); + await this._extEnvironmentVariableCollection.applyToProcessEnvironment(env, { workspaceFolder }, variableResolver); if (this._extEnvironmentVariableCollection.variableMap.size > 0) { this.environmentVariableInfo = this._instantiationService.createInstance(EnvironmentVariableInfoChangesActive, this._extEnvironmentVariableCollection); this._onEnvironmentVariableInfoChange.fire(this.environmentVariableInfo); diff --git a/src/vs/workbench/contrib/terminal/common/environmentVariableService.ts b/src/vs/workbench/contrib/terminal/common/environmentVariableService.ts index 675deceda4e..3a27fb67d79 100644 --- a/src/vs/workbench/contrib/terminal/common/environmentVariableService.ts +++ b/src/vs/workbench/contrib/terminal/common/environmentVariableService.ts @@ -12,9 +12,6 @@ import { deserializeEnvironmentVariableCollection, serializeEnvironmentVariableC import { IEnvironmentVariableCollectionWithPersistence, IEnvironmentVariableService } from 'vs/workbench/contrib/terminal/common/environmentVariable'; import { TerminalStorageKeys } from 'vs/workbench/contrib/terminal/common/terminalStorageKeys'; import { IMergedEnvironmentVariableCollection, ISerializableEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; -import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; -import { IHistoryService } from 'vs/workbench/services/history/common/history'; -import { withNullAsUndefined } from 'vs/base/common/types'; interface ISerializableExtensionEnvironmentVariableCollection { extensionIdentifier: string; @@ -36,8 +33,6 @@ export class EnvironmentVariableService implements IEnvironmentVariableService { constructor( @IExtensionService private readonly _extensionService: IExtensionService, @IStorageService private readonly _storageService: IStorageService, - @IWorkspaceContextService private readonly _workspaceContextService: IWorkspaceContextService, - @IHistoryService private readonly _historyService: IHistoryService, ) { const serializedPersistedCollections = this._storageService.get(TerminalStorageKeys.EnvironmentVariableCollections, StorageScope.WORKSPACE); if (serializedPersistedCollections) { @@ -103,9 +98,7 @@ export class EnvironmentVariableService implements IEnvironmentVariableService { } private _resolveMergedCollection(): IMergedEnvironmentVariableCollection { - const activeWorkspaceRootUri = this._historyService.getLastActiveWorkspaceRoot(); - const lastActiveWorkspace = activeWorkspaceRootUri ? withNullAsUndefined(this._workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri)) : undefined; - return new MergedEnvironmentVariableCollection(this.collections, lastActiveWorkspace); + return new MergedEnvironmentVariableCollection(this.collections); } private async _invalidateExtensionCollections(): Promise { diff --git a/src/vs/workbench/contrib/terminal/electron-sandbox/localTerminalBackend.ts b/src/vs/workbench/contrib/terminal/electron-sandbox/localTerminalBackend.ts index d3a4b2402e6..0e4091bd2b2 100644 --- a/src/vs/workbench/contrib/terminal/electron-sandbox/localTerminalBackend.ts +++ b/src/vs/workbench/contrib/terminal/electron-sandbox/localTerminalBackend.ts @@ -262,7 +262,9 @@ class LocalTerminalBackend extends BaseTerminalBackend implements ITerminalBacke const baseEnv = await (shellLaunchConfig.useShellEnvironment ? this.getShellEnvironment() : this.getEnvironment()); const env = await terminalEnvironment.createTerminalEnvironment(shellLaunchConfig, envFromConfigValue, variableResolver, this._productService.version, this._configurationService.getValue(TerminalSettingId.DetectLocale), baseEnv); if (!shellLaunchConfig.strictEnv && !shellLaunchConfig.hideFromUser) { - await this._environmentVariableService.mergedCollection.applyToProcessEnvironment(env, variableResolver); + const cwdUri = typeof shellLaunchConfig.cwd === 'string' ? URI.parse(shellLaunchConfig.cwd) : shellLaunchConfig.cwd; + const workspaceFolder = cwdUri ? withNullAsUndefined(this._workspaceContextService.getWorkspaceFolder(cwdUri)) : undefined; + await this._environmentVariableService.mergedCollection.applyToProcessEnvironment(env, { workspaceFolder }, variableResolver); } return env; } From 4170fe5db43ffce10a9f9c25b93a644d8aab1939 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Fri, 14 Apr 2023 08:16:55 +0000 Subject: [PATCH 27/68] More fixes --- .../terminal/common/environmentVariable.ts | 7 +++++-- .../common/environmentVariableCollection.ts | 16 ++++++++++++---- .../terminal/node/terminalEnvironment.ts | 4 ++-- .../terminal/browser/environmentVariableInfo.ts | 10 +++++----- .../contrib/terminal/browser/terminalInstance.ts | 4 +++- .../terminal/common/environmentVariable.ts | 4 ++-- .../common/environmentVariableCollection.test.ts | 4 ++-- .../common/environmentVariableService.test.ts | 8 ++++---- 8 files changed, 35 insertions(+), 22 deletions(-) diff --git a/src/vs/platform/terminal/common/environmentVariable.ts b/src/vs/platform/terminal/common/environmentVariable.ts index 0471c6ff1ce..be236704bae 100644 --- a/src/vs/platform/terminal/common/environmentVariable.ts +++ b/src/vs/platform/terminal/common/environmentVariable.ts @@ -56,8 +56,11 @@ type VariableResolver = (str: string) => Promise; */ export interface IMergedEnvironmentVariableCollection { readonly collections: ReadonlyMap; - readonly variableMap: ReadonlyMap; - + /** + * Gets the variable map for a given scope. + * @param scope The scope to get the variable map for. If undefined, the global scope is used. + */ + getVariableMap(scope: EnvironmentVariableScope | undefined): Map; /** * Applies this collection to a process environment. * @param variableResolver An optional function to use to resolve variables within the diff --git a/src/vs/platform/terminal/common/environmentVariableCollection.ts b/src/vs/platform/terminal/common/environmentVariableCollection.ts index 26b73a178cb..7b23ae07461 100644 --- a/src/vs/platform/terminal/common/environmentVariableCollection.ts +++ b/src/vs/platform/terminal/common/environmentVariableCollection.ts @@ -64,12 +64,9 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa lowerToActualVariableNames = {}; Object.keys(env).forEach(e => lowerToActualVariableNames![e.toLowerCase()] = e); } - for (const [variable, mutators] of this.variableMap) { + for (const [variable, mutators] of this.getVariableMap(scope)) { const actualVariable = isWindows ? lowerToActualVariableNames![variable.toLowerCase()] || variable : variable; for (const mutator of mutators) { - if (filterScope(mutator, scope) === false) { - continue; - } const value = variableResolver ? await variableResolver(mutator.value) : mutator.value; // if (mutator.timing === EnvironmentVariableMutatorTiming.AfterShellIntegration) { // const key = `VSCODE_ENV_${mutatorTypeToLabelMap.get(mutator.type)!}`; @@ -129,6 +126,17 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa return { added, changed, removed }; } + + getVariableMap(scope: EnvironmentVariableScope | undefined): Map { + const result = new Map(); + this.variableMap.forEach((mutators, variable) => { + const filteredMutators = mutators.filter(m => filterScope(m, scope)); + if (filteredMutators.length > 0) { + result.set(variable, filteredMutators); + } + }); + return result; + } } function filterScope( diff --git a/src/vs/platform/terminal/node/terminalEnvironment.ts b/src/vs/platform/terminal/node/terminalEnvironment.ts index fb642bd2c94..f973081f9d6 100644 --- a/src/vs/platform/terminal/node/terminalEnvironment.ts +++ b/src/vs/platform/terminal/node/terminalEnvironment.ts @@ -256,10 +256,10 @@ function addEnvMixinPathPrefix(options: ITerminalProcessOptions, envMixin: IProc if (isMacintosh && options.environmentVariableCollections) { // Deserialize and merge const deserialized = deserializeEnvironmentVariableCollections(options.environmentVariableCollections); - const merged = new MergedEnvironmentVariableCollection(deserialized, options.workspaceFolder); + const merged = new MergedEnvironmentVariableCollection(deserialized); // Get all prepend PATH entries - const pathEntry = merged.variableMap.get('PATH'); + const pathEntry = merged.getVariableMap({ workspaceFolder: options.workspaceFolder }).get('PATH'); const prependToPath: string[] = []; if (pathEntry) { for (const mutator of pathEntry) { diff --git a/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts b/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts index 240a0d4a32d..ee35919b093 100644 --- a/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts +++ b/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts @@ -8,7 +8,7 @@ import { ITerminalStatus, ITerminalStatusHoverAction, TerminalCommandId } from ' import { ITerminalService } from 'vs/workbench/contrib/terminal/browser/terminal'; import { localize } from 'vs/nls'; import { Codicon } from 'vs/base/common/codicons'; -import { IExtensionOwnedEnvironmentVariableMutator, IMergedEnvironmentVariableCollection, IMergedEnvironmentVariableCollectionDiff } from 'vs/platform/terminal/common/environmentVariable'; +import { EnvironmentVariableScope, IExtensionOwnedEnvironmentVariableMutator, IMergedEnvironmentVariableCollection, IMergedEnvironmentVariableCollectionDiff } from 'vs/platform/terminal/common/environmentVariable'; import { TerminalStatus } from 'vs/workbench/contrib/terminal/browser/terminalStatusList'; import Severity from 'vs/base/common/severity'; import { ICommandService } from 'vs/platform/commands/common/commands'; @@ -68,9 +68,9 @@ export class EnvironmentVariableInfoChangesActive implements IEnvironmentVariabl ) { } - private _getInfo(): string { + private _getInfo(scope: EnvironmentVariableScope | undefined): string { const extSet: Set = new Set(); - addExtensionIdentifiers(extSet, this._collection.variableMap.values()); + addExtensionIdentifiers(extSet, this._collection.getVariableMap(scope).values()); let message = localize('extensionEnvironmentContributionInfoActive', "The following extensions have contributed to this terminal's environment:"); message += '\n'; @@ -88,11 +88,11 @@ export class EnvironmentVariableInfoChangesActive implements IEnvironmentVariabl }]; } - getStatus(): ITerminalStatus { + getStatus(scope: EnvironmentVariableScope | undefined): ITerminalStatus { return { id: TerminalStatus.EnvironmentVariableInfoChangesActive, severity: Severity.Info, - tooltip: this._getInfo(), + tooltip: this._getInfo(scope), hoverActions: this._getActions() }; } diff --git a/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts b/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts index 70d75777da4..036274e1da0 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts @@ -2160,9 +2160,11 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { this.relaunch(); return; } + const cwdUri = typeof this.shellLaunchConfig.cwd === 'string' ? URI.parse(this.shellLaunchConfig.cwd) : this.shellLaunchConfig.cwd; + const workspaceFolder = cwdUri ? withNullAsUndefined(this._workspaceContextService.getWorkspaceFolder(cwdUri)) : undefined; // Re-create statuses - this.statusList.add(info.getStatus()); + this.statusList.add(info.getStatus({ workspaceFolder })); } async toggleEscapeSequenceLogging(): Promise { diff --git a/src/vs/workbench/contrib/terminal/common/environmentVariable.ts b/src/vs/workbench/contrib/terminal/common/environmentVariable.ts index c29bfb1b688..6d879f6d20e 100644 --- a/src/vs/workbench/contrib/terminal/common/environmentVariable.ts +++ b/src/vs/workbench/contrib/terminal/common/environmentVariable.ts @@ -5,7 +5,7 @@ import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; import { Event } from 'vs/base/common/event'; -import { IEnvironmentVariableCollection, IMergedEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; +import { EnvironmentVariableScope, IEnvironmentVariableCollection, IMergedEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; import { ITerminalStatus } from 'vs/workbench/contrib/terminal/common/terminal'; export const IEnvironmentVariableService = createDecorator('environmentVariableService'); @@ -51,5 +51,5 @@ export interface IEnvironmentVariableCollectionWithPersistence extends IEnvironm export interface IEnvironmentVariableInfo { readonly requiresAction: boolean; - getStatus(): ITerminalStatus; + getStatus(scope: EnvironmentVariableScope | undefined): ITerminalStatus; } diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts index 5724424c375..4280f82f12c 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts @@ -34,7 +34,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ]) }] ]), undefined); - deepStrictEqual([...merged.variableMap.entries()], [ + deepStrictEqual([...merged.getVariableMap(undefined).entries()], [ ['A', [ { extensionIdentifier: 'ext4', type: EnvironmentVariableMutatorType.Append, value: 'a4', scope: undefined, variable: 'A' }, { extensionIdentifier: 'ext3', type: EnvironmentVariableMutatorType.Prepend, value: 'a3', scope: undefined, variable: 'A' }, @@ -67,7 +67,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ]) }] ]), undefined); - deepStrictEqual([...merged.variableMap.entries()], [ + deepStrictEqual([...merged.getVariableMap(undefined).entries()], [ ['A', [ { extensionIdentifier: 'ext3', type: EnvironmentVariableMutatorType.Replace, value: 'a3', scope: undefined, variable: 'A' }, { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Append, value: 'a2', scope: undefined, variable: 'A' }, diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts index 1c465156126..3033717c433 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts @@ -52,7 +52,7 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { collection.set('B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }); collection.set('C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'C' }); environmentVariableService.set('ext1', { map: collection, persistent: true }); - deepStrictEqual([...environmentVariableService.mergedCollection.variableMap.entries()], [ + deepStrictEqual([...environmentVariableService.mergedCollection.getVariableMap(undefined).entries()], [ ['A', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Replace, value: 'a', scope: undefined, variable: 'A' }]], ['B', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Append, value: 'b', scope: undefined, variable: 'B' }]], ['C', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Prepend, value: 'c', scope: undefined, variable: 'C' }]] @@ -61,7 +61,7 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { // Persist with old service, create a new service with the same storage service to verify restore environmentVariableService.persistCollections(); const service2: TestEnvironmentVariableService = instantiationService.createInstance(TestEnvironmentVariableService); - deepStrictEqual([...service2.mergedCollection.variableMap.entries()], [ + deepStrictEqual([...service2.mergedCollection.getVariableMap(undefined).entries()], [ ['A', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Replace, value: 'a', scope: undefined, variable: 'A' }]], ['B', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Append, value: 'b', scope: undefined, variable: 'B' }]], ['C', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Prepend, value: 'c', scope: undefined, variable: 'C' }]] @@ -82,7 +82,7 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { environmentVariableService.set('ext1', { map: collection1, persistent: true }); environmentVariableService.set('ext2', { map: collection2, persistent: true }); environmentVariableService.set('ext3', { map: collection3, persistent: true }); - deepStrictEqual([...environmentVariableService.mergedCollection.variableMap.entries()], [ + deepStrictEqual([...environmentVariableService.mergedCollection.getVariableMap(undefined).entries()], [ ['A', [ { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Replace, value: 'a2', scope: undefined, variable: 'A' }, { extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Append, value: 'a1', scope: undefined, variable: 'A' } @@ -103,7 +103,7 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { environmentVariableService.set('ext3', { map: collection3, persistent: true }); // The entries should be ordered in the order they are applied - deepStrictEqual([...environmentVariableService.mergedCollection.variableMap.entries()], [ + deepStrictEqual([...environmentVariableService.mergedCollection.getVariableMap(undefined).entries()], [ ['A', [ { extensionIdentifier: 'ext3', type: EnvironmentVariableMutatorType.Replace, value: 'a3', scope: undefined, variable: 'A' }, { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Prepend, value: 'a2:', scope: undefined, variable: 'A' }, From bd4e21ad1722fc70935098411da985190be1b462 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Fri, 14 Apr 2023 08:55:20 +0000 Subject: [PATCH 28/68] Propogate more --- .../browser/environmentVariableInfo.ts | 41 ++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts b/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts index ee35919b093..e6797569201 100644 --- a/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts +++ b/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts @@ -25,11 +25,11 @@ export class EnvironmentVariableInfoStale implements IEnvironmentVariableInfo { ) { } - private _getInfo(): string { + private _getInfo(scope: EnvironmentVariableScope | undefined): string { const extSet: Set = new Set(); - addExtensionIdentifiers(extSet, this._diff.added.values()); - addExtensionIdentifiers(extSet, this._diff.removed.values()); - addExtensionIdentifiers(extSet, this._diff.changed.values()); + addExtensionIdentifiers(extSet, this._getScopedDiff(this._diff.added, scope).values()); + addExtensionIdentifiers(extSet, this._getScopedDiff(this._diff.removed, scope).values()); + addExtensionIdentifiers(extSet, this._getScopedDiff(this._diff.changed, scope).values()); let message = localize('extensionEnvironmentContributionInfoStale', "The following extensions want to relaunch the terminal to contribute to its environment:"); message += '\n'; @@ -39,6 +39,17 @@ export class EnvironmentVariableInfoStale implements IEnvironmentVariableInfo { return message; } + private _getScopedDiff(diff: ReadonlyMap, scope: EnvironmentVariableScope | undefined): ReadonlyMap { + const scopedDiff = new Map(); + for (const [variable, mutators] of diff) { + const scopedMutators = mutators.filter(m => filterScope(m, scope)); + if (scopedMutators.length > 0) { + scopedDiff.set(variable, scopedMutators); + } + } + return scopedDiff; + } + private _getActions(): ITerminalStatusHoverAction[] { return [{ label: localize('relaunchTerminalLabel', "Relaunch terminal"), @@ -47,12 +58,12 @@ export class EnvironmentVariableInfoStale implements IEnvironmentVariableInfo { }]; } - getStatus(): ITerminalStatus { + getStatus(scope: EnvironmentVariableScope | undefined): ITerminalStatus { return { id: TerminalStatus.RelaunchNeeded, severity: Severity.Warning, icon: Codicon.warning, - tooltip: this._getInfo(), + tooltip: this._getInfo(scope), hoverActions: this._getActions() }; } @@ -109,3 +120,21 @@ function addExtensionIdentifiers(extSet: Set, diff: IterableIterator e.id === id)?.displayName || id; } + +function filterScope( + mutator: IExtensionOwnedEnvironmentVariableMutator, + scope: EnvironmentVariableScope | undefined +): boolean { + if (!scope) { + return true; + } + if (!mutator.scope) { + return true; + } + // If a mutator is scoped to a workspace folder, only apply it if the workspace + // folder matches. + if (mutator.scope.workspaceFolder && scope.workspaceFolder && mutator.scope.workspaceFolder.index === scope.workspaceFolder.index) { + return true; + } + return false; +} From 0e68130398b98de7366f014d0eb2b9907cd691bf Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Fri, 14 Apr 2023 09:19:18 +0000 Subject: [PATCH 29/68] Undo --- src/vs/platform/terminal/common/environmentVariable.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/vs/platform/terminal/common/environmentVariable.ts b/src/vs/platform/terminal/common/environmentVariable.ts index be236704bae..4aed82cc684 100644 --- a/src/vs/platform/terminal/common/environmentVariable.ts +++ b/src/vs/platform/terminal/common/environmentVariable.ts @@ -56,6 +56,7 @@ type VariableResolver = (str: string) => Promise; */ export interface IMergedEnvironmentVariableCollection { readonly collections: ReadonlyMap; + readonly variableMap: ReadonlyMap; /** * Gets the variable map for a given scope. * @param scope The scope to get the variable map for. If undefined, the global scope is used. From 2b37e8ebe2c5c11291efe7792ddcd5b1732fdc31 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Fri, 14 Apr 2023 09:34:36 +0000 Subject: [PATCH 30/68] Show env contributions --- .../terminal/browser/environmentVariableInfo.ts | 6 +++--- .../terminal.environmentChanges.contribution.ts | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts b/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts index e6797569201..5be84e3ab30 100644 --- a/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts +++ b/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts @@ -91,10 +91,10 @@ export class EnvironmentVariableInfoChangesActive implements IEnvironmentVariabl return message; } - private _getActions(): ITerminalStatusHoverAction[] { + private _getActions(scope: EnvironmentVariableScope | undefined): ITerminalStatusHoverAction[] { return [{ label: localize('showEnvironmentContributions', "Show environment contributions"), - run: () => this._commandService.executeCommand(TerminalCommandId.ShowEnvironmentContributions), + run: () => this._commandService.executeCommand(TerminalCommandId.ShowEnvironmentContributions, scope), commandId: TerminalCommandId.ShowEnvironmentContributions }]; } @@ -104,7 +104,7 @@ export class EnvironmentVariableInfoChangesActive implements IEnvironmentVariabl id: TerminalStatus.EnvironmentVariableInfoChangesActive, severity: Severity.Info, tooltip: this._getInfo(scope), - hoverActions: this._getActions() + hoverActions: this._getActions(scope) }; } } diff --git a/src/vs/workbench/contrib/terminalContrib/environmentChanges/browser/terminal.environmentChanges.contribution.ts b/src/vs/workbench/contrib/terminalContrib/environmentChanges/browser/terminal.environmentChanges.contribution.ts index 1bd219cd475..029c122a5df 100644 --- a/src/vs/workbench/contrib/terminalContrib/environmentChanges/browser/terminal.environmentChanges.contribution.ts +++ b/src/vs/workbench/contrib/terminalContrib/environmentChanges/browser/terminal.environmentChanges.contribution.ts @@ -6,7 +6,7 @@ import { Schemas } from 'vs/base/common/network'; import { URI } from 'vs/base/common/uri'; import { localize } from 'vs/nls'; -import { EnvironmentVariableMutatorType, IMergedEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; +import { EnvironmentVariableMutatorType, EnvironmentVariableScope, IMergedEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; import { registerActiveInstanceAction } from 'vs/workbench/contrib/terminal/browser/terminalActions'; import { TerminalCommandId } from 'vs/workbench/contrib/terminal/common/terminal'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; @@ -16,7 +16,7 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic registerActiveInstanceAction({ id: TerminalCommandId.ShowEnvironmentContributions, title: { value: localize('workbench.action.terminal.showEnvironmentContributions', "Show Environment Contributions"), original: 'Show Environment Contributions' }, - run: async (activeInstance, c, accessor) => { + run: async (activeInstance, c, accessor, scope) => { const collection = activeInstance.extEnvironmentVariableCollection; if (collection) { const editorService = accessor.get(IEditorService); @@ -24,7 +24,7 @@ registerActiveInstanceAction({ resource: URI.from({ scheme: Schemas.untitled }), - contents: describeEnvironmentChanges(collection), + contents: describeEnvironmentChanges(collection, scope as EnvironmentVariableScope | undefined), languageId: 'markdown' }); } @@ -32,15 +32,15 @@ registerActiveInstanceAction({ }); -function describeEnvironmentChanges(collection: IMergedEnvironmentVariableCollection): string { +function describeEnvironmentChanges(collection: IMergedEnvironmentVariableCollection, scope: EnvironmentVariableScope | undefined): string { let content = `# ${localize('envChanges', 'Terminal Environment Changes')}`; for (const [ext, coll] of collection.collections) { content += `\n\n## ${localize('extension', 'Extension: {0}', ext)}`; content += '\n'; for (const [_, mutator] of coll.map.entries()) { - if (collection.owningWorkspace) { + if (scope?.workspaceFolder) { // Only mutators which are applicable on the relevant workspace should be shown. - if (mutator.scope?.workspaceFolder && mutator.scope.workspaceFolder.index !== collection.owningWorkspace.index) { + if (mutator.scope?.workspaceFolder && mutator.scope.workspaceFolder.index !== scope?.workspaceFolder.index) { continue; } } From 2859ba122c21feb9f60a88fdc7bb8be99b364c75 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Fri, 14 Apr 2023 10:39:21 +0000 Subject: [PATCH 31/68] Try to fix diff --- .../terminal/common/environmentVariable.ts | 2 +- .../common/environmentVariableCollection.ts | 14 +++++++------- .../terminal/browser/terminalProcessManager.ts | 6 ++++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/vs/platform/terminal/common/environmentVariable.ts b/src/vs/platform/terminal/common/environmentVariable.ts index 4aed82cc684..8bcf6ea6ff3 100644 --- a/src/vs/platform/terminal/common/environmentVariable.ts +++ b/src/vs/platform/terminal/common/environmentVariable.ts @@ -73,5 +73,5 @@ export interface IMergedEnvironmentVariableCollection { * Generates a diff of this collection against another. Returns undefined if the collections are * the same. */ - diff(other: IMergedEnvironmentVariableCollection): IMergedEnvironmentVariableCollectionDiff | undefined; + diff(other: IMergedEnvironmentVariableCollection, scope: EnvironmentVariableScope | undefined): IMergedEnvironmentVariableCollectionDiff | undefined; } diff --git a/src/vs/platform/terminal/common/environmentVariableCollection.ts b/src/vs/platform/terminal/common/environmentVariableCollection.ts index 7b23ae07461..46918a70621 100644 --- a/src/vs/platform/terminal/common/environmentVariableCollection.ts +++ b/src/vs/platform/terminal/common/environmentVariableCollection.ts @@ -88,14 +88,14 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa } } - diff(other: IMergedEnvironmentVariableCollection): IMergedEnvironmentVariableCollectionDiff | undefined { + diff(other: IMergedEnvironmentVariableCollection, scope: EnvironmentVariableScope | undefined): IMergedEnvironmentVariableCollectionDiff | undefined { const added: Map = new Map(); const changed: Map = new Map(); const removed: Map = new Map(); // Find added - other.variableMap.forEach((otherMutators, variable) => { - const currentMutators = this.variableMap.get(variable); + other.getVariableMap(scope).forEach((otherMutators, variable) => { + const currentMutators = this.getVariableMap(scope).get(variable); const result = getMissingMutatorsFromArray(otherMutators, currentMutators); if (result) { added.set(variable, result); @@ -103,8 +103,8 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa }); // Find removed - this.variableMap.forEach((currentMutators, variable) => { - const otherMutators = other.variableMap.get(variable); + this.getVariableMap(scope).forEach((currentMutators, variable) => { + const otherMutators = other.getVariableMap(scope).get(variable); const result = getMissingMutatorsFromArray(currentMutators, otherMutators); if (result) { removed.set(variable, result); @@ -112,8 +112,8 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa }); // Find changed - this.variableMap.forEach((currentMutators, variable) => { - const otherMutators = other.variableMap.get(variable); + this.getVariableMap(scope).forEach((currentMutators, variable) => { + const otherMutators = other.getVariableMap(scope).get(variable); const result = getChangedMutatorsFromArray(currentMutators, otherMutators); if (result) { changed.set(variable, result); diff --git a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts index 68fc6fa2bb3..5a5748412a7 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts @@ -116,6 +116,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce readonly onProcessExit = this._onProcessExit.event; private readonly _onRestoreCommands = this._register(new Emitter()); readonly onRestoreCommands = this._onRestoreCommands.event; + private _cwdWorkspaceFolder: IWorkspaceFolder | undefined; private _lastActiveWorkspace: IWorkspaceFolder | undefined; get persistentProcessId(): number | undefined { return this._process?.id; } @@ -147,7 +148,8 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce @INotificationService private readonly _notificationService: INotificationService ) { super(); - + const cwdUri = typeof cwd === 'string' ? URI.parse(cwd) : cwd; + this._cwdWorkspaceFolder = cwdUri ? withNullAsUndefined(this._workspaceContextService.getWorkspaceFolder(cwdUri)) : undefined; this.ptyProcessReady = this._createPtyProcessReadyPromise(); this.getLatency(); this._ackDataBufferer = new AckDataBufferer(e => this._process?.acknowledgeDataEvent(e)); @@ -652,7 +654,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce } private _onEnvironmentVariableCollectionChange(newCollection: IMergedEnvironmentVariableCollection): void { - const diff = this._extEnvironmentVariableCollection!.diff(newCollection); + const diff = this._extEnvironmentVariableCollection!.diff(newCollection, { workspaceFolder: this._cwdWorkspaceFolder }); if (diff === undefined) { // If there are no longer differences, remove the stale info indicator if (this.environmentVariableInfo instanceof EnvironmentVariableInfoStale) { From 1b0ab360f7b565efb40092b8aa2d76be7650881f Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Fri, 14 Apr 2023 10:46:58 +0000 Subject: [PATCH 32/68] Fix keys in diff --- .../terminal/common/environmentVariable.ts | 1 - .../common/environmentVariableCollection.ts | 20 +++++++++---------- .../browser/environmentVariableInfo.ts | 4 ++-- .../browser/terminalProcessManager.ts | 2 +- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/vs/platform/terminal/common/environmentVariable.ts b/src/vs/platform/terminal/common/environmentVariable.ts index 8bcf6ea6ff3..ce731ff8b71 100644 --- a/src/vs/platform/terminal/common/environmentVariable.ts +++ b/src/vs/platform/terminal/common/environmentVariable.ts @@ -56,7 +56,6 @@ type VariableResolver = (str: string) => Promise; */ export interface IMergedEnvironmentVariableCollection { readonly collections: ReadonlyMap; - readonly variableMap: ReadonlyMap; /** * Gets the variable map for a given scope. * @param scope The scope to get the variable map for. If undefined, the global scope is used. diff --git a/src/vs/platform/terminal/common/environmentVariableCollection.ts b/src/vs/platform/terminal/common/environmentVariableCollection.ts index 46918a70621..6f731446fd8 100644 --- a/src/vs/platform/terminal/common/environmentVariableCollection.ts +++ b/src/vs/platform/terminal/common/environmentVariableCollection.ts @@ -20,7 +20,7 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa * @karrtikr TODO: Rename it back to map. * @karrtikr TODO: Check all references of variableMap. */ - readonly variableMap: Map = new Map(); + private readonly variableMap: Map = new Map(); constructor( readonly collections: ReadonlyMap, @@ -94,29 +94,29 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa const removed: Map = new Map(); // Find added - other.getVariableMap(scope).forEach((otherMutators, variable) => { - const currentMutators = this.getVariableMap(scope).get(variable); + other.getVariableMap(scope).forEach((otherMutators, key) => { + const currentMutators = this.getVariableMap(scope).get(key); const result = getMissingMutatorsFromArray(otherMutators, currentMutators); if (result) { - added.set(variable, result); + added.set(key, result); } }); // Find removed - this.getVariableMap(scope).forEach((currentMutators, variable) => { - const otherMutators = other.getVariableMap(scope).get(variable); + this.getVariableMap(scope).forEach((currentMutators, key) => { + const otherMutators = other.getVariableMap(scope).get(key); const result = getMissingMutatorsFromArray(currentMutators, otherMutators); if (result) { - removed.set(variable, result); + removed.set(key, result); } }); // Find changed - this.getVariableMap(scope).forEach((currentMutators, variable) => { - const otherMutators = other.getVariableMap(scope).get(variable); + this.getVariableMap(scope).forEach((currentMutators, key) => { + const otherMutators = other.getVariableMap(scope).get(key); const result = getChangedMutatorsFromArray(currentMutators, otherMutators); if (result) { - changed.set(variable, result); + changed.set(key, result); } }); diff --git a/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts b/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts index 5be84e3ab30..705b5d0aa7d 100644 --- a/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts +++ b/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts @@ -41,10 +41,10 @@ export class EnvironmentVariableInfoStale implements IEnvironmentVariableInfo { private _getScopedDiff(diff: ReadonlyMap, scope: EnvironmentVariableScope | undefined): ReadonlyMap { const scopedDiff = new Map(); - for (const [variable, mutators] of diff) { + for (const [key, mutators] of diff) { const scopedMutators = mutators.filter(m => filterScope(m, scope)); if (scopedMutators.length > 0) { - scopedDiff.set(variable, scopedMutators); + scopedDiff.set(key, scopedMutators); } } return scopedDiff; diff --git a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts index 5a5748412a7..87b7dc1bdbe 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts @@ -438,7 +438,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce // condition, the chance is minimal plus the impact on the user is also not that great // if it happens - it's not worth adding plumbing to sync back the resolved collection. await this._extEnvironmentVariableCollection.applyToProcessEnvironment(env, { workspaceFolder }, variableResolver); - if (this._extEnvironmentVariableCollection.variableMap.size > 0) { + if (this._extEnvironmentVariableCollection.getVariableMap({ workspaceFolder }).size > 0) { this.environmentVariableInfo = this._instantiationService.createInstance(EnvironmentVariableInfoChangesActive, this._extEnvironmentVariableCollection); this._onEnvironmentVariableInfoChange.fire(this.environmentVariableInfo); } From 87f4291d71d4427f982aa6be8fe0c248e0d32687 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Fri, 14 Apr 2023 10:54:49 +0000 Subject: [PATCH 33/68] Fix variable map --- .../terminal/common/environmentVariable.ts | 2 +- .../common/environmentVariableCollection.ts | 35 ++++++++----------- .../terminal/node/terminalEnvironment.ts | 2 +- .../browser/environmentVariableInfo.ts | 2 +- .../browser/terminalProcessManager.ts | 2 +- .../environmentVariableCollection.test.ts | 4 +-- .../common/environmentVariableService.test.ts | 8 ++--- 7 files changed, 25 insertions(+), 30 deletions(-) diff --git a/src/vs/platform/terminal/common/environmentVariable.ts b/src/vs/platform/terminal/common/environmentVariable.ts index ce731ff8b71..77017446919 100644 --- a/src/vs/platform/terminal/common/environmentVariable.ts +++ b/src/vs/platform/terminal/common/environmentVariable.ts @@ -60,7 +60,7 @@ export interface IMergedEnvironmentVariableCollection { * Gets the variable map for a given scope. * @param scope The scope to get the variable map for. If undefined, the global scope is used. */ - getVariableMap(scope: EnvironmentVariableScope | undefined): Map; + getMapForScope(scope: EnvironmentVariableScope | undefined): Map; /** * Applies this collection to a process environment. * @param variableResolver An optional function to use to resolve variables within the diff --git a/src/vs/platform/terminal/common/environmentVariableCollection.ts b/src/vs/platform/terminal/common/environmentVariableCollection.ts index 6f731446fd8..903c5838832 100644 --- a/src/vs/platform/terminal/common/environmentVariableCollection.ts +++ b/src/vs/platform/terminal/common/environmentVariableCollection.ts @@ -15,12 +15,7 @@ type VariableResolver = (str: string) => Promise; // ]); export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVariableCollection { - /** - * Using variable as keys is okay here because each terminal instance has its own set of variables. - * @karrtikr TODO: Rename it back to map. - * @karrtikr TODO: Check all references of variableMap. - */ - private readonly variableMap: Map = new Map(); + private readonly map: Map = new Map(); constructor( readonly collections: ReadonlyMap, @@ -30,11 +25,11 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa let next = it.next(); while (!next.done) { const mutator = next.value[1]; - const variable = mutator.variable; - let entry = this.variableMap.get(variable); + const key = next.value[0]; + let entry = this.map.get(key); if (!entry) { entry = []; - this.variableMap.set(variable, entry); + this.map.set(key, entry); } // If the first item in the entry is replace ignore any other entries as they would @@ -64,9 +59,9 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa lowerToActualVariableNames = {}; Object.keys(env).forEach(e => lowerToActualVariableNames![e.toLowerCase()] = e); } - for (const [variable, mutators] of this.getVariableMap(scope)) { - const actualVariable = isWindows ? lowerToActualVariableNames![variable.toLowerCase()] || variable : variable; + for (const [_, mutators] of this.getMapForScope(scope)) { for (const mutator of mutators) { + const actualVariable = isWindows ? lowerToActualVariableNames![mutator.variable.toLowerCase()] || mutator.variable : mutator.variable; const value = variableResolver ? await variableResolver(mutator.value) : mutator.value; // if (mutator.timing === EnvironmentVariableMutatorTiming.AfterShellIntegration) { // const key = `VSCODE_ENV_${mutatorTypeToLabelMap.get(mutator.type)!}`; @@ -94,8 +89,8 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa const removed: Map = new Map(); // Find added - other.getVariableMap(scope).forEach((otherMutators, key) => { - const currentMutators = this.getVariableMap(scope).get(key); + other.getMapForScope(scope).forEach((otherMutators, key) => { + const currentMutators = this.getMapForScope(scope).get(key); const result = getMissingMutatorsFromArray(otherMutators, currentMutators); if (result) { added.set(key, result); @@ -103,8 +98,8 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa }); // Find removed - this.getVariableMap(scope).forEach((currentMutators, key) => { - const otherMutators = other.getVariableMap(scope).get(key); + this.getMapForScope(scope).forEach((currentMutators, key) => { + const otherMutators = other.getMapForScope(scope).get(key); const result = getMissingMutatorsFromArray(currentMutators, otherMutators); if (result) { removed.set(key, result); @@ -112,8 +107,8 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa }); // Find changed - this.getVariableMap(scope).forEach((currentMutators, key) => { - const otherMutators = other.getVariableMap(scope).get(key); + this.getMapForScope(scope).forEach((currentMutators, key) => { + const otherMutators = other.getMapForScope(scope).get(key); const result = getChangedMutatorsFromArray(currentMutators, otherMutators); if (result) { changed.set(key, result); @@ -127,12 +122,12 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa return { added, changed, removed }; } - getVariableMap(scope: EnvironmentVariableScope | undefined): Map { + getMapForScope(scope: EnvironmentVariableScope | undefined): Map { const result = new Map(); - this.variableMap.forEach((mutators, variable) => { + this.map.forEach((mutators, key) => { const filteredMutators = mutators.filter(m => filterScope(m, scope)); if (filteredMutators.length > 0) { - result.set(variable, filteredMutators); + result.set(key, filteredMutators); } }); return result; diff --git a/src/vs/platform/terminal/node/terminalEnvironment.ts b/src/vs/platform/terminal/node/terminalEnvironment.ts index f973081f9d6..00fa1fe1364 100644 --- a/src/vs/platform/terminal/node/terminalEnvironment.ts +++ b/src/vs/platform/terminal/node/terminalEnvironment.ts @@ -259,7 +259,7 @@ function addEnvMixinPathPrefix(options: ITerminalProcessOptions, envMixin: IProc const merged = new MergedEnvironmentVariableCollection(deserialized); // Get all prepend PATH entries - const pathEntry = merged.getVariableMap({ workspaceFolder: options.workspaceFolder }).get('PATH'); + const pathEntry = merged.getMapForScope({ workspaceFolder: options.workspaceFolder }).get('PATH'); const prependToPath: string[] = []; if (pathEntry) { for (const mutator of pathEntry) { diff --git a/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts b/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts index 705b5d0aa7d..80cff436a9f 100644 --- a/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts +++ b/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts @@ -81,7 +81,7 @@ export class EnvironmentVariableInfoChangesActive implements IEnvironmentVariabl private _getInfo(scope: EnvironmentVariableScope | undefined): string { const extSet: Set = new Set(); - addExtensionIdentifiers(extSet, this._collection.getVariableMap(scope).values()); + addExtensionIdentifiers(extSet, this._collection.getMapForScope(scope).values()); let message = localize('extensionEnvironmentContributionInfoActive', "The following extensions have contributed to this terminal's environment:"); message += '\n'; diff --git a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts index 87b7dc1bdbe..50c7532145a 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts @@ -438,7 +438,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce // condition, the chance is minimal plus the impact on the user is also not that great // if it happens - it's not worth adding plumbing to sync back the resolved collection. await this._extEnvironmentVariableCollection.applyToProcessEnvironment(env, { workspaceFolder }, variableResolver); - if (this._extEnvironmentVariableCollection.getVariableMap({ workspaceFolder }).size > 0) { + if (this._extEnvironmentVariableCollection.getMapForScope({ workspaceFolder }).size > 0) { this.environmentVariableInfo = this._instantiationService.createInstance(EnvironmentVariableInfoChangesActive, this._extEnvironmentVariableCollection); this._onEnvironmentVariableInfoChange.fire(this.environmentVariableInfo); } diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts index 4280f82f12c..ee6dd00660e 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts @@ -34,7 +34,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ]) }] ]), undefined); - deepStrictEqual([...merged.getVariableMap(undefined).entries()], [ + deepStrictEqual([...merged.getMapForScope(undefined).entries()], [ ['A', [ { extensionIdentifier: 'ext4', type: EnvironmentVariableMutatorType.Append, value: 'a4', scope: undefined, variable: 'A' }, { extensionIdentifier: 'ext3', type: EnvironmentVariableMutatorType.Prepend, value: 'a3', scope: undefined, variable: 'A' }, @@ -67,7 +67,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ]) }] ]), undefined); - deepStrictEqual([...merged.getVariableMap(undefined).entries()], [ + deepStrictEqual([...merged.getMapForScope(undefined).entries()], [ ['A', [ { extensionIdentifier: 'ext3', type: EnvironmentVariableMutatorType.Replace, value: 'a3', scope: undefined, variable: 'A' }, { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Append, value: 'a2', scope: undefined, variable: 'A' }, diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts index 3033717c433..2a271c5c0c2 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts @@ -52,7 +52,7 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { collection.set('B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }); collection.set('C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'C' }); environmentVariableService.set('ext1', { map: collection, persistent: true }); - deepStrictEqual([...environmentVariableService.mergedCollection.getVariableMap(undefined).entries()], [ + deepStrictEqual([...environmentVariableService.mergedCollection.getMapForScope(undefined).entries()], [ ['A', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Replace, value: 'a', scope: undefined, variable: 'A' }]], ['B', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Append, value: 'b', scope: undefined, variable: 'B' }]], ['C', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Prepend, value: 'c', scope: undefined, variable: 'C' }]] @@ -61,7 +61,7 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { // Persist with old service, create a new service with the same storage service to verify restore environmentVariableService.persistCollections(); const service2: TestEnvironmentVariableService = instantiationService.createInstance(TestEnvironmentVariableService); - deepStrictEqual([...service2.mergedCollection.getVariableMap(undefined).entries()], [ + deepStrictEqual([...service2.mergedCollection.getMapForScope(undefined).entries()], [ ['A', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Replace, value: 'a', scope: undefined, variable: 'A' }]], ['B', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Append, value: 'b', scope: undefined, variable: 'B' }]], ['C', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Prepend, value: 'c', scope: undefined, variable: 'C' }]] @@ -82,7 +82,7 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { environmentVariableService.set('ext1', { map: collection1, persistent: true }); environmentVariableService.set('ext2', { map: collection2, persistent: true }); environmentVariableService.set('ext3', { map: collection3, persistent: true }); - deepStrictEqual([...environmentVariableService.mergedCollection.getVariableMap(undefined).entries()], [ + deepStrictEqual([...environmentVariableService.mergedCollection.getMapForScope(undefined).entries()], [ ['A', [ { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Replace, value: 'a2', scope: undefined, variable: 'A' }, { extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Append, value: 'a1', scope: undefined, variable: 'A' } @@ -103,7 +103,7 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { environmentVariableService.set('ext3', { map: collection3, persistent: true }); // The entries should be ordered in the order they are applied - deepStrictEqual([...environmentVariableService.mergedCollection.getVariableMap(undefined).entries()], [ + deepStrictEqual([...environmentVariableService.mergedCollection.getMapForScope(undefined).entries()], [ ['A', [ { extensionIdentifier: 'ext3', type: EnvironmentVariableMutatorType.Replace, value: 'a3', scope: undefined, variable: 'A' }, { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Prepend, value: 'a2:', scope: undefined, variable: 'A' }, From b68f2e550b6cf0a95d278104953783df7950c984 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Fri, 14 Apr 2023 10:58:10 +0000 Subject: [PATCH 34/68] Undo unncessary changes --- .../browser/environmentVariableInfo.ts | 41 +++---------------- 1 file changed, 6 insertions(+), 35 deletions(-) diff --git a/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts b/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts index 80cff436a9f..9e6a1bf6867 100644 --- a/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts +++ b/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts @@ -25,11 +25,11 @@ export class EnvironmentVariableInfoStale implements IEnvironmentVariableInfo { ) { } - private _getInfo(scope: EnvironmentVariableScope | undefined): string { + private _getInfo(): string { const extSet: Set = new Set(); - addExtensionIdentifiers(extSet, this._getScopedDiff(this._diff.added, scope).values()); - addExtensionIdentifiers(extSet, this._getScopedDiff(this._diff.removed, scope).values()); - addExtensionIdentifiers(extSet, this._getScopedDiff(this._diff.changed, scope).values()); + addExtensionIdentifiers(extSet, this._diff.added.values()); + addExtensionIdentifiers(extSet, this._diff.removed.values()); + addExtensionIdentifiers(extSet, this._diff.changed.values()); let message = localize('extensionEnvironmentContributionInfoStale', "The following extensions want to relaunch the terminal to contribute to its environment:"); message += '\n'; @@ -39,17 +39,6 @@ export class EnvironmentVariableInfoStale implements IEnvironmentVariableInfo { return message; } - private _getScopedDiff(diff: ReadonlyMap, scope: EnvironmentVariableScope | undefined): ReadonlyMap { - const scopedDiff = new Map(); - for (const [key, mutators] of diff) { - const scopedMutators = mutators.filter(m => filterScope(m, scope)); - if (scopedMutators.length > 0) { - scopedDiff.set(key, scopedMutators); - } - } - return scopedDiff; - } - private _getActions(): ITerminalStatusHoverAction[] { return [{ label: localize('relaunchTerminalLabel', "Relaunch terminal"), @@ -58,12 +47,12 @@ export class EnvironmentVariableInfoStale implements IEnvironmentVariableInfo { }]; } - getStatus(scope: EnvironmentVariableScope | undefined): ITerminalStatus { + getStatus(_: EnvironmentVariableScope | undefined): ITerminalStatus { return { id: TerminalStatus.RelaunchNeeded, severity: Severity.Warning, icon: Codicon.warning, - tooltip: this._getInfo(scope), + tooltip: this._getInfo(), hoverActions: this._getActions() }; } @@ -120,21 +109,3 @@ function addExtensionIdentifiers(extSet: Set, diff: IterableIterator e.id === id)?.displayName || id; } - -function filterScope( - mutator: IExtensionOwnedEnvironmentVariableMutator, - scope: EnvironmentVariableScope | undefined -): boolean { - if (!scope) { - return true; - } - if (!mutator.scope) { - return true; - } - // If a mutator is scoped to a workspace folder, only apply it if the workspace - // folder matches. - if (mutator.scope.workspaceFolder && scope.workspaceFolder && mutator.scope.workspaceFolder.index === scope.workspaceFolder.index) { - return true; - } - return false; -} From 6ef977024a702dac3606117d4635b5af22547663 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Fri, 14 Apr 2023 11:12:23 +0000 Subject: [PATCH 35/68] Use variable map instead --- .../terminal/common/environmentVariable.ts | 2 +- .../common/environmentVariableCollection.ts | 21 ++++++++++--------- .../terminal/node/terminalEnvironment.ts | 2 +- .../browser/environmentVariableInfo.ts | 2 +- .../browser/terminalProcessManager.ts | 2 +- .../environmentVariableCollection.test.ts | 4 ++-- .../common/environmentVariableService.test.ts | 8 +++---- 7 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/vs/platform/terminal/common/environmentVariable.ts b/src/vs/platform/terminal/common/environmentVariable.ts index 77017446919..ce731ff8b71 100644 --- a/src/vs/platform/terminal/common/environmentVariable.ts +++ b/src/vs/platform/terminal/common/environmentVariable.ts @@ -60,7 +60,7 @@ export interface IMergedEnvironmentVariableCollection { * Gets the variable map for a given scope. * @param scope The scope to get the variable map for. If undefined, the global scope is used. */ - getMapForScope(scope: EnvironmentVariableScope | undefined): Map; + getVariableMap(scope: EnvironmentVariableScope | undefined): Map; /** * Applies this collection to a process environment. * @param variableResolver An optional function to use to resolve variables within the diff --git a/src/vs/platform/terminal/common/environmentVariableCollection.ts b/src/vs/platform/terminal/common/environmentVariableCollection.ts index 903c5838832..81829ed5eff 100644 --- a/src/vs/platform/terminal/common/environmentVariableCollection.ts +++ b/src/vs/platform/terminal/common/environmentVariableCollection.ts @@ -59,7 +59,7 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa lowerToActualVariableNames = {}; Object.keys(env).forEach(e => lowerToActualVariableNames![e.toLowerCase()] = e); } - for (const [_, mutators] of this.getMapForScope(scope)) { + for (const [_, mutators] of this.getVariableMap(scope)) { for (const mutator of mutators) { const actualVariable = isWindows ? lowerToActualVariableNames![mutator.variable.toLowerCase()] || mutator.variable : mutator.variable; const value = variableResolver ? await variableResolver(mutator.value) : mutator.value; @@ -89,8 +89,8 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa const removed: Map = new Map(); // Find added - other.getMapForScope(scope).forEach((otherMutators, key) => { - const currentMutators = this.getMapForScope(scope).get(key); + other.getVariableMap(scope).forEach((otherMutators, key) => { + const currentMutators = this.getVariableMap(scope).get(key); const result = getMissingMutatorsFromArray(otherMutators, currentMutators); if (result) { added.set(key, result); @@ -98,8 +98,8 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa }); // Find removed - this.getMapForScope(scope).forEach((currentMutators, key) => { - const otherMutators = other.getMapForScope(scope).get(key); + this.getVariableMap(scope).forEach((currentMutators, key) => { + const otherMutators = other.getVariableMap(scope).get(key); const result = getMissingMutatorsFromArray(currentMutators, otherMutators); if (result) { removed.set(key, result); @@ -107,8 +107,8 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa }); // Find changed - this.getMapForScope(scope).forEach((currentMutators, key) => { - const otherMutators = other.getMapForScope(scope).get(key); + this.getVariableMap(scope).forEach((currentMutators, key) => { + const otherMutators = other.getVariableMap(scope).get(key); const result = getChangedMutatorsFromArray(currentMutators, otherMutators); if (result) { changed.set(key, result); @@ -122,12 +122,13 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa return { added, changed, removed }; } - getMapForScope(scope: EnvironmentVariableScope | undefined): Map { + getVariableMap(scope: EnvironmentVariableScope | undefined): Map { const result = new Map(); - this.map.forEach((mutators, key) => { + this.map.forEach((mutators, _key) => { const filteredMutators = mutators.filter(m => filterScope(m, scope)); if (filteredMutators.length > 0) { - result.set(key, filteredMutators); + // All of these mutators are for the same variable because they are in the same scope, hence choose anyone to form a key. + result.set(filteredMutators[0].variable, filteredMutators); } }); return result; diff --git a/src/vs/platform/terminal/node/terminalEnvironment.ts b/src/vs/platform/terminal/node/terminalEnvironment.ts index 00fa1fe1364..f973081f9d6 100644 --- a/src/vs/platform/terminal/node/terminalEnvironment.ts +++ b/src/vs/platform/terminal/node/terminalEnvironment.ts @@ -259,7 +259,7 @@ function addEnvMixinPathPrefix(options: ITerminalProcessOptions, envMixin: IProc const merged = new MergedEnvironmentVariableCollection(deserialized); // Get all prepend PATH entries - const pathEntry = merged.getMapForScope({ workspaceFolder: options.workspaceFolder }).get('PATH'); + const pathEntry = merged.getVariableMap({ workspaceFolder: options.workspaceFolder }).get('PATH'); const prependToPath: string[] = []; if (pathEntry) { for (const mutator of pathEntry) { diff --git a/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts b/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts index 9e6a1bf6867..d660a69b988 100644 --- a/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts +++ b/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts @@ -70,7 +70,7 @@ export class EnvironmentVariableInfoChangesActive implements IEnvironmentVariabl private _getInfo(scope: EnvironmentVariableScope | undefined): string { const extSet: Set = new Set(); - addExtensionIdentifiers(extSet, this._collection.getMapForScope(scope).values()); + addExtensionIdentifiers(extSet, this._collection.getVariableMap(scope).values()); let message = localize('extensionEnvironmentContributionInfoActive', "The following extensions have contributed to this terminal's environment:"); message += '\n'; diff --git a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts index 50c7532145a..87b7dc1bdbe 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts @@ -438,7 +438,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce // condition, the chance is minimal plus the impact on the user is also not that great // if it happens - it's not worth adding plumbing to sync back the resolved collection. await this._extEnvironmentVariableCollection.applyToProcessEnvironment(env, { workspaceFolder }, variableResolver); - if (this._extEnvironmentVariableCollection.getMapForScope({ workspaceFolder }).size > 0) { + if (this._extEnvironmentVariableCollection.getVariableMap({ workspaceFolder }).size > 0) { this.environmentVariableInfo = this._instantiationService.createInstance(EnvironmentVariableInfoChangesActive, this._extEnvironmentVariableCollection); this._onEnvironmentVariableInfoChange.fire(this.environmentVariableInfo); } diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts index ee6dd00660e..4280f82f12c 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts @@ -34,7 +34,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ]) }] ]), undefined); - deepStrictEqual([...merged.getMapForScope(undefined).entries()], [ + deepStrictEqual([...merged.getVariableMap(undefined).entries()], [ ['A', [ { extensionIdentifier: 'ext4', type: EnvironmentVariableMutatorType.Append, value: 'a4', scope: undefined, variable: 'A' }, { extensionIdentifier: 'ext3', type: EnvironmentVariableMutatorType.Prepend, value: 'a3', scope: undefined, variable: 'A' }, @@ -67,7 +67,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ]) }] ]), undefined); - deepStrictEqual([...merged.getMapForScope(undefined).entries()], [ + deepStrictEqual([...merged.getVariableMap(undefined).entries()], [ ['A', [ { extensionIdentifier: 'ext3', type: EnvironmentVariableMutatorType.Replace, value: 'a3', scope: undefined, variable: 'A' }, { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Append, value: 'a2', scope: undefined, variable: 'A' }, diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts index 2a271c5c0c2..3033717c433 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts @@ -52,7 +52,7 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { collection.set('B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }); collection.set('C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'C' }); environmentVariableService.set('ext1', { map: collection, persistent: true }); - deepStrictEqual([...environmentVariableService.mergedCollection.getMapForScope(undefined).entries()], [ + deepStrictEqual([...environmentVariableService.mergedCollection.getVariableMap(undefined).entries()], [ ['A', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Replace, value: 'a', scope: undefined, variable: 'A' }]], ['B', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Append, value: 'b', scope: undefined, variable: 'B' }]], ['C', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Prepend, value: 'c', scope: undefined, variable: 'C' }]] @@ -61,7 +61,7 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { // Persist with old service, create a new service with the same storage service to verify restore environmentVariableService.persistCollections(); const service2: TestEnvironmentVariableService = instantiationService.createInstance(TestEnvironmentVariableService); - deepStrictEqual([...service2.mergedCollection.getMapForScope(undefined).entries()], [ + deepStrictEqual([...service2.mergedCollection.getVariableMap(undefined).entries()], [ ['A', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Replace, value: 'a', scope: undefined, variable: 'A' }]], ['B', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Append, value: 'b', scope: undefined, variable: 'B' }]], ['C', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Prepend, value: 'c', scope: undefined, variable: 'C' }]] @@ -82,7 +82,7 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { environmentVariableService.set('ext1', { map: collection1, persistent: true }); environmentVariableService.set('ext2', { map: collection2, persistent: true }); environmentVariableService.set('ext3', { map: collection3, persistent: true }); - deepStrictEqual([...environmentVariableService.mergedCollection.getMapForScope(undefined).entries()], [ + deepStrictEqual([...environmentVariableService.mergedCollection.getVariableMap(undefined).entries()], [ ['A', [ { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Replace, value: 'a2', scope: undefined, variable: 'A' }, { extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Append, value: 'a1', scope: undefined, variable: 'A' } @@ -103,7 +103,7 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { environmentVariableService.set('ext3', { map: collection3, persistent: true }); // The entries should be ordered in the order they are applied - deepStrictEqual([...environmentVariableService.mergedCollection.getMapForScope(undefined).entries()], [ + deepStrictEqual([...environmentVariableService.mergedCollection.getVariableMap(undefined).entries()], [ ['A', [ { extensionIdentifier: 'ext3', type: EnvironmentVariableMutatorType.Replace, value: 'a3', scope: undefined, variable: 'A' }, { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Prepend, value: 'a2:', scope: undefined, variable: 'A' }, From 0cdf68cc899723c75c51ffda636c1a1018bd1bd3 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Fri, 14 Apr 2023 11:21:05 +0000 Subject: [PATCH 36/68] Fix filtering --- .../common/environmentVariableCollection.ts | 5 +--- ...erminal.environmentChanges.contribution.ts | 23 ++++++++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/vs/platform/terminal/common/environmentVariableCollection.ts b/src/vs/platform/terminal/common/environmentVariableCollection.ts index 81829ed5eff..8da919bfb30 100644 --- a/src/vs/platform/terminal/common/environmentVariableCollection.ts +++ b/src/vs/platform/terminal/common/environmentVariableCollection.ts @@ -139,15 +139,12 @@ function filterScope( mutator: IExtensionOwnedEnvironmentVariableMutator, scope: EnvironmentVariableScope | undefined ): boolean { - if (!scope) { - return true; - } if (!mutator.scope) { return true; } // If a mutator is scoped to a workspace folder, only apply it if the workspace // folder matches. - if (mutator.scope.workspaceFolder && scope.workspaceFolder && mutator.scope.workspaceFolder.index === scope.workspaceFolder.index) { + if (mutator.scope.workspaceFolder && scope?.workspaceFolder && mutator.scope.workspaceFolder.index === scope.workspaceFolder.index) { return true; } return false; diff --git a/src/vs/workbench/contrib/terminalContrib/environmentChanges/browser/terminal.environmentChanges.contribution.ts b/src/vs/workbench/contrib/terminalContrib/environmentChanges/browser/terminal.environmentChanges.contribution.ts index 029c122a5df..fadbd79ae29 100644 --- a/src/vs/workbench/contrib/terminalContrib/environmentChanges/browser/terminal.environmentChanges.contribution.ts +++ b/src/vs/workbench/contrib/terminalContrib/environmentChanges/browser/terminal.environmentChanges.contribution.ts @@ -6,7 +6,7 @@ import { Schemas } from 'vs/base/common/network'; import { URI } from 'vs/base/common/uri'; import { localize } from 'vs/nls'; -import { EnvironmentVariableMutatorType, EnvironmentVariableScope, IMergedEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; +import { EnvironmentVariableMutatorType, EnvironmentVariableScope, IEnvironmentVariableMutator, IMergedEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; import { registerActiveInstanceAction } from 'vs/workbench/contrib/terminal/browser/terminalActions'; import { TerminalCommandId } from 'vs/workbench/contrib/terminal/common/terminal'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; @@ -38,11 +38,8 @@ function describeEnvironmentChanges(collection: IMergedEnvironmentVariableCollec content += `\n\n## ${localize('extension', 'Extension: {0}', ext)}`; content += '\n'; for (const [_, mutator] of coll.map.entries()) { - if (scope?.workspaceFolder) { - // Only mutators which are applicable on the relevant workspace should be shown. - if (mutator.scope?.workspaceFolder && mutator.scope.workspaceFolder.index !== scope?.workspaceFolder.index) { - continue; - } + if (filterScope(mutator, scope) === false) { + continue; } content += `\n- \`${mutatorTypeLabel(mutator.type, mutator.value, mutator.variable)}\``; } @@ -50,6 +47,20 @@ function describeEnvironmentChanges(collection: IMergedEnvironmentVariableCollec return content; } +function filterScope( + mutator: IEnvironmentVariableMutator, + scope: EnvironmentVariableScope | undefined +): boolean { + if (!mutator.scope) { + return true; + } + // Only mutators which are applicable on the relevant workspace should be shown. + if (mutator.scope.workspaceFolder && scope?.workspaceFolder && mutator.scope.workspaceFolder.index === scope.workspaceFolder.index) { + return true; + } + return false; +} + function mutatorTypeLabel(type: EnvironmentVariableMutatorType, value: string, variable: string): string { switch (type) { case EnvironmentVariableMutatorType.Prepend: return `${variable}=${value}\${env:${variable}}`; From 97469499e64dc7c5b4d8940f348da3a8c2b5d3d3 Mon Sep 17 00:00:00 2001 From: First Date: Fri, 14 Apr 2023 04:31:50 -0700 Subject: [PATCH 37/68] Undo --- .../platform/terminal/common/environmentVariableCollection.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vs/platform/terminal/common/environmentVariableCollection.ts b/src/vs/platform/terminal/common/environmentVariableCollection.ts index 8da919bfb30..536d21ec5af 100644 --- a/src/vs/platform/terminal/common/environmentVariableCollection.ts +++ b/src/vs/platform/terminal/common/environmentVariableCollection.ts @@ -59,9 +59,9 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa lowerToActualVariableNames = {}; Object.keys(env).forEach(e => lowerToActualVariableNames![e.toLowerCase()] = e); } - for (const [_, mutators] of this.getVariableMap(scope)) { + for (const [variable, mutators] of this.getVariableMap(scope)) { + const actualVariable = isWindows ? lowerToActualVariableNames![variable.toLowerCase()] || variable : variable; for (const mutator of mutators) { - const actualVariable = isWindows ? lowerToActualVariableNames![mutator.variable.toLowerCase()] || mutator.variable : mutator.variable; const value = variableResolver ? await variableResolver(mutator.value) : mutator.value; // if (mutator.timing === EnvironmentVariableMutatorTiming.AfterShellIntegration) { // const key = `VSCODE_ENV_${mutatorTypeToLabelMap.get(mutator.type)!}`; From 3b0ac4bbd0329895ba23a400b42eab6295759f2d Mon Sep 17 00:00:00 2001 From: First Date: Fri, 14 Apr 2023 04:43:01 -0700 Subject: [PATCH 38/68] Revert unncessary changes --- .../common/environmentVariableCollection.ts | 18 +++++++++--------- src/vs/server/node/remoteTerminalChannel.ts | 1 - .../terminal/browser/terminalProcessManager.ts | 4 ++-- .../common/environmentVariableService.ts | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/vs/platform/terminal/common/environmentVariableCollection.ts b/src/vs/platform/terminal/common/environmentVariableCollection.ts index 536d21ec5af..6a6ae1c6ff1 100644 --- a/src/vs/platform/terminal/common/environmentVariableCollection.ts +++ b/src/vs/platform/terminal/common/environmentVariableCollection.ts @@ -89,29 +89,29 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa const removed: Map = new Map(); // Find added - other.getVariableMap(scope).forEach((otherMutators, key) => { - const currentMutators = this.getVariableMap(scope).get(key); + other.getVariableMap(scope).forEach((otherMutators, variable) => { + const currentMutators = this.getVariableMap(scope).get(variable); const result = getMissingMutatorsFromArray(otherMutators, currentMutators); if (result) { - added.set(key, result); + added.set(variable, result); } }); // Find removed - this.getVariableMap(scope).forEach((currentMutators, key) => { - const otherMutators = other.getVariableMap(scope).get(key); + this.getVariableMap(scope).forEach((currentMutators, variable) => { + const otherMutators = other.getVariableMap(scope).get(variable); const result = getMissingMutatorsFromArray(currentMutators, otherMutators); if (result) { - removed.set(key, result); + removed.set(variable, result); } }); // Find changed - this.getVariableMap(scope).forEach((currentMutators, key) => { - const otherMutators = other.getVariableMap(scope).get(key); + this.getVariableMap(scope).forEach((currentMutators, variable) => { + const otherMutators = other.getVariableMap(scope).get(variable); const result = getChangedMutatorsFromArray(currentMutators, otherMutators); if (result) { - changed.set(key, result); + changed.set(variable, result); } }); diff --git a/src/vs/server/node/remoteTerminalChannel.ts b/src/vs/server/node/remoteTerminalChannel.ts index b34889cddec..39b6b0a8aea 100644 --- a/src/vs/server/node/remoteTerminalChannel.ts +++ b/src/vs/server/node/remoteTerminalChannel.ts @@ -240,7 +240,6 @@ export class RemoteTerminalChannel extends Disposable implements IServerChannel< const mergedCollection = new MergedEnvironmentVariableCollection(envVariableCollections); const cwdUri = typeof shellLaunchConfig.cwd === 'string' ? URI.parse(shellLaunchConfig.cwd) : shellLaunchConfig.cwd; const workspaceFolder = cwdUri ? withNullAsUndefined(activeWorkspaceFolder) : undefined; - // @karrtikr TODO: Pass workspace folder to applyToProcessEnvironment await mergedCollection.applyToProcessEnvironment(env, { workspaceFolder }, variableResolver); } diff --git a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts index 87b7dc1bdbe..feafd6bab9b 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts @@ -286,7 +286,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce }, windowsEnableConpty: this._configHelper.config.windowsEnableConpty, environmentVariableCollections: this._extEnvironmentVariableCollection?.collections ? serializeEnvironmentVariableCollections(this._extEnvironmentVariableCollection.collections) : undefined, - workspaceFolder: this._lastActiveWorkspace, + workspaceFolder: this._cwdWorkspaceFolder, }; try { newProcess = await backend.createProcess( @@ -478,7 +478,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce }, windowsEnableConpty: this._configHelper.config.windowsEnableConpty, environmentVariableCollections: this._extEnvironmentVariableCollection ? serializeEnvironmentVariableCollections(this._extEnvironmentVariableCollection.collections) : undefined, - workspaceFolder: this._lastActiveWorkspace, + workspaceFolder: this._cwdWorkspaceFolder, }; const shouldPersist = ((this._configurationService.getValue(TaskSettingId.Reconnection) && shellLaunchConfig.reconnectionProperties) || !shellLaunchConfig.isFeatureTerminal) && this._configHelper.config.enablePersistentSessions && !shellLaunchConfig.isTransient; return await backend.createProcess(shellLaunchConfig, initialCwd, cols, rows, this._configHelper.config.unicodeVersion, env, options, shouldPersist); diff --git a/src/vs/workbench/contrib/terminal/common/environmentVariableService.ts b/src/vs/workbench/contrib/terminal/common/environmentVariableService.ts index 3a27fb67d79..9f68db1d984 100644 --- a/src/vs/workbench/contrib/terminal/common/environmentVariableService.ts +++ b/src/vs/workbench/contrib/terminal/common/environmentVariableService.ts @@ -32,7 +32,7 @@ export class EnvironmentVariableService implements IEnvironmentVariableService { constructor( @IExtensionService private readonly _extensionService: IExtensionService, - @IStorageService private readonly _storageService: IStorageService, + @IStorageService private readonly _storageService: IStorageService ) { const serializedPersistedCollections = this._storageService.get(TerminalStorageKeys.EnvironmentVariableCollections, StorageScope.WORKSPACE); if (serializedPersistedCollections) { From a3d0107e07c76a849d9b77f31294af373176b821 Mon Sep 17 00:00:00 2001 From: First Date: Fri, 14 Apr 2023 13:41:23 -0700 Subject: [PATCH 39/68] Remove console --- src/vs/workbench/api/common/extHostTerminalService.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index 1236cdc8a3f..9f7d9a6c403 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -902,9 +902,6 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect } private _setIfDiffers(variable: string, mutator: vscode.EnvironmentVariableMutator): void { - if (variable === 'VIRTUAL_ENV') { - console.log('Set variable to mutator', JSON.stringify(mutator)); - } 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) { @@ -922,7 +919,7 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect } private getKey(variable: string, scope: vscode.EnvironmentVariableScope | undefined) { - return variable.concat(this.getWorkspaceKey(scope?.workspaceFolder)); + return `${variable}:::${this.getWorkspaceKey(scope?.workspaceFolder)}`; } private getWorkspaceKey(workspaceFolder: vscode.WorkspaceFolder | undefined): string { From 028ebcbba22c7760e3740333a2de26a2b83d5612 Mon Sep 17 00:00:00 2001 From: First Date: Fri, 14 Apr 2023 13:52:42 -0700 Subject: [PATCH 40/68] switch key --- src/vs/workbench/api/common/extHostTerminalService.ts | 7 ++++--- .../contrib/terminal/browser/environmentVariableInfo.ts | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index 9f7d9a6c403..a2ba244609d 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -919,11 +919,12 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect } private getKey(variable: string, scope: vscode.EnvironmentVariableScope | undefined) { - return `${variable}:::${this.getWorkspaceKey(scope?.workspaceFolder)}`; + const workspaceKey = this.getWorkspaceKey(scope?.workspaceFolder); + return workspaceKey ? `${variable}:::${workspaceKey}` : variable; } - private getWorkspaceKey(workspaceFolder: vscode.WorkspaceFolder | undefined): string { - return workspaceFolder ? workspaceFolder.uri.toString() : ''; + 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 { diff --git a/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts b/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts index d660a69b988..66e0ad68d4b 100644 --- a/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts +++ b/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts @@ -47,7 +47,7 @@ export class EnvironmentVariableInfoStale implements IEnvironmentVariableInfo { }]; } - getStatus(_: EnvironmentVariableScope | undefined): ITerminalStatus { + getStatus(): ITerminalStatus { return { id: TerminalStatus.RelaunchNeeded, severity: Severity.Warning, From fcde0a793b6eb26afe7e8fef7494b88abd25a530 Mon Sep 17 00:00:00 2001 From: First Date: Fri, 14 Apr 2023 17:15:31 -0700 Subject: [PATCH 41/68] Add clear propsoed api --- .../workbench/api/common/extHostTerminalService.ts | 12 ++++++++++-- .../vscode.proposed.envCollectionWorkspace.d.ts | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index a2ba244609d..b5a6343503c 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -941,8 +941,16 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect this._onDidChangeCollection.fire(); } - clear(): void { - this.map.clear(); + 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); + } + } + } else { + this.map.clear(); + } this._onDidChangeCollection.fire(); } } diff --git a/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts b/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts index cdabc7764e5..202782232fb 100644 --- a/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts +++ b/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts @@ -19,12 +19,12 @@ declare module 'vscode' { 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; } export type EnvironmentVariableScope = { /** - * The workspace folder to which this environment variable collection applies to. - * If unspecified, the collection applies to all workspace folders. + * The workspace folder to which this collection applies to. If unspecified, collection applies to all workspace folders. */ workspaceFolder?: WorkspaceFolder; }; From 1fc1fb1f90b7992a03a48a2e1d088dfae72e8b7c Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Sat, 15 Apr 2023 17:26:19 +0000 Subject: [PATCH 42/68] Serialize and deserialize description --- .../terminal/common/environmentVariable.ts | 20 +++++++++- .../common/environmentVariableCollection.ts | 40 ++++++++++++++++++- .../common/environmentVariableShared.ts | 16 ++++++-- src/vs/server/node/remoteTerminalChannel.ts | 6 +-- .../api/browser/mainThreadTerminalService.ts | 9 +++-- .../workbench/api/common/extHost.protocol.ts | 4 +- .../api/common/extHostTerminalService.ts | 18 +++++++-- .../browser/environmentVariableInfo.ts | 17 ++++++-- .../browser/terminalProcessManager.ts | 2 +- .../common/environmentVariableService.ts | 11 +++-- .../terminal/common/remoteTerminalChannel.ts | 8 ++-- ...scode.proposed.envCollectionWorkspace.d.ts | 6 +++ 12 files changed, 126 insertions(+), 31 deletions(-) diff --git a/src/vs/platform/terminal/common/environmentVariable.ts b/src/vs/platform/terminal/common/environmentVariable.ts index ce731ff8b71..9567b49aa30 100644 --- a/src/vs/platform/terminal/common/environmentVariable.ts +++ b/src/vs/platform/terminal/common/environmentVariable.ts @@ -24,19 +24,30 @@ export interface IEnvironmentVariableMutator { // readonly timing?: EnvironmentVariableMutatorTiming; } +export interface IEnvironmentDescriptionMutator { + readonly description: string | undefined; + readonly scope: EnvironmentVariableScope | undefined; +} + export type EnvironmentVariableScope = { workspaceFolder?: IWorkspaceFolderData; }; export interface IEnvironmentVariableCollection { readonly map: ReadonlyMap; + readonly descriptionMap: ReadonlyMap; } /** [variable, mutator] */ export type ISerializableEnvironmentVariableCollection = [string, IEnvironmentVariableMutator][]; -/** [extension, collection] */ -export type ISerializableEnvironmentVariableCollections = [string, ISerializableEnvironmentVariableCollection][]; +export type ISerializableEnvironmentDescriptionMap = [string, IEnvironmentDescriptionMutator][]; +export interface IExtensionOwnedEnvironmentDescriptionMutator extends IEnvironmentDescriptionMutator { + readonly extensionIdentifier: string; +} + +/** [extension, collection, description] */ +export type ISerializableEnvironmentVariableCollections = [string, ISerializableEnvironmentVariableCollection, ISerializableEnvironmentDescriptionMap][]; export interface IExtensionOwnedEnvironmentVariableMutator extends IEnvironmentVariableMutator { readonly extensionIdentifier: string; @@ -61,6 +72,11 @@ export interface IMergedEnvironmentVariableCollection { * @param scope The scope to get the variable map for. If undefined, the global scope is used. */ getVariableMap(scope: EnvironmentVariableScope | undefined): Map; + /** + * Gets the description map for a given scope. + * @param scope The scope to get the description map for. If undefined, the global scope is used. + */ + getDescriptionMap(scope: EnvironmentVariableScope | undefined): Map; /** * Applies this collection to a process environment. * @param variableResolver An optional function to use to resolve variables within the diff --git a/src/vs/platform/terminal/common/environmentVariableCollection.ts b/src/vs/platform/terminal/common/environmentVariableCollection.ts index 6a6ae1c6ff1..44f243953eb 100644 --- a/src/vs/platform/terminal/common/environmentVariableCollection.ts +++ b/src/vs/platform/terminal/common/environmentVariableCollection.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { IProcessEnvironment, isWindows } from 'vs/base/common/platform'; -import { EnvironmentVariableMutatorType, EnvironmentVariableScope, IEnvironmentVariableCollection, IExtensionOwnedEnvironmentVariableMutator, IMergedEnvironmentVariableCollection, IMergedEnvironmentVariableCollectionDiff } from 'vs/platform/terminal/common/environmentVariable'; +import { EnvironmentVariableMutatorType, EnvironmentVariableScope, IEnvironmentVariableCollection, IExtensionOwnedEnvironmentDescriptionMutator, IExtensionOwnedEnvironmentVariableMutator, IMergedEnvironmentVariableCollection, IMergedEnvironmentVariableCollectionDiff } from 'vs/platform/terminal/common/environmentVariable'; type VariableResolver = (str: string) => Promise; @@ -16,11 +16,13 @@ type VariableResolver = (str: string) => Promise; export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVariableCollection { private readonly map: Map = new Map(); + private readonly descriptionMap: Map = new Map(); constructor( readonly collections: ReadonlyMap, ) { collections.forEach((collection, extensionIdentifier) => { + this.populateDescriptionMap(collection, extensionIdentifier); const it = collection.map.entries(); let next = it.next(); while (!next.done) { @@ -133,10 +135,44 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa }); return result; } + + getDescriptionMap(scope: EnvironmentVariableScope | undefined): Map { + const result = new Map(); + this.descriptionMap.forEach((mutators, _key) => { + const filteredMutators = mutators.filter(m => filterScope(m, scope)); + if (filteredMutators.length > 0) { + // There should be exactly one description per extension per scope. + result.set(filteredMutators[0].extensionIdentifier, filteredMutators[0].description); + } + }); + return result; + } + + private populateDescriptionMap(collection: IEnvironmentVariableCollection, extensionIdentifier: string): void { + const it = collection.descriptionMap.entries(); + let next = it.next(); + while (!next.done) { + const mutator = next.value[1]; + const key = next.value[0]; + let entry = this.descriptionMap.get(key); + if (!entry) { + entry = []; + this.descriptionMap.set(key, entry); + } + entry.push({ + extensionIdentifier, + scope: mutator.scope, + description: mutator.description + }); + + next = it.next(); + } + + } } function filterScope( - mutator: IExtensionOwnedEnvironmentVariableMutator, + mutator: IExtensionOwnedEnvironmentVariableMutator | IExtensionOwnedEnvironmentDescriptionMutator, scope: EnvironmentVariableScope | undefined ): boolean { if (!mutator.scope) { diff --git a/src/vs/platform/terminal/common/environmentVariableShared.ts b/src/vs/platform/terminal/common/environmentVariableShared.ts index 75874739537..c4b7bfda0b4 100644 --- a/src/vs/platform/terminal/common/environmentVariableShared.ts +++ b/src/vs/platform/terminal/common/environmentVariableShared.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { IEnvironmentVariableCollection, IEnvironmentVariableMutator, ISerializableEnvironmentVariableCollection, ISerializableEnvironmentVariableCollections } from 'vs/platform/terminal/common/environmentVariable'; +import { IEnvironmentDescriptionMutator, IEnvironmentVariableCollection, IEnvironmentVariableMutator, ISerializableEnvironmentDescriptionMap as ISerializableEnvironmentDescriptionMap, ISerializableEnvironmentVariableCollection, ISerializableEnvironmentVariableCollections } from 'vs/platform/terminal/common/environmentVariable'; // This file is shared between the renderer and extension host @@ -11,15 +11,25 @@ export function serializeEnvironmentVariableCollection(collection: ReadonlyMap): ISerializableEnvironmentDescriptionMap { + return [...descriptionMap.entries()]; +} + export function deserializeEnvironmentVariableCollection( serializedCollection: ISerializableEnvironmentVariableCollection ): Map { return new Map(serializedCollection); } +export function deserializeEnvironmentDescriptionMap( + serializableEnvironmentDescription: ISerializableEnvironmentDescriptionMap +): Map { + return new Map(serializableEnvironmentDescription); +} + export function serializeEnvironmentVariableCollections(collections: ReadonlyMap): ISerializableEnvironmentVariableCollections { return Array.from(collections.entries()).map(e => { - return [e[0], serializeEnvironmentVariableCollection(e[1].map)]; + return [e[0], serializeEnvironmentVariableCollection(e[1].map), serializeEnvironmentDescriptionMap(e[1].descriptionMap)]; }); } @@ -27,6 +37,6 @@ export function deserializeEnvironmentVariableCollections( serializedCollection: ISerializableEnvironmentVariableCollections ): Map { return new Map(serializedCollection.map(e => { - return [e[0], { map: deserializeEnvironmentVariableCollection(e[1]) }]; + return [e[0], { map: deserializeEnvironmentVariableCollection(e[1]), descriptionMap: deserializeEnvironmentDescriptionMap(e[2]) }]; })); } diff --git a/src/vs/server/node/remoteTerminalChannel.ts b/src/vs/server/node/remoteTerminalChannel.ts index 39b6b0a8aea..3ca99ecbfdf 100644 --- a/src/vs/server/node/remoteTerminalChannel.ts +++ b/src/vs/server/node/remoteTerminalChannel.ts @@ -22,7 +22,7 @@ import { createURITransformer } from 'vs/workbench/api/node/uriTransformer'; import { CLIServerBase, ICommandsExecuter } from 'vs/workbench/api/node/extHostCLIServer'; import { IEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; import { MergedEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableCollection'; -import { deserializeEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableShared'; +import { deserializeEnvironmentDescriptionMap, deserializeEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableShared'; import { ICreateTerminalProcessArguments, ICreateTerminalProcessResult, IWorkspaceFolderData } from 'vs/workbench/contrib/terminal/common/remoteTerminalChannel'; import * as terminalEnvironment from 'vs/workbench/contrib/terminal/common/terminalEnvironment'; import { AbstractVariableResolverService } from 'vs/workbench/services/configurationResolver/common/variableResolver'; @@ -233,8 +233,8 @@ export class RemoteTerminalChannel extends Disposable implements IServerChannel< // Apply extension environment variable collections to the environment if (!shellLaunchConfig.strictEnv) { const entries: [string, IEnvironmentVariableCollection][] = []; - for (const [k, v] of args.envVariableCollections) { - entries.push([k, { map: deserializeEnvironmentVariableCollection(v) }]); + for (const [k, v, d] of args.envVariableCollections) { + entries.push([k, { map: deserializeEnvironmentVariableCollection(v), descriptionMap: deserializeEnvironmentDescriptionMap(d) }]); } const envVariableCollections = new Map(entries); const mergedCollection = new MergedEnvironmentVariableCollection(envVariableCollections); diff --git a/src/vs/workbench/api/browser/mainThreadTerminalService.ts b/src/vs/workbench/api/browser/mainThreadTerminalService.ts index 93d4cd269d7..f43a403ff42 100644 --- a/src/vs/workbench/api/browser/mainThreadTerminalService.ts +++ b/src/vs/workbench/api/browser/mainThreadTerminalService.ts @@ -15,7 +15,7 @@ import { TerminalDataBufferer } from 'vs/platform/terminal/common/terminalDataBu import { ITerminalEditorService, ITerminalExternalLinkProvider, ITerminalGroupService, ITerminalInstance, ITerminalLink, ITerminalService } from 'vs/workbench/contrib/terminal/browser/terminal'; import { TerminalProcessExtHostProxy } from 'vs/workbench/contrib/terminal/browser/terminalProcessExtHostProxy'; import { IEnvironmentVariableService } from 'vs/workbench/contrib/terminal/common/environmentVariable'; -import { deserializeEnvironmentVariableCollection, serializeEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableShared'; +import { deserializeEnvironmentDescriptionMap, deserializeEnvironmentVariableCollection, serializeEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableShared'; import { IStartExtensionTerminalRequest, ITerminalProcessExtHostProxy, ITerminalProfileResolverService, ITerminalProfileService } from 'vs/workbench/contrib/terminal/common/terminal'; import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService'; import { withNullAsUndefined } from 'vs/base/common/types'; @@ -25,7 +25,7 @@ import { Promises } from 'vs/base/common/async'; import { CancellationToken } from 'vs/base/common/cancellation'; import { ITerminalCommand } from 'vs/platform/terminal/common/capabilities/capabilities'; import { TerminalQuickFixType } from 'vs/workbench/api/common/extHostTypes'; -import { ISerializableEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; +import { ISerializableEnvironmentDescriptionMap, ISerializableEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; import { ITerminalLinkProviderService } from 'vs/workbench/contrib/terminalContrib/links/browser/links'; import { ITerminalQuickFixService, ITerminalQuickFixOptions, ITerminalQuickFix } from 'vs/workbench/contrib/terminalContrib/quickFix/browser/quickFix'; @@ -400,11 +400,12 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape return terminal; } - $setEnvironmentVariableCollection(extensionIdentifier: string, persistent: boolean, collection: ISerializableEnvironmentVariableCollection | undefined): void { + $setEnvironmentVariableCollection(extensionIdentifier: string, persistent: boolean, collection: ISerializableEnvironmentVariableCollection | undefined, descriptionMap: ISerializableEnvironmentDescriptionMap): void { if (collection) { const translatedCollection = { persistent, - map: deserializeEnvironmentVariableCollection(collection) + map: deserializeEnvironmentVariableCollection(collection), + descriptionMap: deserializeEnvironmentDescriptionMap(descriptionMap) }; this._environmentVariableService.set(extensionIdentifier, translatedCollection); } else { diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index 09355a18613..e81493b1a94 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -41,7 +41,7 @@ import * as quickInput from 'vs/platform/quickinput/common/quickInput'; import { IRemoteConnectionData, TunnelDescription } from 'vs/platform/remote/common/remoteAuthorityResolver'; import { ClassifiedEvent, IGDPRProperty, OmitMetadata, StrictPropertyCheck } from 'vs/platform/telemetry/common/gdprTypings'; import { TelemetryLevel } from 'vs/platform/telemetry/common/telemetry'; -import { ISerializableEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; +import { ISerializableEnvironmentDescriptionMap, ISerializableEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; import { ICreateContributedTerminalProfileOptions, IProcessProperty, IShellLaunchConfigDto, ITerminalEnvironment, ITerminalLaunchError, ITerminalProfile, TerminalExitReason, TerminalLocation } from 'vs/platform/terminal/common/terminal'; import { ProvidedPortAttributes, TunnelCreationOptions, TunnelOptions, TunnelPrivacyId, TunnelProviderFeatures } from 'vs/platform/tunnel/common/tunnel'; import { EditSessionIdentityMatch } from 'vs/platform/workspace/common/editSessions'; @@ -491,7 +491,7 @@ export interface MainThreadTerminalServiceShape extends IDisposable { $unregisterProfileProvider(id: string): void; $registerQuickFixProvider(id: string, extensionIdentifier: string): void; $unregisterQuickFixProvider(id: string): void; - $setEnvironmentVariableCollection(extensionIdentifier: string, persistent: boolean, collection: ISerializableEnvironmentVariableCollection | undefined): void; + $setEnvironmentVariableCollection(extensionIdentifier: string, persistent: boolean, collection: ISerializableEnvironmentVariableCollection | undefined, descriptionMap: ISerializableEnvironmentDescriptionMap): void; // Process $sendProcessData(terminalId: number, data: string): void; diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index b5a6343503c..160ffc2c7f1 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -14,10 +14,10 @@ import { Disposable as VSCodeDisposable, EnvironmentVariableMutatorType, Termina import { IExtensionDescription } from 'vs/platform/extensions/common/extensions'; import { localize } from 'vs/nls'; import { NotSupportedError } from 'vs/base/common/errors'; -import { serializeEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableShared'; +import { serializeEnvironmentDescriptionMap, serializeEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableShared'; import { CancellationTokenSource } from 'vs/base/common/cancellation'; import { generateUuid } from 'vs/base/common/uuid'; -import { IEnvironmentVariableMutator, ISerializableEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; +import { IEnvironmentDescriptionMutator, IEnvironmentVariableMutator, ISerializableEnvironmentDescriptionMap, ISerializableEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; import { ICreateContributedTerminalProfileOptions, IProcessReadyEvent, IShellLaunchConfigDto, ITerminalChildProcess, ITerminalLaunchError, ITerminalProfile, TerminalIcon, TerminalLocation, IProcessProperty, ProcessPropertyType, IProcessPropertyMap } from 'vs/platform/terminal/common/terminal'; import { TerminalDataBufferer } from 'vs/platform/terminal/common/terminalDataBuffering'; import { ThemeColor } from 'vs/base/common/themables'; @@ -834,7 +834,8 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I private _syncEnvironmentVariableCollection(extensionIdentifier: string, collection: EnvironmentVariableCollection): void { const serialized = serializeEnvironmentVariableCollection(collection.map); - this._proxy.$setEnvironmentVariableCollection(extensionIdentifier, collection.persistent, serialized.length === 0 ? undefined : serialized); + const serializedDescription = serializeEnvironmentDescriptionMap(collection.descriptionMap); + this._proxy.$setEnvironmentVariableCollection(extensionIdentifier, collection.persistent, serialized.length === 0 ? undefined : serialized, serializedDescription); } public $initEnvironmentVariableCollections(collections: [string, ISerializableEnvironmentVariableCollection][]): void { @@ -868,6 +869,7 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollection { readonly map: Map = new Map(); + readonly descriptionMap: Map = new Map(); private _persistent: boolean = true; public get persistent(): boolean { return this._persistent; } @@ -953,6 +955,16 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect } this._onDidChangeCollection.fire(); } + + setDescription(description: string | undefined, scope?: vscode.EnvironmentVariableScope): void { + const key = this.getKey('', scope); + const current = this.descriptionMap.get(key); + if (!current || current.description !== description) { + const value: IEnvironmentDescriptionMutator = { description, scope }; + this.descriptionMap.set(key, value); + this._onDidChangeCollection.fire(); + } + } } export class WorkerExtHostTerminalService extends BaseExtHostTerminalService { diff --git a/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts b/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts index 66e0ad68d4b..242e6c16ffd 100644 --- a/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts +++ b/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts @@ -20,12 +20,13 @@ export class EnvironmentVariableInfoStale implements IEnvironmentVariableInfo { constructor( private readonly _diff: IMergedEnvironmentVariableCollectionDiff, private readonly _terminalId: number, + private readonly _collection: IMergedEnvironmentVariableCollection, @ITerminalService private readonly _terminalService: ITerminalService, @IExtensionService private readonly _extensionService: IExtensionService ) { } - private _getInfo(): string { + private _getInfo(scope: EnvironmentVariableScope | undefined): string { const extSet: Set = new Set(); addExtensionIdentifiers(extSet, this._diff.added.values()); addExtensionIdentifiers(extSet, this._diff.removed.values()); @@ -33,8 +34,13 @@ export class EnvironmentVariableInfoStale implements IEnvironmentVariableInfo { let message = localize('extensionEnvironmentContributionInfoStale', "The following extensions want to relaunch the terminal to contribute to its environment:"); message += '\n'; + const descriptionMap = this._collection.getDescriptionMap(scope); for (const ext of extSet) { message += `\n- \`${getExtensionName(ext, this._extensionService)}\``; + const description = descriptionMap.get(ext); + if (description) { + message += `: ${description}`; + } } return message; } @@ -47,12 +53,12 @@ export class EnvironmentVariableInfoStale implements IEnvironmentVariableInfo { }]; } - getStatus(): ITerminalStatus { + getStatus(scope: EnvironmentVariableScope | undefined): ITerminalStatus { return { id: TerminalStatus.RelaunchNeeded, severity: Severity.Warning, icon: Codicon.warning, - tooltip: this._getInfo(), + tooltip: this._getInfo(scope), hoverActions: this._getActions() }; } @@ -74,8 +80,13 @@ export class EnvironmentVariableInfoChangesActive implements IEnvironmentVariabl let message = localize('extensionEnvironmentContributionInfoActive', "The following extensions have contributed to this terminal's environment:"); message += '\n'; + const descriptionMap = this._collection.getDescriptionMap(scope); for (const ext of extSet) { message += `\n- \`${getExtensionName(ext, this._extensionService)}\``; + const description = descriptionMap.get(ext); + if (description) { + message += `: ${description}`; + } } return message; } diff --git a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts index feafd6bab9b..c7fed8fa83f 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts @@ -663,7 +663,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce } return; } - this.environmentVariableInfo = this._instantiationService.createInstance(EnvironmentVariableInfoStale, diff, this._instanceId); + this.environmentVariableInfo = this._instantiationService.createInstance(EnvironmentVariableInfoStale, diff, this._instanceId, newCollection); this._onEnvironmentVariableInfoChange.fire(this.environmentVariableInfo); } } diff --git a/src/vs/workbench/contrib/terminal/common/environmentVariableService.ts b/src/vs/workbench/contrib/terminal/common/environmentVariableService.ts index 9f68db1d984..cd1c411b3a2 100644 --- a/src/vs/workbench/contrib/terminal/common/environmentVariableService.ts +++ b/src/vs/workbench/contrib/terminal/common/environmentVariableService.ts @@ -8,14 +8,15 @@ import { debounce, throttle } from 'vs/base/common/decorators'; import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage'; import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions'; import { MergedEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableCollection'; -import { deserializeEnvironmentVariableCollection, serializeEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableShared'; +import { deserializeEnvironmentDescriptionMap, deserializeEnvironmentVariableCollection, serializeEnvironmentDescriptionMap, serializeEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableShared'; import { IEnvironmentVariableCollectionWithPersistence, IEnvironmentVariableService } from 'vs/workbench/contrib/terminal/common/environmentVariable'; import { TerminalStorageKeys } from 'vs/workbench/contrib/terminal/common/terminalStorageKeys'; -import { IMergedEnvironmentVariableCollection, ISerializableEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; +import { IMergedEnvironmentVariableCollection, ISerializableEnvironmentDescriptionMap, ISerializableEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; interface ISerializableExtensionEnvironmentVariableCollection { extensionIdentifier: string; collection: ISerializableEnvironmentVariableCollection; + description: ISerializableEnvironmentDescriptionMap; } /** @@ -39,7 +40,8 @@ export class EnvironmentVariableService implements IEnvironmentVariableService { const collectionsJson: ISerializableExtensionEnvironmentVariableCollection[] = JSON.parse(serializedPersistedCollections); collectionsJson.forEach(c => this.collections.set(c.extensionIdentifier, { persistent: true, - map: deserializeEnvironmentVariableCollection(c.collection) + map: deserializeEnvironmentVariableCollection(c.collection), + descriptionMap: deserializeEnvironmentDescriptionMap(c.description) })); // Asynchronously invalidate collections where extensions have been uninstalled, this is @@ -80,7 +82,8 @@ export class EnvironmentVariableService implements IEnvironmentVariableService { if (collection.persistent) { collectionsJson.push({ extensionIdentifier, - collection: serializeEnvironmentVariableCollection(this.collections.get(extensionIdentifier)!.map) + collection: serializeEnvironmentVariableCollection(this.collections.get(extensionIdentifier)!.map), + description: serializeEnvironmentDescriptionMap(collection.descriptionMap) }); } }); diff --git a/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts b/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts index f725cd971b9..5b128c3361d 100644 --- a/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts +++ b/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts @@ -11,7 +11,7 @@ import { IWorkbenchConfigurationService } from 'vs/workbench/services/configurat import { ILogService } from 'vs/platform/log/common/log'; import { IRemoteAuthorityResolverService } from 'vs/platform/remote/common/remoteAuthorityResolver'; import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; -import { serializeEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableShared'; +import { serializeEnvironmentDescriptionMap, serializeEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableShared'; import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver'; import { SideBySideEditor, EditorResourceAccessor } from 'vs/workbench/common/editor'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; @@ -23,11 +23,11 @@ import { IGetTerminalLayoutInfoArgs, IProcessDetails, ISetTerminalLayoutInfoArgs import { IProcessEnvironment, OperatingSystem } from 'vs/base/common/platform'; import { ICompleteTerminalConfiguration } from 'vs/workbench/contrib/terminal/common/terminal'; import { IPtyHostProcessReplayEvent } from 'vs/platform/terminal/common/capabilities/capabilities'; -import { ISerializableEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; +import { ISerializableEnvironmentDescriptionMap as ISerializableEnvironmentDescriptionMap, ISerializableEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; export const REMOTE_TERMINAL_CHANNEL_NAME = 'remoteterminal'; -export type ITerminalEnvironmentVariableCollections = [string, ISerializableEnvironmentVariableCollection][]; +export type ITerminalEnvironmentVariableCollections = [string, ISerializableEnvironmentVariableCollection, ISerializableEnvironmentDescriptionMap][]; export interface IWorkspaceFolderData { uri: UriComponents; @@ -152,7 +152,7 @@ export class RemoteTerminalChannelClient implements IPtyHostController { const envVariableCollections: ITerminalEnvironmentVariableCollections = []; for (const [k, v] of this._environmentVariableService.collections.entries()) { - envVariableCollections.push([k, serializeEnvironmentVariableCollection(v.map)]); + envVariableCollections.push([k, serializeEnvironmentVariableCollection(v.map), serializeEnvironmentDescriptionMap(v.descriptionMap)]); } const resolverResult = await this._remoteAuthorityResolverService.resolveAuthority(this._remoteAuthority); diff --git a/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts b/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts index 202782232fb..9c7ce4fbf05 100644 --- a/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts +++ b/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts @@ -14,6 +14,12 @@ declare module 'vscode' { } export interface EnvironmentVariableCollection extends Iterable<[variable: string, mutator: EnvironmentVariableMutator]> { + /** + * 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. + */ + setDescription(description: string | 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; From baca51cfc18fd75b6d41908f3e8f85b99c1770e9 Mon Sep 17 00:00:00 2001 From: First Date: Sun, 16 Apr 2023 01:00:03 -0700 Subject: [PATCH 43/68] Descrp 2 --- src/vs/workbench/api/common/extHostTerminalService.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index 160ffc2c7f1..824349947ab 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -950,8 +950,10 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect this.map.delete(key); } } + this.clearDescription(scope); } else { this.map.clear(); + this.descriptionMap.clear(); } this._onDidChangeCollection.fire(); } @@ -965,6 +967,11 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect this._onDidChangeCollection.fire(); } } + + private clearDescription(scope?: vscode.EnvironmentVariableScope): void { + const key = this.getKey('', scope); + this.descriptionMap.delete(key); + } } export class WorkerExtHostTerminalService extends BaseExtHostTerminalService { From ecb6c8a5acbc3b3739a3d05583ef6fc71f4ae798 Mon Sep 17 00:00:00 2001 From: First Date: Sun, 16 Apr 2023 01:39:08 -0700 Subject: [PATCH 44/68] Fall back to last active workspace if cwd is not speicified --- .../contrib/terminal/browser/terminalProcessManager.ts | 3 ++- .../terminal/electron-sandbox/localTerminalBackend.ts | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts index c7fed8fa83f..478ee622006 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts @@ -174,6 +174,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce } const activeWorkspaceRootUri = this._historyService.getLastActiveWorkspaceRoot(); this._lastActiveWorkspace = activeWorkspaceRootUri ? withNullAsUndefined(this._workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri)) : undefined; + this._cwdWorkspaceFolder = this._cwdWorkspaceFolder ?? this._lastActiveWorkspace; // fallback to last active workspace if cwd is not available or it is not in workspace if (environmentVariableCollections) { this._extEnvironmentVariableCollection = new MergedEnvironmentVariableCollection(environmentVariableCollections); @@ -414,7 +415,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce // Fetch any extension environment additions and apply them private async _resolveEnvironment(backend: ITerminalBackend, variableResolver: terminalEnvironment.VariableResolver | undefined, shellLaunchConfig: IShellLaunchConfig): Promise { const cwdUri = typeof shellLaunchConfig.cwd === 'string' ? URI.parse(shellLaunchConfig.cwd) : shellLaunchConfig.cwd; - const workspaceFolder = cwdUri ? withNullAsUndefined(this._workspaceContextService.getWorkspaceFolder(cwdUri)) : undefined; + const workspaceFolder = cwdUri ? withNullAsUndefined(this._workspaceContextService.getWorkspaceFolder(cwdUri)) : this._lastActiveWorkspace; const platformKey = isWindows ? 'windows' : (isMacintosh ? 'osx' : 'linux'); const envFromConfigValue = this._configurationService.getValue(`terminal.integrated.env.${platformKey}`); this._configHelper.showRecommendations(shellLaunchConfig); diff --git a/src/vs/workbench/contrib/terminal/electron-sandbox/localTerminalBackend.ts b/src/vs/workbench/contrib/terminal/electron-sandbox/localTerminalBackend.ts index 0e4091bd2b2..f9043b7e832 100644 --- a/src/vs/workbench/contrib/terminal/electron-sandbox/localTerminalBackend.ts +++ b/src/vs/workbench/contrib/terminal/electron-sandbox/localTerminalBackend.ts @@ -263,7 +263,11 @@ class LocalTerminalBackend extends BaseTerminalBackend implements ITerminalBacke const env = await terminalEnvironment.createTerminalEnvironment(shellLaunchConfig, envFromConfigValue, variableResolver, this._productService.version, this._configurationService.getValue(TerminalSettingId.DetectLocale), baseEnv); if (!shellLaunchConfig.strictEnv && !shellLaunchConfig.hideFromUser) { const cwdUri = typeof shellLaunchConfig.cwd === 'string' ? URI.parse(shellLaunchConfig.cwd) : shellLaunchConfig.cwd; - const workspaceFolder = cwdUri ? withNullAsUndefined(this._workspaceContextService.getWorkspaceFolder(cwdUri)) : undefined; + let workspaceFolder = cwdUri ? withNullAsUndefined(this._workspaceContextService.getWorkspaceFolder(cwdUri)) : undefined; + if (!workspaceFolder) { + const activeWorkspaceRootUri = this._historyService.getLastActiveWorkspaceRoot(); + workspaceFolder = activeWorkspaceRootUri ? withNullAsUndefined(this._workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri)) : undefined; + } await this._environmentVariableService.mergedCollection.applyToProcessEnvironment(env, { workspaceFolder }, variableResolver); } return env; From b9ec13d3d2b2642aa216ca7730346b1bd494de9d Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Sun, 16 Apr 2023 08:44:18 +0000 Subject: [PATCH 45/68] Revert "Serialize and deserialize description" --- .../terminal/common/environmentVariable.ts | 20 +--------- .../common/environmentVariableCollection.ts | 40 +------------------ .../common/environmentVariableShared.ts | 16 ++------ src/vs/server/node/remoteTerminalChannel.ts | 6 +-- .../api/browser/mainThreadTerminalService.ts | 9 ++--- .../workbench/api/common/extHost.protocol.ts | 4 +- .../api/common/extHostTerminalService.ts | 25 ++---------- .../browser/environmentVariableInfo.ts | 17 ++------ .../browser/terminalProcessManager.ts | 2 +- .../common/environmentVariableService.ts | 11 ++--- .../terminal/common/remoteTerminalChannel.ts | 8 ++-- ...scode.proposed.envCollectionWorkspace.d.ts | 6 --- 12 files changed, 31 insertions(+), 133 deletions(-) diff --git a/src/vs/platform/terminal/common/environmentVariable.ts b/src/vs/platform/terminal/common/environmentVariable.ts index 9567b49aa30..ce731ff8b71 100644 --- a/src/vs/platform/terminal/common/environmentVariable.ts +++ b/src/vs/platform/terminal/common/environmentVariable.ts @@ -24,30 +24,19 @@ export interface IEnvironmentVariableMutator { // readonly timing?: EnvironmentVariableMutatorTiming; } -export interface IEnvironmentDescriptionMutator { - readonly description: string | undefined; - readonly scope: EnvironmentVariableScope | undefined; -} - export type EnvironmentVariableScope = { workspaceFolder?: IWorkspaceFolderData; }; export interface IEnvironmentVariableCollection { readonly map: ReadonlyMap; - readonly descriptionMap: ReadonlyMap; } /** [variable, mutator] */ export type ISerializableEnvironmentVariableCollection = [string, IEnvironmentVariableMutator][]; -export type ISerializableEnvironmentDescriptionMap = [string, IEnvironmentDescriptionMutator][]; -export interface IExtensionOwnedEnvironmentDescriptionMutator extends IEnvironmentDescriptionMutator { - readonly extensionIdentifier: string; -} - -/** [extension, collection, description] */ -export type ISerializableEnvironmentVariableCollections = [string, ISerializableEnvironmentVariableCollection, ISerializableEnvironmentDescriptionMap][]; +/** [extension, collection] */ +export type ISerializableEnvironmentVariableCollections = [string, ISerializableEnvironmentVariableCollection][]; export interface IExtensionOwnedEnvironmentVariableMutator extends IEnvironmentVariableMutator { readonly extensionIdentifier: string; @@ -72,11 +61,6 @@ export interface IMergedEnvironmentVariableCollection { * @param scope The scope to get the variable map for. If undefined, the global scope is used. */ getVariableMap(scope: EnvironmentVariableScope | undefined): Map; - /** - * Gets the description map for a given scope. - * @param scope The scope to get the description map for. If undefined, the global scope is used. - */ - getDescriptionMap(scope: EnvironmentVariableScope | undefined): Map; /** * Applies this collection to a process environment. * @param variableResolver An optional function to use to resolve variables within the diff --git a/src/vs/platform/terminal/common/environmentVariableCollection.ts b/src/vs/platform/terminal/common/environmentVariableCollection.ts index 44f243953eb..6a6ae1c6ff1 100644 --- a/src/vs/platform/terminal/common/environmentVariableCollection.ts +++ b/src/vs/platform/terminal/common/environmentVariableCollection.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { IProcessEnvironment, isWindows } from 'vs/base/common/platform'; -import { EnvironmentVariableMutatorType, EnvironmentVariableScope, IEnvironmentVariableCollection, IExtensionOwnedEnvironmentDescriptionMutator, IExtensionOwnedEnvironmentVariableMutator, IMergedEnvironmentVariableCollection, IMergedEnvironmentVariableCollectionDiff } from 'vs/platform/terminal/common/environmentVariable'; +import { EnvironmentVariableMutatorType, EnvironmentVariableScope, IEnvironmentVariableCollection, IExtensionOwnedEnvironmentVariableMutator, IMergedEnvironmentVariableCollection, IMergedEnvironmentVariableCollectionDiff } from 'vs/platform/terminal/common/environmentVariable'; type VariableResolver = (str: string) => Promise; @@ -16,13 +16,11 @@ type VariableResolver = (str: string) => Promise; export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVariableCollection { private readonly map: Map = new Map(); - private readonly descriptionMap: Map = new Map(); constructor( readonly collections: ReadonlyMap, ) { collections.forEach((collection, extensionIdentifier) => { - this.populateDescriptionMap(collection, extensionIdentifier); const it = collection.map.entries(); let next = it.next(); while (!next.done) { @@ -135,44 +133,10 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa }); return result; } - - getDescriptionMap(scope: EnvironmentVariableScope | undefined): Map { - const result = new Map(); - this.descriptionMap.forEach((mutators, _key) => { - const filteredMutators = mutators.filter(m => filterScope(m, scope)); - if (filteredMutators.length > 0) { - // There should be exactly one description per extension per scope. - result.set(filteredMutators[0].extensionIdentifier, filteredMutators[0].description); - } - }); - return result; - } - - private populateDescriptionMap(collection: IEnvironmentVariableCollection, extensionIdentifier: string): void { - const it = collection.descriptionMap.entries(); - let next = it.next(); - while (!next.done) { - const mutator = next.value[1]; - const key = next.value[0]; - let entry = this.descriptionMap.get(key); - if (!entry) { - entry = []; - this.descriptionMap.set(key, entry); - } - entry.push({ - extensionIdentifier, - scope: mutator.scope, - description: mutator.description - }); - - next = it.next(); - } - - } } function filterScope( - mutator: IExtensionOwnedEnvironmentVariableMutator | IExtensionOwnedEnvironmentDescriptionMutator, + mutator: IExtensionOwnedEnvironmentVariableMutator, scope: EnvironmentVariableScope | undefined ): boolean { if (!mutator.scope) { diff --git a/src/vs/platform/terminal/common/environmentVariableShared.ts b/src/vs/platform/terminal/common/environmentVariableShared.ts index c4b7bfda0b4..75874739537 100644 --- a/src/vs/platform/terminal/common/environmentVariableShared.ts +++ b/src/vs/platform/terminal/common/environmentVariableShared.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { IEnvironmentDescriptionMutator, IEnvironmentVariableCollection, IEnvironmentVariableMutator, ISerializableEnvironmentDescriptionMap as ISerializableEnvironmentDescriptionMap, ISerializableEnvironmentVariableCollection, ISerializableEnvironmentVariableCollections } from 'vs/platform/terminal/common/environmentVariable'; +import { IEnvironmentVariableCollection, IEnvironmentVariableMutator, ISerializableEnvironmentVariableCollection, ISerializableEnvironmentVariableCollections } from 'vs/platform/terminal/common/environmentVariable'; // This file is shared between the renderer and extension host @@ -11,25 +11,15 @@ export function serializeEnvironmentVariableCollection(collection: ReadonlyMap): ISerializableEnvironmentDescriptionMap { - return [...descriptionMap.entries()]; -} - export function deserializeEnvironmentVariableCollection( serializedCollection: ISerializableEnvironmentVariableCollection ): Map { return new Map(serializedCollection); } -export function deserializeEnvironmentDescriptionMap( - serializableEnvironmentDescription: ISerializableEnvironmentDescriptionMap -): Map { - return new Map(serializableEnvironmentDescription); -} - export function serializeEnvironmentVariableCollections(collections: ReadonlyMap): ISerializableEnvironmentVariableCollections { return Array.from(collections.entries()).map(e => { - return [e[0], serializeEnvironmentVariableCollection(e[1].map), serializeEnvironmentDescriptionMap(e[1].descriptionMap)]; + return [e[0], serializeEnvironmentVariableCollection(e[1].map)]; }); } @@ -37,6 +27,6 @@ export function deserializeEnvironmentVariableCollections( serializedCollection: ISerializableEnvironmentVariableCollections ): Map { return new Map(serializedCollection.map(e => { - return [e[0], { map: deserializeEnvironmentVariableCollection(e[1]), descriptionMap: deserializeEnvironmentDescriptionMap(e[2]) }]; + return [e[0], { map: deserializeEnvironmentVariableCollection(e[1]) }]; })); } diff --git a/src/vs/server/node/remoteTerminalChannel.ts b/src/vs/server/node/remoteTerminalChannel.ts index 3ca99ecbfdf..39b6b0a8aea 100644 --- a/src/vs/server/node/remoteTerminalChannel.ts +++ b/src/vs/server/node/remoteTerminalChannel.ts @@ -22,7 +22,7 @@ import { createURITransformer } from 'vs/workbench/api/node/uriTransformer'; import { CLIServerBase, ICommandsExecuter } from 'vs/workbench/api/node/extHostCLIServer'; import { IEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; import { MergedEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableCollection'; -import { deserializeEnvironmentDescriptionMap, deserializeEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableShared'; +import { deserializeEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableShared'; import { ICreateTerminalProcessArguments, ICreateTerminalProcessResult, IWorkspaceFolderData } from 'vs/workbench/contrib/terminal/common/remoteTerminalChannel'; import * as terminalEnvironment from 'vs/workbench/contrib/terminal/common/terminalEnvironment'; import { AbstractVariableResolverService } from 'vs/workbench/services/configurationResolver/common/variableResolver'; @@ -233,8 +233,8 @@ export class RemoteTerminalChannel extends Disposable implements IServerChannel< // Apply extension environment variable collections to the environment if (!shellLaunchConfig.strictEnv) { const entries: [string, IEnvironmentVariableCollection][] = []; - for (const [k, v, d] of args.envVariableCollections) { - entries.push([k, { map: deserializeEnvironmentVariableCollection(v), descriptionMap: deserializeEnvironmentDescriptionMap(d) }]); + for (const [k, v] of args.envVariableCollections) { + entries.push([k, { map: deserializeEnvironmentVariableCollection(v) }]); } const envVariableCollections = new Map(entries); const mergedCollection = new MergedEnvironmentVariableCollection(envVariableCollections); diff --git a/src/vs/workbench/api/browser/mainThreadTerminalService.ts b/src/vs/workbench/api/browser/mainThreadTerminalService.ts index f43a403ff42..93d4cd269d7 100644 --- a/src/vs/workbench/api/browser/mainThreadTerminalService.ts +++ b/src/vs/workbench/api/browser/mainThreadTerminalService.ts @@ -15,7 +15,7 @@ import { TerminalDataBufferer } from 'vs/platform/terminal/common/terminalDataBu import { ITerminalEditorService, ITerminalExternalLinkProvider, ITerminalGroupService, ITerminalInstance, ITerminalLink, ITerminalService } from 'vs/workbench/contrib/terminal/browser/terminal'; import { TerminalProcessExtHostProxy } from 'vs/workbench/contrib/terminal/browser/terminalProcessExtHostProxy'; import { IEnvironmentVariableService } from 'vs/workbench/contrib/terminal/common/environmentVariable'; -import { deserializeEnvironmentDescriptionMap, deserializeEnvironmentVariableCollection, serializeEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableShared'; +import { deserializeEnvironmentVariableCollection, serializeEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableShared'; import { IStartExtensionTerminalRequest, ITerminalProcessExtHostProxy, ITerminalProfileResolverService, ITerminalProfileService } from 'vs/workbench/contrib/terminal/common/terminal'; import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService'; import { withNullAsUndefined } from 'vs/base/common/types'; @@ -25,7 +25,7 @@ import { Promises } from 'vs/base/common/async'; import { CancellationToken } from 'vs/base/common/cancellation'; import { ITerminalCommand } from 'vs/platform/terminal/common/capabilities/capabilities'; import { TerminalQuickFixType } from 'vs/workbench/api/common/extHostTypes'; -import { ISerializableEnvironmentDescriptionMap, ISerializableEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; +import { ISerializableEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; import { ITerminalLinkProviderService } from 'vs/workbench/contrib/terminalContrib/links/browser/links'; import { ITerminalQuickFixService, ITerminalQuickFixOptions, ITerminalQuickFix } from 'vs/workbench/contrib/terminalContrib/quickFix/browser/quickFix'; @@ -400,12 +400,11 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape return terminal; } - $setEnvironmentVariableCollection(extensionIdentifier: string, persistent: boolean, collection: ISerializableEnvironmentVariableCollection | undefined, descriptionMap: ISerializableEnvironmentDescriptionMap): void { + $setEnvironmentVariableCollection(extensionIdentifier: string, persistent: boolean, collection: ISerializableEnvironmentVariableCollection | undefined): void { if (collection) { const translatedCollection = { persistent, - map: deserializeEnvironmentVariableCollection(collection), - descriptionMap: deserializeEnvironmentDescriptionMap(descriptionMap) + map: deserializeEnvironmentVariableCollection(collection) }; this._environmentVariableService.set(extensionIdentifier, translatedCollection); } else { diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index e81493b1a94..09355a18613 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -41,7 +41,7 @@ import * as quickInput from 'vs/platform/quickinput/common/quickInput'; import { IRemoteConnectionData, TunnelDescription } from 'vs/platform/remote/common/remoteAuthorityResolver'; import { ClassifiedEvent, IGDPRProperty, OmitMetadata, StrictPropertyCheck } from 'vs/platform/telemetry/common/gdprTypings'; import { TelemetryLevel } from 'vs/platform/telemetry/common/telemetry'; -import { ISerializableEnvironmentDescriptionMap, ISerializableEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; +import { ISerializableEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; import { ICreateContributedTerminalProfileOptions, IProcessProperty, IShellLaunchConfigDto, ITerminalEnvironment, ITerminalLaunchError, ITerminalProfile, TerminalExitReason, TerminalLocation } from 'vs/platform/terminal/common/terminal'; import { ProvidedPortAttributes, TunnelCreationOptions, TunnelOptions, TunnelPrivacyId, TunnelProviderFeatures } from 'vs/platform/tunnel/common/tunnel'; import { EditSessionIdentityMatch } from 'vs/platform/workspace/common/editSessions'; @@ -491,7 +491,7 @@ export interface MainThreadTerminalServiceShape extends IDisposable { $unregisterProfileProvider(id: string): void; $registerQuickFixProvider(id: string, extensionIdentifier: string): void; $unregisterQuickFixProvider(id: string): void; - $setEnvironmentVariableCollection(extensionIdentifier: string, persistent: boolean, collection: ISerializableEnvironmentVariableCollection | undefined, descriptionMap: ISerializableEnvironmentDescriptionMap): void; + $setEnvironmentVariableCollection(extensionIdentifier: string, persistent: boolean, collection: ISerializableEnvironmentVariableCollection | undefined): void; // Process $sendProcessData(terminalId: number, data: string): void; diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index 824349947ab..b5a6343503c 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -14,10 +14,10 @@ import { Disposable as VSCodeDisposable, EnvironmentVariableMutatorType, Termina import { IExtensionDescription } from 'vs/platform/extensions/common/extensions'; import { localize } from 'vs/nls'; import { NotSupportedError } from 'vs/base/common/errors'; -import { serializeEnvironmentDescriptionMap, serializeEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableShared'; +import { serializeEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableShared'; import { CancellationTokenSource } from 'vs/base/common/cancellation'; import { generateUuid } from 'vs/base/common/uuid'; -import { IEnvironmentDescriptionMutator, IEnvironmentVariableMutator, ISerializableEnvironmentDescriptionMap, ISerializableEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; +import { IEnvironmentVariableMutator, ISerializableEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; import { ICreateContributedTerminalProfileOptions, IProcessReadyEvent, IShellLaunchConfigDto, ITerminalChildProcess, ITerminalLaunchError, ITerminalProfile, TerminalIcon, TerminalLocation, IProcessProperty, ProcessPropertyType, IProcessPropertyMap } from 'vs/platform/terminal/common/terminal'; import { TerminalDataBufferer } from 'vs/platform/terminal/common/terminalDataBuffering'; import { ThemeColor } from 'vs/base/common/themables'; @@ -834,8 +834,7 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I private _syncEnvironmentVariableCollection(extensionIdentifier: string, collection: EnvironmentVariableCollection): void { const serialized = serializeEnvironmentVariableCollection(collection.map); - const serializedDescription = serializeEnvironmentDescriptionMap(collection.descriptionMap); - this._proxy.$setEnvironmentVariableCollection(extensionIdentifier, collection.persistent, serialized.length === 0 ? undefined : serialized, serializedDescription); + this._proxy.$setEnvironmentVariableCollection(extensionIdentifier, collection.persistent, serialized.length === 0 ? undefined : serialized); } public $initEnvironmentVariableCollections(collections: [string, ISerializableEnvironmentVariableCollection][]): void { @@ -869,7 +868,6 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollection { readonly map: Map = new Map(); - readonly descriptionMap: Map = new Map(); private _persistent: boolean = true; public get persistent(): boolean { return this._persistent; } @@ -950,28 +948,11 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect this.map.delete(key); } } - this.clearDescription(scope); } else { this.map.clear(); - this.descriptionMap.clear(); } this._onDidChangeCollection.fire(); } - - setDescription(description: string | undefined, scope?: vscode.EnvironmentVariableScope): void { - const key = this.getKey('', scope); - const current = this.descriptionMap.get(key); - if (!current || current.description !== description) { - const value: IEnvironmentDescriptionMutator = { description, scope }; - this.descriptionMap.set(key, value); - this._onDidChangeCollection.fire(); - } - } - - private clearDescription(scope?: vscode.EnvironmentVariableScope): void { - const key = this.getKey('', scope); - this.descriptionMap.delete(key); - } } export class WorkerExtHostTerminalService extends BaseExtHostTerminalService { diff --git a/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts b/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts index 242e6c16ffd..66e0ad68d4b 100644 --- a/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts +++ b/src/vs/workbench/contrib/terminal/browser/environmentVariableInfo.ts @@ -20,13 +20,12 @@ export class EnvironmentVariableInfoStale implements IEnvironmentVariableInfo { constructor( private readonly _diff: IMergedEnvironmentVariableCollectionDiff, private readonly _terminalId: number, - private readonly _collection: IMergedEnvironmentVariableCollection, @ITerminalService private readonly _terminalService: ITerminalService, @IExtensionService private readonly _extensionService: IExtensionService ) { } - private _getInfo(scope: EnvironmentVariableScope | undefined): string { + private _getInfo(): string { const extSet: Set = new Set(); addExtensionIdentifiers(extSet, this._diff.added.values()); addExtensionIdentifiers(extSet, this._diff.removed.values()); @@ -34,13 +33,8 @@ export class EnvironmentVariableInfoStale implements IEnvironmentVariableInfo { let message = localize('extensionEnvironmentContributionInfoStale', "The following extensions want to relaunch the terminal to contribute to its environment:"); message += '\n'; - const descriptionMap = this._collection.getDescriptionMap(scope); for (const ext of extSet) { message += `\n- \`${getExtensionName(ext, this._extensionService)}\``; - const description = descriptionMap.get(ext); - if (description) { - message += `: ${description}`; - } } return message; } @@ -53,12 +47,12 @@ export class EnvironmentVariableInfoStale implements IEnvironmentVariableInfo { }]; } - getStatus(scope: EnvironmentVariableScope | undefined): ITerminalStatus { + getStatus(): ITerminalStatus { return { id: TerminalStatus.RelaunchNeeded, severity: Severity.Warning, icon: Codicon.warning, - tooltip: this._getInfo(scope), + tooltip: this._getInfo(), hoverActions: this._getActions() }; } @@ -80,13 +74,8 @@ export class EnvironmentVariableInfoChangesActive implements IEnvironmentVariabl let message = localize('extensionEnvironmentContributionInfoActive', "The following extensions have contributed to this terminal's environment:"); message += '\n'; - const descriptionMap = this._collection.getDescriptionMap(scope); for (const ext of extSet) { message += `\n- \`${getExtensionName(ext, this._extensionService)}\``; - const description = descriptionMap.get(ext); - if (description) { - message += `: ${description}`; - } } return message; } diff --git a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts index 478ee622006..292669813c2 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts @@ -664,7 +664,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce } return; } - this.environmentVariableInfo = this._instantiationService.createInstance(EnvironmentVariableInfoStale, diff, this._instanceId, newCollection); + this.environmentVariableInfo = this._instantiationService.createInstance(EnvironmentVariableInfoStale, diff, this._instanceId); this._onEnvironmentVariableInfoChange.fire(this.environmentVariableInfo); } } diff --git a/src/vs/workbench/contrib/terminal/common/environmentVariableService.ts b/src/vs/workbench/contrib/terminal/common/environmentVariableService.ts index cd1c411b3a2..9f68db1d984 100644 --- a/src/vs/workbench/contrib/terminal/common/environmentVariableService.ts +++ b/src/vs/workbench/contrib/terminal/common/environmentVariableService.ts @@ -8,15 +8,14 @@ import { debounce, throttle } from 'vs/base/common/decorators'; import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage'; import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions'; import { MergedEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableCollection'; -import { deserializeEnvironmentDescriptionMap, deserializeEnvironmentVariableCollection, serializeEnvironmentDescriptionMap, serializeEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableShared'; +import { deserializeEnvironmentVariableCollection, serializeEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableShared'; import { IEnvironmentVariableCollectionWithPersistence, IEnvironmentVariableService } from 'vs/workbench/contrib/terminal/common/environmentVariable'; import { TerminalStorageKeys } from 'vs/workbench/contrib/terminal/common/terminalStorageKeys'; -import { IMergedEnvironmentVariableCollection, ISerializableEnvironmentDescriptionMap, ISerializableEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; +import { IMergedEnvironmentVariableCollection, ISerializableEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; interface ISerializableExtensionEnvironmentVariableCollection { extensionIdentifier: string; collection: ISerializableEnvironmentVariableCollection; - description: ISerializableEnvironmentDescriptionMap; } /** @@ -40,8 +39,7 @@ export class EnvironmentVariableService implements IEnvironmentVariableService { const collectionsJson: ISerializableExtensionEnvironmentVariableCollection[] = JSON.parse(serializedPersistedCollections); collectionsJson.forEach(c => this.collections.set(c.extensionIdentifier, { persistent: true, - map: deserializeEnvironmentVariableCollection(c.collection), - descriptionMap: deserializeEnvironmentDescriptionMap(c.description) + map: deserializeEnvironmentVariableCollection(c.collection) })); // Asynchronously invalidate collections where extensions have been uninstalled, this is @@ -82,8 +80,7 @@ export class EnvironmentVariableService implements IEnvironmentVariableService { if (collection.persistent) { collectionsJson.push({ extensionIdentifier, - collection: serializeEnvironmentVariableCollection(this.collections.get(extensionIdentifier)!.map), - description: serializeEnvironmentDescriptionMap(collection.descriptionMap) + collection: serializeEnvironmentVariableCollection(this.collections.get(extensionIdentifier)!.map) }); } }); diff --git a/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts b/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts index 5b128c3361d..f725cd971b9 100644 --- a/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts +++ b/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts @@ -11,7 +11,7 @@ import { IWorkbenchConfigurationService } from 'vs/workbench/services/configurat import { ILogService } from 'vs/platform/log/common/log'; import { IRemoteAuthorityResolverService } from 'vs/platform/remote/common/remoteAuthorityResolver'; import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; -import { serializeEnvironmentDescriptionMap, serializeEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableShared'; +import { serializeEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableShared'; import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver'; import { SideBySideEditor, EditorResourceAccessor } from 'vs/workbench/common/editor'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; @@ -23,11 +23,11 @@ import { IGetTerminalLayoutInfoArgs, IProcessDetails, ISetTerminalLayoutInfoArgs import { IProcessEnvironment, OperatingSystem } from 'vs/base/common/platform'; import { ICompleteTerminalConfiguration } from 'vs/workbench/contrib/terminal/common/terminal'; import { IPtyHostProcessReplayEvent } from 'vs/platform/terminal/common/capabilities/capabilities'; -import { ISerializableEnvironmentDescriptionMap as ISerializableEnvironmentDescriptionMap, ISerializableEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; +import { ISerializableEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; export const REMOTE_TERMINAL_CHANNEL_NAME = 'remoteterminal'; -export type ITerminalEnvironmentVariableCollections = [string, ISerializableEnvironmentVariableCollection, ISerializableEnvironmentDescriptionMap][]; +export type ITerminalEnvironmentVariableCollections = [string, ISerializableEnvironmentVariableCollection][]; export interface IWorkspaceFolderData { uri: UriComponents; @@ -152,7 +152,7 @@ export class RemoteTerminalChannelClient implements IPtyHostController { const envVariableCollections: ITerminalEnvironmentVariableCollections = []; for (const [k, v] of this._environmentVariableService.collections.entries()) { - envVariableCollections.push([k, serializeEnvironmentVariableCollection(v.map), serializeEnvironmentDescriptionMap(v.descriptionMap)]); + envVariableCollections.push([k, serializeEnvironmentVariableCollection(v.map)]); } const resolverResult = await this._remoteAuthorityResolverService.resolveAuthority(this._remoteAuthority); diff --git a/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts b/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts index 9c7ce4fbf05..202782232fb 100644 --- a/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts +++ b/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts @@ -14,12 +14,6 @@ declare module 'vscode' { } export interface EnvironmentVariableCollection extends Iterable<[variable: string, mutator: EnvironmentVariableMutator]> { - /** - * 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. - */ - setDescription(description: string | 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; From 1736cb1c54bd9eb7ea4c506a870dbef9c2acf51d Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Tue, 18 Apr 2023 22:09:40 +0000 Subject: [PATCH 46/68] Fix compile errors --- .../environmentVariableCollection.test.ts | 68 +++++++++---------- .../common/environmentVariableService.test.ts | 2 +- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts index 4280f82f12c..e59ea1538a5 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts @@ -33,7 +33,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['A', { value: 'a4', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] ]) }] - ]), undefined); + ])); deepStrictEqual([...merged.getVariableMap(undefined).entries()], [ ['A', [ { extensionIdentifier: 'ext4', type: EnvironmentVariableMutatorType.Append, value: 'a4', scope: undefined, variable: 'A' }, @@ -66,7 +66,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['A', { value: 'a4', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] ]) }] - ]), undefined); + ])); deepStrictEqual([...merged.getVariableMap(undefined).entries()], [ ['A', [ { extensionIdentifier: 'ext3', type: EnvironmentVariableMutatorType.Replace, value: 'a3', scope: undefined, variable: 'A' }, @@ -87,13 +87,13 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'C' }] ]) }] - ]), undefined); + ])); const env: IProcessEnvironment = { A: 'foo', B: 'bar', C: 'baz' }; - await merged.applyToProcessEnvironment(env); + await merged.applyToProcessEnvironment(env, undefined); deepStrictEqual(env, { A: 'a', B: 'barb', @@ -110,9 +110,9 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'C' }] ]) }] - ]), undefined); + ])); const env: IProcessEnvironment = {}; - await merged.applyToProcessEnvironment(env); + await merged.applyToProcessEnvironment(env, undefined); deepStrictEqual(env, { A: 'a', B: 'b', @@ -129,13 +129,13 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['c', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'c' }] ]) }] - ]), undefined); + ])); const env: IProcessEnvironment = { A: 'A', B: 'B', C: 'C' }; - await merged.applyToProcessEnvironment(env); + await merged.applyToProcessEnvironment(env, undefined); if (isWindows) { deepStrictEqual(env, { A: 'a', @@ -163,27 +163,27 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] ]) }] - ]), undefined); + ])); const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] ]) }] - ]), undefined); - const diff = merged1.diff(merged2); + ])); + const diff = merged1.diff(merged2, undefined); strictEqual(diff, undefined); }); test('should generate added diffs from when the first entry is added', () => { - const merged1 = new MergedEnvironmentVariableCollection(new Map([]), undefined); + const merged1 = new MergedEnvironmentVariableCollection(new Map([])); const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] ]) }] - ]), undefined); - const diff = merged1.diff(merged2)!; + ])); + const diff = merged1.diff(merged2, undefined)!; strictEqual(diff.changed.size, 0); strictEqual(diff.removed.size, 0); const entries = [...diff.added.entries()]; @@ -199,7 +199,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] ]) }] - ]), undefined); + ])); const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ @@ -207,8 +207,8 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }] ]) }] - ]), undefined); - const diff = merged1.diff(merged2)!; + ])); + const diff = merged1.diff(merged2, undefined)!; strictEqual(diff.changed.size, 0); strictEqual(diff.removed.size, 0); const entries = [...diff.added.entries()]; @@ -224,7 +224,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }] ]) }] - ]), undefined); + ])); const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext2', { @@ -237,8 +237,8 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }] ]) }] - ]), undefined); - const diff = merged1.diff(merged2)!; + ])); + const diff = merged1.diff(merged2, undefined)!; strictEqual(diff.changed.size, 0); strictEqual(diff.removed.size, 0); deepStrictEqual([...diff.added.entries()], [ @@ -257,8 +257,8 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] ]) }] - ]), undefined); - const diff2 = merged1.diff(merged3)!; + ])); + const diff2 = merged1.diff(merged3, undefined)!; strictEqual(diff2.changed.size, 0); strictEqual(diff2.removed.size, 0); deepStrictEqual([...diff.added.entries()], [...diff2.added.entries()], 'Swapping the order of the entries in the other collection should yield the same result'); @@ -271,7 +271,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] ]) }] - ]), undefined); + ])); const merged4 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ @@ -284,8 +284,8 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] ]) }] - ]), undefined); - const diff = merged1.diff(merged4); + ])); + const diff = merged1.diff(merged4, undefined); strictEqual(diff, undefined, 'Replace should ignore any entries after it'); }); @@ -297,15 +297,15 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['B', { value: 'b', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'B' }] ]) }] - ]), undefined); + ])); const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] ]) }] - ]), undefined); - const diff = merged1.diff(merged2)!; + ])); + const diff = merged1.diff(merged2, undefined)!; strictEqual(diff.changed.size, 0); strictEqual(diff.added.size, 0); deepStrictEqual([...diff.removed.entries()], [ @@ -321,7 +321,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['B', { value: 'b', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'B' }] ]) }] - ]), undefined); + ])); const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ @@ -329,8 +329,8 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }] ]) }] - ]), undefined); - const diff = merged1.diff(merged2)!; + ])); + const diff = merged1.diff(merged2, undefined)!; strictEqual(diff.added.size, 0); strictEqual(diff.removed.size, 0); deepStrictEqual([...diff.changed.entries()], [ @@ -347,7 +347,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['B', { value: 'b', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'B' }] ]) }] - ]), undefined); + ])); const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ @@ -355,8 +355,8 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['C', { value: 'c', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'C' }] ]) }] - ]), undefined); - const diff = merged1.diff(merged2)!; + ])); + const diff = merged1.diff(merged2, undefined)!; deepStrictEqual([...diff.added.entries()], [ ['C', [{ extensionIdentifier: 'ext1', value: 'c', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'C' }]], ]); diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts index 3033717c433..97a5e63778e 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts @@ -113,7 +113,7 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { // Verify the entries get applied to the environment as expected const env: IProcessEnvironment = { A: 'foo' }; - await environmentVariableService.mergedCollection.applyToProcessEnvironment(env); + await environmentVariableService.mergedCollection.applyToProcessEnvironment(env, undefined); deepStrictEqual(env, { A: 'a2:a3:a1' }); }); }); From fe8176d90d66f9de068209cadb620199df994ef5 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Tue, 18 Apr 2023 22:16:17 +0000 Subject: [PATCH 47/68] Update tests in env var --- .../common/environmentVariableService.test.ts | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts index 97a5e63778e..dace131fc2a 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts @@ -48,9 +48,9 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { test('should persist collections to the storage service and be able to restore from them', () => { const collection = new Map(); - collection.set('A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }); - collection.set('B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }); - collection.set('C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'C' }); + collection.set('A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }); + collection.set('B-key', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }); + collection.set('C-key', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'C' }); environmentVariableService.set('ext1', { map: collection, persistent: true }); deepStrictEqual([...environmentVariableService.mergedCollection.getVariableMap(undefined).entries()], [ ['A', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Replace, value: 'a', scope: undefined, variable: 'A' }]], @@ -73,12 +73,12 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { const collection1 = new Map(); const collection2 = new Map(); const collection3 = new Map(); - collection1.set('A', { value: 'a1', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }); - collection1.set('B', { value: 'b1', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'B' }); - collection2.set('A', { value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }); - collection2.set('B', { value: 'b2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }); - collection3.set('A', { value: 'a3', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }); - collection3.set('B', { value: 'b3', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'B' }); + collection1.set('A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }); + collection1.set('B-key', { value: 'b1', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'B' }); + collection2.set('A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }); + collection2.set('B-key', { value: 'b2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }); + collection3.set('A-key', { value: 'a3', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }); + collection3.set('B-key', { value: 'b3', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'B' }); environmentVariableService.set('ext1', { map: collection1, persistent: true }); environmentVariableService.set('ext2', { map: collection2, persistent: true }); environmentVariableService.set('ext3', { map: collection3, persistent: true }); @@ -95,9 +95,9 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { const collection1 = new Map(); const collection2 = new Map(); const collection3 = new Map(); - collection1.set('A', { value: ':a1', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }); - collection2.set('A', { value: 'a2:', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }); - collection3.set('A', { value: 'a3', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }); + collection1.set('A-key', { value: ':a1', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }); + collection2.set('A-key', { value: 'a2:', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }); + collection3.set('A-key', { value: 'a3', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }); environmentVariableService.set('ext1', { map: collection1, persistent: true }); environmentVariableService.set('ext2', { map: collection2, persistent: true }); environmentVariableService.set('ext3', { map: collection3, persistent: true }); From 37dae9801e967ac1ce4b0360486fa6f3d0812c50 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Tue, 18 Apr 2023 22:36:39 +0000 Subject: [PATCH 48/68] Use different key in variable collection tests --- .../environmentVariableCollection.test.ts | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts index e59ea1538a5..31099a42af1 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts @@ -15,22 +15,22 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }] ]) }], ['ext2', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] ]) }], ['ext3', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a3', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a3', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }] ]) }], ['ext4', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a4', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a4', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] ]) }] ])); @@ -48,22 +48,22 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }] ]) }], ['ext2', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] ]) }], ['ext3', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a3', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a3', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] ]) }], ['ext4', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a4', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a4', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] ]) }] ])); @@ -82,7 +82,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged = new MergedEnvironmentVariableCollection(new Map([ ['ext', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], + ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }], ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'C' }] ]) @@ -105,7 +105,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged = new MergedEnvironmentVariableCollection(new Map([ ['ext', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], + ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }], ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'C' }] ]) @@ -124,7 +124,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged = new MergedEnvironmentVariableCollection(new Map([ ['ext', { map: deserializeEnvironmentVariableCollection([ - ['a', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'a' }], + ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'a' }], ['b', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'b' }], ['c', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'c' }] ]) @@ -160,14 +160,14 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged1 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] ]) }] ])); const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] ]) }] ])); @@ -179,7 +179,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] ]) }] ])); @@ -196,14 +196,14 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged1 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] ]) }] ])); const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], + ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }] ]) }] @@ -221,7 +221,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged1 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }] ]) }] ])); @@ -229,12 +229,12 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext2', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] ]) }], ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }] ]) }] ])); @@ -248,13 +248,13 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged3 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }] ]) }], // This entry should get removed ['ext2', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] ]) }] ])); @@ -268,20 +268,20 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged1 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] ]) }] ])); const merged4 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] ]) }], // This entry should get removed as it comes after a replace ['ext2', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] ]) }] ])); @@ -293,7 +293,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged1 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], + ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], ['B', { value: 'b', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'B' }] ]) }] @@ -301,7 +301,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] ]) }] ])); @@ -317,7 +317,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged1 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], + ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], ['B', { value: 'b', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'B' }] ]) }] @@ -325,7 +325,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], + ['A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }] ]) }] @@ -343,7 +343,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged1 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], + ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], ['B', { value: 'b', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'B' }] ]) }] @@ -351,7 +351,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A', { value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], + ['A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], ['C', { value: 'c', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'C' }] ]) }] From 30fd6e0fae25cc3a386551c8eef0081a1061e50f Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Tue, 18 Apr 2023 23:24:46 +0000 Subject: [PATCH 49/68] Add scope tests for ctor --- .../environmentVariableCollection.test.ts | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts index 31099a42af1..8bb87a406bb 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts @@ -8,6 +8,7 @@ import { EnvironmentVariableMutatorType } from 'vs/platform/terminal/common/envi import { IProcessEnvironment, isWindows } from 'vs/base/common/platform'; import { MergedEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableCollection'; import { deserializeEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableShared'; +import { URI } from 'vs/base/common/uri'; suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { suite('ctor', () => { @@ -75,6 +76,74 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ]] ], 'The ext4 entry should be removed as it comes after a Replace'); }); + + test('Workspace scoped entries are not included when looking for global entries', () => { + const workspaceScope1 = { workspaceFolder: { uri: URI.file('workspace1'), name: 'workspace1', index: 0 } }; + const workspaceScope2 = { workspaceFolder: { uri: URI.file('workspace2'), name: 'workspace2', index: 3 } }; + const merged = new MergedEnvironmentVariableCollection(new Map([ + ['ext1', { + map: deserializeEnvironmentVariableCollection([ + ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: workspaceScope1, variable: 'A' }] + ]) + }], + ['ext2', { + map: deserializeEnvironmentVariableCollection([ + ['A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] + ]) + }], + ['ext3', { + map: deserializeEnvironmentVariableCollection([ + ['A-key', { value: 'a3', type: EnvironmentVariableMutatorType.Prepend, scope: workspaceScope2, variable: 'A' }] + ]) + }], + ['ext4', { + map: deserializeEnvironmentVariableCollection([ + ['A-key', { value: 'a4', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] + ]) + }] + ])); + deepStrictEqual([...merged.getVariableMap(undefined).entries()], [ + ['A', [ + { extensionIdentifier: 'ext4', type: EnvironmentVariableMutatorType.Append, value: 'a4', scope: undefined, variable: 'A' }, + { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Append, value: 'a2', scope: undefined, variable: 'A' }, + ]] + ]); + }); + + test('Appropriate workspace scoped entries are returned when querying for a particular workspace folder', () => { + const workspaceScope1 = { workspaceFolder: { uri: URI.file('workspace1'), name: 'workspace1', index: 0 } }; + const workspaceScope2 = { workspaceFolder: { uri: URI.file('workspace2'), name: 'workspace2', index: 3 } }; + const merged = new MergedEnvironmentVariableCollection(new Map([ + ['ext1', { + map: deserializeEnvironmentVariableCollection([ + ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: workspaceScope1, variable: 'A' }] + ]) + }], + ['ext2', { + map: deserializeEnvironmentVariableCollection([ + ['A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] + ]) + }], + ['ext3', { + map: deserializeEnvironmentVariableCollection([ + ['A-key', { value: 'a3', type: EnvironmentVariableMutatorType.Prepend, scope: workspaceScope2, variable: 'A' }] + ]) + }], + ['ext4', { + map: deserializeEnvironmentVariableCollection([ + ['A-key', { value: 'a4', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] + ]) + }] + ])); + deepStrictEqual([...merged.getVariableMap(workspaceScope2).entries()], [ + ['A', [ + { extensionIdentifier: 'ext4', type: EnvironmentVariableMutatorType.Append, value: 'a4', scope: undefined, variable: 'A' }, + { extensionIdentifier: 'ext3', type: EnvironmentVariableMutatorType.Prepend, value: 'a3', scope: workspaceScope2, variable: 'A' }, + { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Append, value: 'a2', scope: undefined, variable: 'A' }, + ]] + ]); + }); + }); suite('applyToProcessEnvironment', () => { From 606c2db11e5f923a1c99f8bfb9964ea998b7ec42 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Tue, 18 Apr 2023 23:28:48 +0000 Subject: [PATCH 50/68] Add scope tests for applyToProcessEnvironment --- .../environmentVariableCollection.test.ts | 91 ++++++++++++------- 1 file changed, 58 insertions(+), 33 deletions(-) diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts index 8bb87a406bb..22827cb5f99 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts @@ -77,39 +77,6 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ], 'The ext4 entry should be removed as it comes after a Replace'); }); - test('Workspace scoped entries are not included when looking for global entries', () => { - const workspaceScope1 = { workspaceFolder: { uri: URI.file('workspace1'), name: 'workspace1', index: 0 } }; - const workspaceScope2 = { workspaceFolder: { uri: URI.file('workspace2'), name: 'workspace2', index: 3 } }; - const merged = new MergedEnvironmentVariableCollection(new Map([ - ['ext1', { - map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: workspaceScope1, variable: 'A' }] - ]) - }], - ['ext2', { - map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] - ]) - }], - ['ext3', { - map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a3', type: EnvironmentVariableMutatorType.Prepend, scope: workspaceScope2, variable: 'A' }] - ]) - }], - ['ext4', { - map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a4', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] - ]) - }] - ])); - deepStrictEqual([...merged.getVariableMap(undefined).entries()], [ - ['A', [ - { extensionIdentifier: 'ext4', type: EnvironmentVariableMutatorType.Append, value: 'a4', scope: undefined, variable: 'A' }, - { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Append, value: 'a2', scope: undefined, variable: 'A' }, - ]] - ]); - }); - test('Appropriate workspace scoped entries are returned when querying for a particular workspace folder', () => { const workspaceScope1 = { workspaceFolder: { uri: URI.file('workspace1'), name: 'workspace1', index: 0 } }; const workspaceScope2 = { workspaceFolder: { uri: URI.file('workspace2'), name: 'workspace2', index: 3 } }; @@ -144,6 +111,39 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ]); }); + test('Workspace scoped entries are not included when looking for global entries', () => { + const workspaceScope1 = { workspaceFolder: { uri: URI.file('workspace1'), name: 'workspace1', index: 0 } }; + const workspaceScope2 = { workspaceFolder: { uri: URI.file('workspace2'), name: 'workspace2', index: 3 } }; + const merged = new MergedEnvironmentVariableCollection(new Map([ + ['ext1', { + map: deserializeEnvironmentVariableCollection([ + ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: workspaceScope1, variable: 'A' }] + ]) + }], + ['ext2', { + map: deserializeEnvironmentVariableCollection([ + ['A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] + ]) + }], + ['ext3', { + map: deserializeEnvironmentVariableCollection([ + ['A-key', { value: 'a3', type: EnvironmentVariableMutatorType.Prepend, scope: workspaceScope2, variable: 'A' }] + ]) + }], + ['ext4', { + map: deserializeEnvironmentVariableCollection([ + ['A-key', { value: 'a4', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] + ]) + }] + ])); + deepStrictEqual([...merged.getVariableMap(undefined).entries()], [ + ['A', [ + { extensionIdentifier: 'ext4', type: EnvironmentVariableMutatorType.Append, value: 'a4', scope: undefined, variable: 'A' }, + { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Append, value: 'a2', scope: undefined, variable: 'A' }, + ]] + ]); + }); + }); suite('applyToProcessEnvironment', () => { @@ -170,6 +170,31 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { }); }); + test('should apply the appropriate workspace scoped entries to an environment', async () => { + const workspaceScope1 = { workspaceFolder: { uri: URI.file('workspace1'), name: 'workspace1', index: 0 } }; + const workspaceScope2 = { workspaceFolder: { uri: URI.file('workspace2'), name: 'workspace2', index: 3 } }; + const merged = new MergedEnvironmentVariableCollection(new Map([ + ['ext', { + map: deserializeEnvironmentVariableCollection([ + ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: workspaceScope1, variable: 'A' }], + ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: workspaceScope2, variable: 'B' }], + ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'C' }] + ]) + }] + ])); + const env: IProcessEnvironment = { + A: 'foo', + B: 'bar', + C: 'baz' + }; + await merged.applyToProcessEnvironment(env, workspaceScope1); + deepStrictEqual(env, { + A: 'a', + B: 'bar', // This is not changed because the scope does not match + C: 'cbaz' + }); + }); + test('should apply the collection to environment entries with no values', async () => { const merged = new MergedEnvironmentVariableCollection(new Map([ ['ext', { From ae4c38eb5319f92b97d0904fed4f8f52134ae1ac Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Tue, 18 Apr 2023 23:37:10 +0000 Subject: [PATCH 51/68] Add tests for workspace scoped diffs --- .../environmentVariableCollection.test.ts | 59 ++++++++++++++----- 1 file changed, 44 insertions(+), 15 deletions(-) diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts index 22827cb5f99..57c14f3d8e8 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts @@ -78,12 +78,12 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { }); test('Appropriate workspace scoped entries are returned when querying for a particular workspace folder', () => { - const workspaceScope1 = { workspaceFolder: { uri: URI.file('workspace1'), name: 'workspace1', index: 0 } }; - const workspaceScope2 = { workspaceFolder: { uri: URI.file('workspace2'), name: 'workspace2', index: 3 } }; + const scope1 = { workspaceFolder: { uri: URI.file('workspace1'), name: 'workspace1', index: 0 } }; + const scope2 = { workspaceFolder: { uri: URI.file('workspace2'), name: 'workspace2', index: 3 } }; const merged = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: workspaceScope1, variable: 'A' }] + ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: scope1, variable: 'A' }] ]) }], ['ext2', { @@ -93,7 +93,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { }], ['ext3', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a3', type: EnvironmentVariableMutatorType.Prepend, scope: workspaceScope2, variable: 'A' }] + ['A-key', { value: 'a3', type: EnvironmentVariableMutatorType.Prepend, scope: scope2, variable: 'A' }] ]) }], ['ext4', { @@ -102,22 +102,22 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ]) }] ])); - deepStrictEqual([...merged.getVariableMap(workspaceScope2).entries()], [ + deepStrictEqual([...merged.getVariableMap(scope2).entries()], [ ['A', [ { extensionIdentifier: 'ext4', type: EnvironmentVariableMutatorType.Append, value: 'a4', scope: undefined, variable: 'A' }, - { extensionIdentifier: 'ext3', type: EnvironmentVariableMutatorType.Prepend, value: 'a3', scope: workspaceScope2, variable: 'A' }, + { extensionIdentifier: 'ext3', type: EnvironmentVariableMutatorType.Prepend, value: 'a3', scope: scope2, variable: 'A' }, { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Append, value: 'a2', scope: undefined, variable: 'A' }, ]] ]); }); test('Workspace scoped entries are not included when looking for global entries', () => { - const workspaceScope1 = { workspaceFolder: { uri: URI.file('workspace1'), name: 'workspace1', index: 0 } }; - const workspaceScope2 = { workspaceFolder: { uri: URI.file('workspace2'), name: 'workspace2', index: 3 } }; + const scope1 = { workspaceFolder: { uri: URI.file('workspace1'), name: 'workspace1', index: 0 } }; + const scope2 = { workspaceFolder: { uri: URI.file('workspace2'), name: 'workspace2', index: 3 } }; const merged = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: workspaceScope1, variable: 'A' }] + ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: scope1, variable: 'A' }] ]) }], ['ext2', { @@ -127,7 +127,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { }], ['ext3', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a3', type: EnvironmentVariableMutatorType.Prepend, scope: workspaceScope2, variable: 'A' }] + ['A-key', { value: 'a3', type: EnvironmentVariableMutatorType.Prepend, scope: scope2, variable: 'A' }] ]) }], ['ext4', { @@ -171,13 +171,13 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { }); test('should apply the appropriate workspace scoped entries to an environment', async () => { - const workspaceScope1 = { workspaceFolder: { uri: URI.file('workspace1'), name: 'workspace1', index: 0 } }; - const workspaceScope2 = { workspaceFolder: { uri: URI.file('workspace2'), name: 'workspace2', index: 3 } }; + const scope1 = { workspaceFolder: { uri: URI.file('workspace1'), name: 'workspace1', index: 0 } }; + const scope2 = { workspaceFolder: { uri: URI.file('workspace2'), name: 'workspace2', index: 3 } }; const merged = new MergedEnvironmentVariableCollection(new Map([ ['ext', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: workspaceScope1, variable: 'A' }], - ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: workspaceScope2, variable: 'B' }], + ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: scope1, variable: 'A' }], + ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: scope2, variable: 'B' }], ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'C' }] ]) }] @@ -187,7 +187,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { B: 'bar', C: 'baz' }; - await merged.applyToProcessEnvironment(env, workspaceScope1); + await merged.applyToProcessEnvironment(env, scope1); deepStrictEqual(env, { A: 'a', B: 'bar', // This is not changed because the scope does not match @@ -461,5 +461,34 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['A', [{ extensionIdentifier: 'ext1', value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }]] ]); }); + + test('should only generate workspace specific diffs', () => { + const scope1 = { workspaceFolder: { uri: URI.file('workspace1'), name: 'workspace1', index: 0 } }; + const scope2 = { workspaceFolder: { uri: URI.file('workspace2'), name: 'workspace2', index: 3 } }; + const merged1 = new MergedEnvironmentVariableCollection(new Map([ + ['ext1', { + map: deserializeEnvironmentVariableCollection([ + ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, scope: scope1, variable: 'A' }], + ['B', { value: 'b', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'B' }] + ]) + }] + ])); + const merged2 = new MergedEnvironmentVariableCollection(new Map([ + ['ext1', { + map: deserializeEnvironmentVariableCollection([ + ['A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: scope1, variable: 'A' }], + ['C', { value: 'c', type: EnvironmentVariableMutatorType.Append, scope: scope2, variable: 'C' }] + ]) + }] + ])); + const diff = merged1.diff(merged2, undefined)!; + deepStrictEqual([...diff.added.entries()], [[]]); + deepStrictEqual([...diff.removed.entries()], [ + ['B', [{ extensionIdentifier: 'ext1', value: 'b', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'B' }]] + ]); + deepStrictEqual([...diff.changed.entries()], [ + ['A', [{ extensionIdentifier: 'ext1', value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }]] + ]); + }); }); }); From 305b4199e1b11f8fadb8ce15b96889baa68bf7ee Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Tue, 18 Apr 2023 23:43:48 +0000 Subject: [PATCH 52/68] Add scope tests for env var service --- .../common/environmentVariableService.test.ts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts index dace131fc2a..2b31da927a6 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts @@ -13,6 +13,7 @@ import { IExtensionService } from 'vs/workbench/services/extensions/common/exten import { Emitter } from 'vs/base/common/event'; import { IProcessEnvironment } from 'vs/base/common/platform'; import { IHistoryService } from 'vs/workbench/services/history/common/history'; +import { URI } from 'vs/base/common/uri'; class TestEnvironmentVariableService extends EnvironmentVariableService { persistCollections(): void { this._persistCollections(); } @@ -116,5 +117,32 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { await environmentVariableService.mergedCollection.applyToProcessEnvironment(env, undefined); deepStrictEqual(env, { A: 'a2:a3:a1' }); }); + + test('should correctly apply the workspace specific environment values from multiple extension contributions in the correct order', async () => { + const scope1 = { workspaceFolder: { uri: URI.file('workspace1'), name: 'workspace1', index: 0 } }; + const scope2 = { workspaceFolder: { uri: URI.file('workspace2'), name: 'workspace2', index: 3 } }; + const collection1 = new Map(); + const collection2 = new Map(); + const collection3 = new Map(); + collection1.set('A-key', { value: ':a1', type: EnvironmentVariableMutatorType.Append, scope: scope1, variable: 'A' }); + collection2.set('A-key', { value: 'a2:', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }); + collection3.set('A-key', { value: 'a3', type: EnvironmentVariableMutatorType.Replace, scope: scope2, variable: 'A' }); + environmentVariableService.set('ext1', { map: collection1, persistent: true }); + environmentVariableService.set('ext2', { map: collection2, persistent: true }); + environmentVariableService.set('ext3', { map: collection3, persistent: true }); + + // The entries should be ordered in the order they are applied + deepStrictEqual([...environmentVariableService.mergedCollection.getVariableMap(scope1).entries()], [ + ['A', [ + { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Prepend, value: 'a2:', scope: undefined, variable: 'A' }, + { extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Append, value: ':a1', scope: scope1, variable: 'A' } + ]] + ]); + + // Verify the entries get applied to the environment as expected + const env: IProcessEnvironment = { A: 'foo' }; + await environmentVariableService.mergedCollection.applyToProcessEnvironment(env, scope1); + deepStrictEqual(env, { A: 'a2:foo:a1' }); + }); }); }); From ce770329cd566e34ccbfe5c35704f84b6bc51f0c Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Tue, 18 Apr 2023 23:54:30 +0000 Subject: [PATCH 53/68] Fix --- .../terminal/test/common/environmentVariableCollection.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts index 57c14f3d8e8..1702e116fda 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts @@ -482,7 +482,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { }] ])); const diff = merged1.diff(merged2, undefined)!; - deepStrictEqual([...diff.added.entries()], [[]]); + deepStrictEqual([...diff.added.entries()], []); deepStrictEqual([...diff.removed.entries()], [ ['B', [{ extensionIdentifier: 'ext1', value: 'b', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'B' }]] ]); From d50e185fcf90d74b8d61b65f5fce36b9b598e20f Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Wed, 19 Apr 2023 00:18:31 +0000 Subject: [PATCH 54/68] Attempt to fix tests --- .../test/common/environmentVariableCollection.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts index 1702e116fda..eecfdf757b3 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts @@ -481,13 +481,13 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ]) }] ])); - const diff = merged1.diff(merged2, undefined)!; - deepStrictEqual([...diff.added.entries()], []); + const diff = merged1.diff(merged2, scope1)!; + strictEqual(diff.added.size, 0); deepStrictEqual([...diff.removed.entries()], [ ['B', [{ extensionIdentifier: 'ext1', value: 'b', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'B' }]] ]); deepStrictEqual([...diff.changed.entries()], [ - ['A', [{ extensionIdentifier: 'ext1', value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }]] + ['A', [{ extensionIdentifier: 'ext1', value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: scope1, variable: 'A' }]] ]); }); }); From ac3d1562b5e0a53b0f8f94fe720b82abb6cef135 Mon Sep 17 00:00:00 2001 From: First Date: Wed, 19 Apr 2023 15:24:23 -0700 Subject: [PATCH 55/68] Deprecate old env var storage --- .../contrib/terminal/common/environmentVariableService.ts | 1 + .../workbench/contrib/terminal/common/terminalStorageKeys.ts | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/contrib/terminal/common/environmentVariableService.ts b/src/vs/workbench/contrib/terminal/common/environmentVariableService.ts index 9f68db1d984..dbd39153b54 100644 --- a/src/vs/workbench/contrib/terminal/common/environmentVariableService.ts +++ b/src/vs/workbench/contrib/terminal/common/environmentVariableService.ts @@ -34,6 +34,7 @@ export class EnvironmentVariableService implements IEnvironmentVariableService { @IExtensionService private readonly _extensionService: IExtensionService, @IStorageService private readonly _storageService: IStorageService ) { + this._storageService.remove(TerminalStorageKeys.DeprecatedEnvironmentVariableCollections, StorageScope.WORKSPACE); const serializedPersistedCollections = this._storageService.get(TerminalStorageKeys.EnvironmentVariableCollections, StorageScope.WORKSPACE); if (serializedPersistedCollections) { const collectionsJson: ISerializableExtensionEnvironmentVariableCollection[] = JSON.parse(serializedPersistedCollections); diff --git a/src/vs/workbench/contrib/terminal/common/terminalStorageKeys.ts b/src/vs/workbench/contrib/terminal/common/terminalStorageKeys.ts index 30f88b0cfa0..521a2cde049 100644 --- a/src/vs/workbench/contrib/terminal/common/terminalStorageKeys.ts +++ b/src/vs/workbench/contrib/terminal/common/terminalStorageKeys.ts @@ -8,7 +8,8 @@ export const enum TerminalStorageKeys { SuggestedRendererType = 'terminal.integrated.suggestedRendererType', TabsListWidthHorizontal = 'tabs-list-width-horizontal', TabsListWidthVertical = 'tabs-list-width-vertical', - EnvironmentVariableCollections = 'terminal.integrated.environmentVariableCollections', + DeprecatedEnvironmentVariableCollections = 'terminal.integrated.environmentVariableCollections', + EnvironmentVariableCollections = 'terminal.integrated.environmentVariableCollectionsV2', TerminalBufferState = 'terminal.integrated.bufferState', TerminalLayoutInfo = 'terminal.integrated.layoutInfo', PinnedRecentCommandsPrefix = 'terminal.pinnedRecentCommands', From 0dc2f4867268ceea1c327215eb9c8f73d590cccf Mon Sep 17 00:00:00 2001 From: First Date: Wed, 19 Apr 2023 16:25:34 -0700 Subject: [PATCH 56/68] Undo using cwd for remote terminal --- src/vs/server/node/remoteTerminalChannel.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/vs/server/node/remoteTerminalChannel.ts b/src/vs/server/node/remoteTerminalChannel.ts index 39b6b0a8aea..fddf20d605d 100644 --- a/src/vs/server/node/remoteTerminalChannel.ts +++ b/src/vs/server/node/remoteTerminalChannel.ts @@ -238,8 +238,7 @@ export class RemoteTerminalChannel extends Disposable implements IServerChannel< } const envVariableCollections = new Map(entries); const mergedCollection = new MergedEnvironmentVariableCollection(envVariableCollections); - const cwdUri = typeof shellLaunchConfig.cwd === 'string' ? URI.parse(shellLaunchConfig.cwd) : shellLaunchConfig.cwd; - const workspaceFolder = cwdUri ? withNullAsUndefined(activeWorkspaceFolder) : undefined; + const workspaceFolder = activeWorkspaceFolder ? withNullAsUndefined(activeWorkspaceFolder) : undefined; await mergedCollection.applyToProcessEnvironment(env, { workspaceFolder }, variableResolver); } From 81f2173b70122a7a42aefcff838acb1d90d02d5f Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Thu, 20 Apr 2023 17:21:38 +0000 Subject: [PATCH 57/68] Use common function to get workspace folder --- .../terminal/browser/terminalInstance.ts | 5 ++--- .../browser/terminalProcessManager.ts | 7 ++----- .../electron-sandbox/localTerminalBackend.ts | 8 ++----- .../common/terminalResolver.ts | 21 +++++++++++++++++++ 4 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 src/vs/workbench/services/configurationResolver/common/terminalResolver.ts diff --git a/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts b/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts index 036274e1da0..d25f67f7516 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts @@ -89,6 +89,7 @@ import { PANEL_BACKGROUND, SIDE_BAR_BACKGROUND } from 'vs/workbench/common/theme import { TerminalExtensionsRegistry } from 'vs/workbench/contrib/terminal/browser/terminalExtensions'; import { ResolvedKeybinding } from 'vs/base/common/keybindings'; import { ResultKind } from 'vs/platform/keybinding/common/keybindingResolver'; +import { getWorkspaceForTerminal } from 'vs/workbench/services/configurationResolver/common/terminalResolver'; const enum Constants { /** @@ -2160,10 +2161,8 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { this.relaunch(); return; } - const cwdUri = typeof this.shellLaunchConfig.cwd === 'string' ? URI.parse(this.shellLaunchConfig.cwd) : this.shellLaunchConfig.cwd; - const workspaceFolder = cwdUri ? withNullAsUndefined(this._workspaceContextService.getWorkspaceFolder(cwdUri)) : undefined; - // Re-create statuses + const workspaceFolder = getWorkspaceForTerminal(this.shellLaunchConfig.cwd, this._workspaceContextService, this._historyService); this.statusList.add(info.getStatus({ workspaceFolder })); } diff --git a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts index 292669813c2..2c3d2247fa7 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts @@ -39,6 +39,7 @@ import { TaskSettingId } from 'vs/workbench/contrib/tasks/common/tasks'; import Severity from 'vs/base/common/severity'; import { INotificationService } from 'vs/platform/notification/common/notification'; import { IEnvironmentVariableCollection, IMergedEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable'; +import { getWorkspaceForTerminal } from 'vs/workbench/services/configurationResolver/common/terminalResolver'; const enum ProcessConstants { /** @@ -148,8 +149,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce @INotificationService private readonly _notificationService: INotificationService ) { super(); - const cwdUri = typeof cwd === 'string' ? URI.parse(cwd) : cwd; - this._cwdWorkspaceFolder = cwdUri ? withNullAsUndefined(this._workspaceContextService.getWorkspaceFolder(cwdUri)) : undefined; + this._cwdWorkspaceFolder = getWorkspaceForTerminal(cwd, this._workspaceContextService, this._historyService); this.ptyProcessReady = this._createPtyProcessReadyPromise(); this.getLatency(); this._ackDataBufferer = new AckDataBufferer(e => this._process?.acknowledgeDataEvent(e)); @@ -172,9 +172,6 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce } else { this.remoteAuthority = this._workbenchEnvironmentService.remoteAuthority; } - const activeWorkspaceRootUri = this._historyService.getLastActiveWorkspaceRoot(); - this._lastActiveWorkspace = activeWorkspaceRootUri ? withNullAsUndefined(this._workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri)) : undefined; - this._cwdWorkspaceFolder = this._cwdWorkspaceFolder ?? this._lastActiveWorkspace; // fallback to last active workspace if cwd is not available or it is not in workspace if (environmentVariableCollections) { this._extEnvironmentVariableCollection = new MergedEnvironmentVariableCollection(environmentVariableCollections); diff --git a/src/vs/workbench/contrib/terminal/electron-sandbox/localTerminalBackend.ts b/src/vs/workbench/contrib/terminal/electron-sandbox/localTerminalBackend.ts index f9043b7e832..cf8cda99141 100644 --- a/src/vs/workbench/contrib/terminal/electron-sandbox/localTerminalBackend.ts +++ b/src/vs/workbench/contrib/terminal/electron-sandbox/localTerminalBackend.ts @@ -30,6 +30,7 @@ import * as terminalEnvironment from 'vs/workbench/contrib/terminal/common/termi import { IProductService } from 'vs/platform/product/common/productService'; import { IEnvironmentVariableService } from 'vs/workbench/contrib/terminal/common/environmentVariable'; import { BaseTerminalBackend } from 'vs/workbench/contrib/terminal/browser/baseTerminalBackend'; +import { getWorkspaceForTerminal } from 'vs/workbench/services/configurationResolver/common/terminalResolver'; export class LocalTerminalBackendContribution implements IWorkbenchContribution { constructor( @@ -262,12 +263,7 @@ class LocalTerminalBackend extends BaseTerminalBackend implements ITerminalBacke const baseEnv = await (shellLaunchConfig.useShellEnvironment ? this.getShellEnvironment() : this.getEnvironment()); const env = await terminalEnvironment.createTerminalEnvironment(shellLaunchConfig, envFromConfigValue, variableResolver, this._productService.version, this._configurationService.getValue(TerminalSettingId.DetectLocale), baseEnv); if (!shellLaunchConfig.strictEnv && !shellLaunchConfig.hideFromUser) { - const cwdUri = typeof shellLaunchConfig.cwd === 'string' ? URI.parse(shellLaunchConfig.cwd) : shellLaunchConfig.cwd; - let workspaceFolder = cwdUri ? withNullAsUndefined(this._workspaceContextService.getWorkspaceFolder(cwdUri)) : undefined; - if (!workspaceFolder) { - const activeWorkspaceRootUri = this._historyService.getLastActiveWorkspaceRoot(); - workspaceFolder = activeWorkspaceRootUri ? withNullAsUndefined(this._workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri)) : undefined; - } + const workspaceFolder = getWorkspaceForTerminal(shellLaunchConfig.cwd, this._workspaceContextService, this._historyService); await this._environmentVariableService.mergedCollection.applyToProcessEnvironment(env, { workspaceFolder }, variableResolver); } return env; diff --git a/src/vs/workbench/services/configurationResolver/common/terminalResolver.ts b/src/vs/workbench/services/configurationResolver/common/terminalResolver.ts new file mode 100644 index 00000000000..f6f11802790 --- /dev/null +++ b/src/vs/workbench/services/configurationResolver/common/terminalResolver.ts @@ -0,0 +1,21 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { withNullAsUndefined } from 'vs/base/common/types'; +import { URI } from 'vs/base/common/uri'; +import { IWorkspaceContextService, IWorkspaceFolder } from 'vs/platform/workspace/common/workspace'; +import { IHistoryService } from 'vs/workbench/services/history/common/history'; + +export function getWorkspaceForTerminal(cwd: URI | string | undefined, workspaceContextService: IWorkspaceContextService, historyService: IHistoryService): IWorkspaceFolder | undefined { + const cwdUri = typeof cwd === 'string' ? URI.parse(cwd) : cwd; + let workspaceFolder = cwdUri ? withNullAsUndefined(workspaceContextService.getWorkspaceFolder(cwdUri)) : undefined; + if (!workspaceFolder) { + // fallback to last active workspace if cwd is not available or it is not in workspace + // TOOD: last active workspace is known to be unreliable, we should remove this fallback eventually + const activeWorkspaceRootUri = historyService.getLastActiveWorkspaceRoot(); + workspaceFolder = activeWorkspaceRootUri ? withNullAsUndefined(workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri)) : undefined; + } + return workspaceFolder; +} From be89fd23d09ab9dbeb961c63a1208f4259f7d9b4 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Thu, 20 Apr 2023 17:51:13 +0000 Subject: [PATCH 58/68] Fix for remote terminals --- src/vs/server/node/remoteTerminalChannel.ts | 4 +++- .../contrib/terminal/common/remoteTerminalChannel.ts | 5 ++++- .../configurationResolver/common/terminalResolver.ts | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/vs/server/node/remoteTerminalChannel.ts b/src/vs/server/node/remoteTerminalChannel.ts index fddf20d605d..209a33f6a6f 100644 --- a/src/vs/server/node/remoteTerminalChannel.ts +++ b/src/vs/server/node/remoteTerminalChannel.ts @@ -32,6 +32,7 @@ import { IProductService } from 'vs/platform/product/common/productService'; import { IExtensionManagementService } from 'vs/platform/extensionManagement/common/extensionManagement'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { withNullAsUndefined } from 'vs/base/common/types'; +import { getWorkspaceForTerminal } from 'vs/workbench/services/configurationResolver/common/terminalResolver'; class CustomVariableResolver extends AbstractVariableResolverService { constructor( @@ -238,8 +239,9 @@ export class RemoteTerminalChannel extends Disposable implements IServerChannel< } const envVariableCollections = new Map(entries); const mergedCollection = new MergedEnvironmentVariableCollection(envVariableCollections); + const cwdWorkspaceFolder = getWorkspaceForTerminal(shellLaunchConfig.cwd, args.workspaceContextService, undefined); const workspaceFolder = activeWorkspaceFolder ? withNullAsUndefined(activeWorkspaceFolder) : undefined; - await mergedCollection.applyToProcessEnvironment(env, { workspaceFolder }, variableResolver); + await mergedCollection.applyToProcessEnvironment(env, { workspaceFolder: cwdWorkspaceFolder ?? workspaceFolder }, variableResolver); } // Fork the process and listen for messages diff --git a/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts b/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts index f725cd971b9..24fc081a00a 100644 --- a/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts +++ b/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts @@ -51,6 +51,8 @@ export interface ICreateTerminalProcessArguments { rows: number; unicodeVersion: '6' | '11'; resolverEnv: { [key: string]: string | null } | undefined; + // TODO: Remove this when last active workspace is fixed + workspaceContextService: IWorkspaceContextService; } export interface ICreateTerminalProcessResult { @@ -182,7 +184,8 @@ export class RemoteTerminalChannelClient implements IPtyHostController { cols, rows, unicodeVersion, - resolverEnv + resolverEnv, + workspaceContextService: this._workspaceContextService, }; return await this._channel.call('$createProcess', args); } diff --git a/src/vs/workbench/services/configurationResolver/common/terminalResolver.ts b/src/vs/workbench/services/configurationResolver/common/terminalResolver.ts index f6f11802790..cf19d4d31f8 100644 --- a/src/vs/workbench/services/configurationResolver/common/terminalResolver.ts +++ b/src/vs/workbench/services/configurationResolver/common/terminalResolver.ts @@ -8,13 +8,13 @@ import { URI } from 'vs/base/common/uri'; import { IWorkspaceContextService, IWorkspaceFolder } from 'vs/platform/workspace/common/workspace'; import { IHistoryService } from 'vs/workbench/services/history/common/history'; -export function getWorkspaceForTerminal(cwd: URI | string | undefined, workspaceContextService: IWorkspaceContextService, historyService: IHistoryService): IWorkspaceFolder | undefined { +export function getWorkspaceForTerminal(cwd: URI | string | undefined, workspaceContextService: IWorkspaceContextService, historyService: IHistoryService | undefined): IWorkspaceFolder | undefined { const cwdUri = typeof cwd === 'string' ? URI.parse(cwd) : cwd; let workspaceFolder = cwdUri ? withNullAsUndefined(workspaceContextService.getWorkspaceFolder(cwdUri)) : undefined; if (!workspaceFolder) { // fallback to last active workspace if cwd is not available or it is not in workspace // TOOD: last active workspace is known to be unreliable, we should remove this fallback eventually - const activeWorkspaceRootUri = historyService.getLastActiveWorkspaceRoot(); + const activeWorkspaceRootUri = historyService?.getLastActiveWorkspaceRoot(); workspaceFolder = activeWorkspaceRootUri ? withNullAsUndefined(workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri)) : undefined; } return workspaceFolder; From 3c708899a3cacffbac9733cbf2461b27a9661b12 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Thu, 20 Apr 2023 18:12:21 +0000 Subject: [PATCH 59/68] Nit --- .../contrib/terminal/browser/terminalProcessManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts index 2c3d2247fa7..15dfda7c2cc 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts @@ -436,7 +436,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce // condition, the chance is minimal plus the impact on the user is also not that great // if it happens - it's not worth adding plumbing to sync back the resolved collection. await this._extEnvironmentVariableCollection.applyToProcessEnvironment(env, { workspaceFolder }, variableResolver); - if (this._extEnvironmentVariableCollection.getVariableMap({ workspaceFolder }).size > 0) { + if (this._extEnvironmentVariableCollection.getVariableMap({ workspaceFolder }).size) { this.environmentVariableInfo = this._instantiationService.createInstance(EnvironmentVariableInfoChangesActive, this._extEnvironmentVariableCollection); this._onEnvironmentVariableInfoChange.fire(this.environmentVariableInfo); } From 2b2b5f0319a87625aa6f7fcc1e108162efbc5649 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Thu, 20 Apr 2023 18:34:20 +0000 Subject: [PATCH 60/68] Make scope optional interally --- .../terminal/common/environmentVariable.ts | 2 +- .../api/common/extHostTerminalService.ts | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/vs/platform/terminal/common/environmentVariable.ts b/src/vs/platform/terminal/common/environmentVariable.ts index ce731ff8b71..f207a85a987 100644 --- a/src/vs/platform/terminal/common/environmentVariable.ts +++ b/src/vs/platform/terminal/common/environmentVariable.ts @@ -20,7 +20,7 @@ export interface IEnvironmentVariableMutator { readonly variable: string; readonly value: string; readonly type: EnvironmentVariableMutatorType; - readonly scope: EnvironmentVariableScope | undefined; + readonly scope?: EnvironmentVariableScope; // readonly timing?: EnvironmentVariableMutatorTiming; } diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index b5a6343503c..7cb1ff22227 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -931,8 +931,16 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect this.map.forEach((value, _) => callback.call(thisArg, value.variable, convertMutator(value), this)); } - [Symbol.iterator](): IterableIterator<[key: string, mutator: IEnvironmentVariableMutator]> { - return this.map.entries(); + [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 { @@ -991,7 +999,8 @@ function asTerminalColor(color?: vscode.ThemeColor): ThemeColor | undefined { } function convertMutator(mutator: IEnvironmentVariableMutator): vscode.EnvironmentVariableMutator { - const newMutator: vscode.EnvironmentVariableMutator = { ...mutator }; + const newMutator = { ...mutator }; + newMutator.scope = newMutator.scope ?? undefined; delete (newMutator as any).variable; - return newMutator; + return newMutator as vscode.EnvironmentVariableMutator; } From 50408e199f4f047e5a7b7c40183faaffe1578769 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Thu, 20 Apr 2023 18:41:50 +0000 Subject: [PATCH 61/68] Make scope as optional --- .../src/singlefolder-tests/terminal.test.ts | 12 +- .../environmentVariableCollection.test.ts | 138 +++++++++--------- .../common/environmentVariableService.test.ts | 52 +++---- .../common/environmentVariableShared.test.ts | 24 +-- 4 files changed, 113 insertions(+), 113 deletions(-) diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/terminal.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/terminal.test.ts index 36c1e66c852..b76e348e02e 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/terminal.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/terminal.test.ts @@ -850,17 +850,17 @@ import { assertNoRpc, poll } from '../utils'; collection.prepend('C', '~c2~'); // Verify get - deepStrictEqual(collection.get('A'), { value: '~a2~', type: EnvironmentVariableMutatorType.Replace, scope: undefined }); - deepStrictEqual(collection.get('B'), { value: '~b2~', type: EnvironmentVariableMutatorType.Append, scope: undefined }); - deepStrictEqual(collection.get('C'), { value: '~c2~', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }); + deepStrictEqual(collection.get('A'), { value: '~a2~', type: EnvironmentVariableMutatorType.Replace }); + deepStrictEqual(collection.get('B'), { value: '~b2~', type: EnvironmentVariableMutatorType.Append }); + deepStrictEqual(collection.get('C'), { value: '~c2~', type: EnvironmentVariableMutatorType.Prepend }); // Verify forEach const entries: [string, EnvironmentVariableMutator][] = []; collection.forEach((v, m) => entries.push([v, m])); deepStrictEqual(entries, [ - ['A', { value: '~a2~', type: EnvironmentVariableMutatorType.Replace, scope: undefined }], - ['B', { value: '~b2~', type: EnvironmentVariableMutatorType.Append, scope: undefined }], - ['C', { value: '~c2~', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }] + ['A', { value: '~a2~', type: EnvironmentVariableMutatorType.Replace }], + ['B', { value: '~b2~', type: EnvironmentVariableMutatorType.Append }], + ['C', { value: '~c2~', type: EnvironmentVariableMutatorType.Prepend }] ]); }); }); diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts index eecfdf757b3..528fb863631 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableCollection.test.ts @@ -16,31 +16,31 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, variable: 'A' }] ]) }], ['ext2', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Append, variable: 'A' }] ]) }], ['ext3', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a3', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a3', type: EnvironmentVariableMutatorType.Prepend, variable: 'A' }] ]) }], ['ext4', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a4', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a4', type: EnvironmentVariableMutatorType.Append, variable: 'A' }] ]) }] ])); deepStrictEqual([...merged.getVariableMap(undefined).entries()], [ ['A', [ - { extensionIdentifier: 'ext4', type: EnvironmentVariableMutatorType.Append, value: 'a4', scope: undefined, variable: 'A' }, - { extensionIdentifier: 'ext3', type: EnvironmentVariableMutatorType.Prepend, value: 'a3', scope: undefined, variable: 'A' }, - { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Append, value: 'a2', scope: undefined, variable: 'A' }, - { extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Prepend, value: 'a1', scope: undefined, variable: 'A' } + { extensionIdentifier: 'ext4', type: EnvironmentVariableMutatorType.Append, value: 'a4', variable: 'A' }, + { extensionIdentifier: 'ext3', type: EnvironmentVariableMutatorType.Prepend, value: 'a3', variable: 'A' }, + { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Append, value: 'a2', variable: 'A' }, + { extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Prepend, value: 'a1', variable: 'A' } ]] ]); }); @@ -49,30 +49,30 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, variable: 'A' }] ]) }], ['ext2', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Append, variable: 'A' }] ]) }], ['ext3', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a3', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a3', type: EnvironmentVariableMutatorType.Replace, variable: 'A' }] ]) }], ['ext4', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a4', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a4', type: EnvironmentVariableMutatorType.Append, variable: 'A' }] ]) }] ])); deepStrictEqual([...merged.getVariableMap(undefined).entries()], [ ['A', [ - { extensionIdentifier: 'ext3', type: EnvironmentVariableMutatorType.Replace, value: 'a3', scope: undefined, variable: 'A' }, - { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Append, value: 'a2', scope: undefined, variable: 'A' }, - { extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Prepend, value: 'a1', scope: undefined, variable: 'A' } + { extensionIdentifier: 'ext3', type: EnvironmentVariableMutatorType.Replace, value: 'a3', variable: 'A' }, + { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Append, value: 'a2', variable: 'A' }, + { extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Prepend, value: 'a1', variable: 'A' } ]] ], 'The ext4 entry should be removed as it comes after a Replace'); }); @@ -88,7 +88,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { }], ['ext2', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Append, variable: 'A' }] ]) }], ['ext3', { @@ -98,15 +98,15 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { }], ['ext4', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a4', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a4', type: EnvironmentVariableMutatorType.Append, variable: 'A' }] ]) }] ])); deepStrictEqual([...merged.getVariableMap(scope2).entries()], [ ['A', [ - { extensionIdentifier: 'ext4', type: EnvironmentVariableMutatorType.Append, value: 'a4', scope: undefined, variable: 'A' }, + { extensionIdentifier: 'ext4', type: EnvironmentVariableMutatorType.Append, value: 'a4', variable: 'A' }, { extensionIdentifier: 'ext3', type: EnvironmentVariableMutatorType.Prepend, value: 'a3', scope: scope2, variable: 'A' }, - { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Append, value: 'a2', scope: undefined, variable: 'A' }, + { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Append, value: 'a2', variable: 'A' }, ]] ]); }); @@ -122,7 +122,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { }], ['ext2', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Append, variable: 'A' }] ]) }], ['ext3', { @@ -132,14 +132,14 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { }], ['ext4', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a4', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a4', type: EnvironmentVariableMutatorType.Append, variable: 'A' }] ]) }] ])); deepStrictEqual([...merged.getVariableMap(undefined).entries()], [ ['A', [ - { extensionIdentifier: 'ext4', type: EnvironmentVariableMutatorType.Append, value: 'a4', scope: undefined, variable: 'A' }, - { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Append, value: 'a2', scope: undefined, variable: 'A' }, + { extensionIdentifier: 'ext4', type: EnvironmentVariableMutatorType.Append, value: 'a4', variable: 'A' }, + { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Append, value: 'a2', variable: 'A' }, ]] ]); }); @@ -151,9 +151,9 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged = new MergedEnvironmentVariableCollection(new Map([ ['ext', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], - ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }], - ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'C' }] + ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, variable: 'A' }], + ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, variable: 'B' }], + ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, variable: 'C' }] ]) }] ])); @@ -178,7 +178,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { map: deserializeEnvironmentVariableCollection([ ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: scope1, variable: 'A' }], ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: scope2, variable: 'B' }], - ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'C' }] + ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, variable: 'C' }] ]) }] ])); @@ -199,9 +199,9 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged = new MergedEnvironmentVariableCollection(new Map([ ['ext', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], - ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }], - ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'C' }] + ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, variable: 'A' }], + ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, variable: 'B' }], + ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, variable: 'C' }] ]) }] ])); @@ -218,9 +218,9 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged = new MergedEnvironmentVariableCollection(new Map([ ['ext', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'a' }], - ['b', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'b' }], - ['c', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'c' }] + ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, variable: 'a' }], + ['b', { value: 'b', type: EnvironmentVariableMutatorType.Append, variable: 'b' }], + ['c', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, variable: 'c' }] ]) }] ])); @@ -254,14 +254,14 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged1 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, variable: 'A' }] ]) }] ])); const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, variable: 'A' }] ]) }] ])); @@ -273,7 +273,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, variable: 'A' }] ]) }] ])); @@ -282,7 +282,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { strictEqual(diff.removed.size, 0); const entries = [...diff.added.entries()]; deepStrictEqual(entries, [ - ['A', [{ extensionIdentifier: 'ext1', value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }]] + ['A', [{ extensionIdentifier: 'ext1', value: 'a', type: EnvironmentVariableMutatorType.Replace, variable: 'A' }]] ]); }); @@ -290,15 +290,15 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged1 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, variable: 'A' }] ]) }] ])); const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], - ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }] + ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, variable: 'A' }], + ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, variable: 'B' }] ]) }] ])); @@ -307,7 +307,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { strictEqual(diff.removed.size, 0); const entries = [...diff.added.entries()]; deepStrictEqual(entries, [ - ['B', [{ extensionIdentifier: 'ext1', value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }]] + ['B', [{ extensionIdentifier: 'ext1', value: 'b', type: EnvironmentVariableMutatorType.Append, variable: 'B' }]] ]); }); @@ -315,7 +315,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged1 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, variable: 'A' }] ]) }] ])); @@ -323,12 +323,12 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext2', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Append, variable: 'A' }] ]) }], ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, variable: 'A' }] ]) }] ])); @@ -336,19 +336,19 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { strictEqual(diff.changed.size, 0); strictEqual(diff.removed.size, 0); deepStrictEqual([...diff.added.entries()], [ - ['A', [{ extensionIdentifier: 'ext2', value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }]] + ['A', [{ extensionIdentifier: 'ext2', value: 'a2', type: EnvironmentVariableMutatorType.Append, variable: 'A' }]] ]); const merged3 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Prepend, variable: 'A' }] ]) }], // This entry should get removed ['ext2', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Append, variable: 'A' }] ]) }] ])); @@ -362,20 +362,20 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged1 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, variable: 'A' }] ]) }] ])); const merged4 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, variable: 'A' }] ]) }], // This entry should get removed as it comes after a replace ['ext2', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Append, variable: 'A' }] ]) }] ])); @@ -387,15 +387,15 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged1 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], - ['B', { value: 'b', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'B' }] + ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, variable: 'A' }], + ['B', { value: 'b', type: EnvironmentVariableMutatorType.Replace, variable: 'B' }] ]) }] ])); const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }] + ['A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, variable: 'A' }] ]) }] ])); @@ -403,7 +403,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { strictEqual(diff.changed.size, 0); strictEqual(diff.added.size, 0); deepStrictEqual([...diff.removed.entries()], [ - ['B', [{ extensionIdentifier: 'ext1', value: 'b', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'B' }]] + ['B', [{ extensionIdentifier: 'ext1', value: 'b', type: EnvironmentVariableMutatorType.Replace, variable: 'B' }]] ]); }); @@ -411,16 +411,16 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged1 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], - ['B', { value: 'b', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'B' }] + ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, variable: 'A' }], + ['B', { value: 'b', type: EnvironmentVariableMutatorType.Replace, variable: 'B' }] ]) }] ])); const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], - ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }] + ['A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Replace, variable: 'A' }], + ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, variable: 'B' }] ]) }] ])); @@ -428,8 +428,8 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { strictEqual(diff.added.size, 0); strictEqual(diff.removed.size, 0); deepStrictEqual([...diff.changed.entries()], [ - ['A', [{ extensionIdentifier: 'ext1', value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }]], - ['B', [{ extensionIdentifier: 'ext1', value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }]] + ['A', [{ extensionIdentifier: 'ext1', value: 'a2', type: EnvironmentVariableMutatorType.Replace, variable: 'A' }]], + ['B', [{ extensionIdentifier: 'ext1', value: 'b', type: EnvironmentVariableMutatorType.Append, variable: 'B' }]] ]); }); @@ -437,28 +437,28 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const merged1 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], - ['B', { value: 'b', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'B' }] + ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, variable: 'A' }], + ['B', { value: 'b', type: EnvironmentVariableMutatorType.Prepend, variable: 'B' }] ]) }] ])); const merged2 = new MergedEnvironmentVariableCollection(new Map([ ['ext1', { map: deserializeEnvironmentVariableCollection([ - ['A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], - ['C', { value: 'c', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'C' }] + ['A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Replace, variable: 'A' }], + ['C', { value: 'c', type: EnvironmentVariableMutatorType.Append, variable: 'C' }] ]) }] ])); const diff = merged1.diff(merged2, undefined)!; deepStrictEqual([...diff.added.entries()], [ - ['C', [{ extensionIdentifier: 'ext1', value: 'c', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'C' }]], + ['C', [{ extensionIdentifier: 'ext1', value: 'c', type: EnvironmentVariableMutatorType.Append, variable: 'C' }]], ]); deepStrictEqual([...diff.removed.entries()], [ - ['B', [{ extensionIdentifier: 'ext1', value: 'b', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'B' }]] + ['B', [{ extensionIdentifier: 'ext1', value: 'b', type: EnvironmentVariableMutatorType.Prepend, variable: 'B' }]] ]); deepStrictEqual([...diff.changed.entries()], [ - ['A', [{ extensionIdentifier: 'ext1', value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }]] + ['A', [{ extensionIdentifier: 'ext1', value: 'a2', type: EnvironmentVariableMutatorType.Replace, variable: 'A' }]] ]); }); @@ -469,7 +469,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { ['ext1', { map: deserializeEnvironmentVariableCollection([ ['A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Replace, scope: scope1, variable: 'A' }], - ['B', { value: 'b', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'B' }] + ['B', { value: 'b', type: EnvironmentVariableMutatorType.Prepend, variable: 'B' }] ]) }] ])); @@ -484,7 +484,7 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => { const diff = merged1.diff(merged2, scope1)!; strictEqual(diff.added.size, 0); deepStrictEqual([...diff.removed.entries()], [ - ['B', [{ extensionIdentifier: 'ext1', value: 'b', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'B' }]] + ['B', [{ extensionIdentifier: 'ext1', value: 'b', type: EnvironmentVariableMutatorType.Prepend, variable: 'B' }]] ]); deepStrictEqual([...diff.changed.entries()], [ ['A', [{ extensionIdentifier: 'ext1', value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: scope1, variable: 'A' }]] diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts index 2b31da927a6..c1651e86f9e 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableService.test.ts @@ -49,23 +49,23 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { test('should persist collections to the storage service and be able to restore from them', () => { const collection = new Map(); - collection.set('A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }); - collection.set('B-key', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }); - collection.set('C-key', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'C' }); + collection.set('A-key', { value: 'a', type: EnvironmentVariableMutatorType.Replace, variable: 'A' }); + collection.set('B-key', { value: 'b', type: EnvironmentVariableMutatorType.Append, variable: 'B' }); + collection.set('C-key', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, variable: 'C' }); environmentVariableService.set('ext1', { map: collection, persistent: true }); deepStrictEqual([...environmentVariableService.mergedCollection.getVariableMap(undefined).entries()], [ - ['A', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Replace, value: 'a', scope: undefined, variable: 'A' }]], - ['B', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Append, value: 'b', scope: undefined, variable: 'B' }]], - ['C', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Prepend, value: 'c', scope: undefined, variable: 'C' }]] + ['A', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Replace, value: 'a', variable: 'A' }]], + ['B', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Append, value: 'b', variable: 'B' }]], + ['C', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Prepend, value: 'c', variable: 'C' }]] ]); // Persist with old service, create a new service with the same storage service to verify restore environmentVariableService.persistCollections(); const service2: TestEnvironmentVariableService = instantiationService.createInstance(TestEnvironmentVariableService); deepStrictEqual([...service2.mergedCollection.getVariableMap(undefined).entries()], [ - ['A', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Replace, value: 'a', scope: undefined, variable: 'A' }]], - ['B', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Append, value: 'b', scope: undefined, variable: 'B' }]], - ['C', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Prepend, value: 'c', scope: undefined, variable: 'C' }]] + ['A', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Replace, value: 'a', variable: 'A' }]], + ['B', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Append, value: 'b', variable: 'B' }]], + ['C', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Prepend, value: 'c', variable: 'C' }]] ]); }); @@ -74,21 +74,21 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { const collection1 = new Map(); const collection2 = new Map(); const collection3 = new Map(); - collection1.set('A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }); - collection1.set('B-key', { value: 'b1', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'B' }); - collection2.set('A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }); - collection2.set('B-key', { value: 'b2', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }); - collection3.set('A-key', { value: 'a3', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }); - collection3.set('B-key', { value: 'b3', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'B' }); + collection1.set('A-key', { value: 'a1', type: EnvironmentVariableMutatorType.Append, variable: 'A' }); + collection1.set('B-key', { value: 'b1', type: EnvironmentVariableMutatorType.Replace, variable: 'B' }); + collection2.set('A-key', { value: 'a2', type: EnvironmentVariableMutatorType.Replace, variable: 'A' }); + collection2.set('B-key', { value: 'b2', type: EnvironmentVariableMutatorType.Append, variable: 'B' }); + collection3.set('A-key', { value: 'a3', type: EnvironmentVariableMutatorType.Prepend, variable: 'A' }); + collection3.set('B-key', { value: 'b3', type: EnvironmentVariableMutatorType.Replace, variable: 'B' }); environmentVariableService.set('ext1', { map: collection1, persistent: true }); environmentVariableService.set('ext2', { map: collection2, persistent: true }); environmentVariableService.set('ext3', { map: collection3, persistent: true }); deepStrictEqual([...environmentVariableService.mergedCollection.getVariableMap(undefined).entries()], [ ['A', [ - { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Replace, value: 'a2', scope: undefined, variable: 'A' }, - { extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Append, value: 'a1', scope: undefined, variable: 'A' } + { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Replace, value: 'a2', variable: 'A' }, + { extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Append, value: 'a1', variable: 'A' } ]], - ['B', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Replace, value: 'b1', scope: undefined, variable: 'B' }]] + ['B', [{ extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Replace, value: 'b1', variable: 'B' }]] ]); }); @@ -96,9 +96,9 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { const collection1 = new Map(); const collection2 = new Map(); const collection3 = new Map(); - collection1.set('A-key', { value: ':a1', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'A' }); - collection2.set('A-key', { value: 'a2:', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }); - collection3.set('A-key', { value: 'a3', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }); + collection1.set('A-key', { value: ':a1', type: EnvironmentVariableMutatorType.Append, variable: 'A' }); + collection2.set('A-key', { value: 'a2:', type: EnvironmentVariableMutatorType.Prepend, variable: 'A' }); + collection3.set('A-key', { value: 'a3', type: EnvironmentVariableMutatorType.Replace, variable: 'A' }); environmentVariableService.set('ext1', { map: collection1, persistent: true }); environmentVariableService.set('ext2', { map: collection2, persistent: true }); environmentVariableService.set('ext3', { map: collection3, persistent: true }); @@ -106,9 +106,9 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { // The entries should be ordered in the order they are applied deepStrictEqual([...environmentVariableService.mergedCollection.getVariableMap(undefined).entries()], [ ['A', [ - { extensionIdentifier: 'ext3', type: EnvironmentVariableMutatorType.Replace, value: 'a3', scope: undefined, variable: 'A' }, - { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Prepend, value: 'a2:', scope: undefined, variable: 'A' }, - { extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Append, value: ':a1', scope: undefined, variable: 'A' } + { extensionIdentifier: 'ext3', type: EnvironmentVariableMutatorType.Replace, value: 'a3', variable: 'A' }, + { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Prepend, value: 'a2:', variable: 'A' }, + { extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Append, value: ':a1', variable: 'A' } ]] ]); @@ -125,7 +125,7 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { const collection2 = new Map(); const collection3 = new Map(); collection1.set('A-key', { value: ':a1', type: EnvironmentVariableMutatorType.Append, scope: scope1, variable: 'A' }); - collection2.set('A-key', { value: 'a2:', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'A' }); + collection2.set('A-key', { value: 'a2:', type: EnvironmentVariableMutatorType.Prepend, variable: 'A' }); collection3.set('A-key', { value: 'a3', type: EnvironmentVariableMutatorType.Replace, scope: scope2, variable: 'A' }); environmentVariableService.set('ext1', { map: collection1, persistent: true }); environmentVariableService.set('ext2', { map: collection2, persistent: true }); @@ -134,7 +134,7 @@ suite('EnvironmentVariable - EnvironmentVariableService', () => { // The entries should be ordered in the order they are applied deepStrictEqual([...environmentVariableService.mergedCollection.getVariableMap(scope1).entries()], [ ['A', [ - { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Prepend, value: 'a2:', scope: undefined, variable: 'A' }, + { extensionIdentifier: 'ext2', type: EnvironmentVariableMutatorType.Prepend, value: 'a2:', variable: 'A' }, { extensionIdentifier: 'ext1', type: EnvironmentVariableMutatorType.Append, value: ':a1', scope: scope1, variable: 'A' } ]] ]); diff --git a/src/vs/workbench/contrib/terminal/test/common/environmentVariableShared.test.ts b/src/vs/workbench/contrib/terminal/test/common/environmentVariableShared.test.ts index 6ccf1005e6c..d3fb2177556 100644 --- a/src/vs/workbench/contrib/terminal/test/common/environmentVariableShared.test.ts +++ b/src/vs/workbench/contrib/terminal/test/common/environmentVariableShared.test.ts @@ -10,15 +10,15 @@ import { EnvironmentVariableMutatorType, IEnvironmentVariableMutator } from 'vs/ suite('EnvironmentVariable - deserializeEnvironmentVariableCollection', () => { test('should construct correctly with 3 arguments', () => { const c = deserializeEnvironmentVariableCollection([ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], - ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }], - ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'C' }] + ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, variable: 'A' }], + ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, variable: 'B' }], + ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, variable: 'C' }] ]); const keys = [...c.keys()]; deepStrictEqual(keys, ['A', 'B', 'C']); - deepStrictEqual(c.get('A'), { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }); - deepStrictEqual(c.get('B'), { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }); - deepStrictEqual(c.get('C'), { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'C' }); + deepStrictEqual(c.get('A'), { value: 'a', type: EnvironmentVariableMutatorType.Replace, variable: 'A' }); + deepStrictEqual(c.get('B'), { value: 'b', type: EnvironmentVariableMutatorType.Append, variable: 'B' }); + deepStrictEqual(c.get('C'), { value: 'c', type: EnvironmentVariableMutatorType.Prepend, variable: 'C' }); }); }); @@ -26,13 +26,13 @@ suite('EnvironmentVariable - serializeEnvironmentVariableCollection', () => { test('should correctly serialize the object', () => { const collection = new Map(); deepStrictEqual(serializeEnvironmentVariableCollection(collection), []); - collection.set('A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }); - collection.set('B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }); - collection.set('C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'C' }); + collection.set('A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, variable: 'A' }); + collection.set('B', { value: 'b', type: EnvironmentVariableMutatorType.Append, variable: 'B' }); + collection.set('C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, variable: 'C' }); deepStrictEqual(serializeEnvironmentVariableCollection(collection), [ - ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, scope: undefined, variable: 'A' }], - ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, scope: undefined, variable: 'B' }], - ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, scope: undefined, variable: 'C' }] + ['A', { value: 'a', type: EnvironmentVariableMutatorType.Replace, variable: 'A' }], + ['B', { value: 'b', type: EnvironmentVariableMutatorType.Append, variable: 'B' }], + ['C', { value: 'c', type: EnvironmentVariableMutatorType.Prepend, variable: 'C' }] ]); }); }); From 4176a47c55ee28e5eb4d90b52103730e3eae022b Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Thu, 20 Apr 2023 18:53:24 +0000 Subject: [PATCH 62/68] Change variable resolver to use cwd workspace folder --- .../contrib/terminal/browser/terminalProcessManager.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts index 15dfda7c2cc..68cec851b88 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts @@ -118,7 +118,6 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce private readonly _onRestoreCommands = this._register(new Emitter()); readonly onRestoreCommands = this._onRestoreCommands.event; private _cwdWorkspaceFolder: IWorkspaceFolder | undefined; - private _lastActiveWorkspace: IWorkspaceFolder | undefined; get persistentProcessId(): number | undefined { return this._process?.id; } get shouldPersist(): boolean { return !!this.reconnectionProperties || (this._process ? this._process.shouldPersist : false); } @@ -242,7 +241,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce this.backend = backend; // Create variable resolver - const variableResolver = terminalEnvironment.createVariableResolver(this._lastActiveWorkspace, await this._terminalProfileResolverService.getEnvironment(this.remoteAuthority), this._configurationResolverService); + const variableResolver = terminalEnvironment.createVariableResolver(this._cwdWorkspaceFolder, await this._terminalProfileResolverService.getEnvironment(this.remoteAuthority), this._configurationResolverService); // resolvedUserHome is needed here as remote resolvers can launch local terminals before // they're connected to the remote. @@ -411,8 +410,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce // Fetch any extension environment additions and apply them private async _resolveEnvironment(backend: ITerminalBackend, variableResolver: terminalEnvironment.VariableResolver | undefined, shellLaunchConfig: IShellLaunchConfig): Promise { - const cwdUri = typeof shellLaunchConfig.cwd === 'string' ? URI.parse(shellLaunchConfig.cwd) : shellLaunchConfig.cwd; - const workspaceFolder = cwdUri ? withNullAsUndefined(this._workspaceContextService.getWorkspaceFolder(cwdUri)) : this._lastActiveWorkspace; + const workspaceFolder = getWorkspaceForTerminal(shellLaunchConfig.cwd, this._workspaceContextService, this._historyService); const platformKey = isWindows ? 'windows' : (isMacintosh ? 'osx' : 'linux'); const envFromConfigValue = this._configurationService.getValue(`terminal.integrated.env.${platformKey}`); this._configHelper.showRecommendations(shellLaunchConfig); From 9d68cc55324b46df2bb92c1c99fe0979a26da12e Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Thu, 20 Apr 2023 18:59:36 +0000 Subject: [PATCH 63/68] OOps --- .../workbench/contrib/terminal/browser/terminalProcessManager.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts index 68cec851b88..8b45521762b 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts @@ -7,7 +7,6 @@ import { Emitter, Event } from 'vs/base/common/event'; import { Disposable, dispose, IDisposable, toDisposable } from 'vs/base/common/lifecycle'; import { Schemas } from 'vs/base/common/network'; import { IProcessEnvironment, isMacintosh, isWindows, OperatingSystem, OS } from 'vs/base/common/platform'; -import { withNullAsUndefined } from 'vs/base/common/types'; import { URI } from 'vs/base/common/uri'; import { localize } from 'vs/nls'; import { formatMessageForTerminal } from 'vs/platform/terminal/common/terminalStrings'; From 69e919cc0e234e333217a91bc7e69592f7d8cb51 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Thu, 20 Apr 2023 20:22:46 +0000 Subject: [PATCH 64/68] Delete scope property if `undefined` --- .../terminal/common/environmentVariableCollection.ts | 10 +++++++--- src/vs/workbench/api/common/extHostTerminalService.ts | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/vs/platform/terminal/common/environmentVariableCollection.ts b/src/vs/platform/terminal/common/environmentVariableCollection.ts index 6a6ae1c6ff1..c9858f8a494 100644 --- a/src/vs/platform/terminal/common/environmentVariableCollection.ts +++ b/src/vs/platform/terminal/common/environmentVariableCollection.ts @@ -39,14 +39,18 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa continue; } - // Mutators get applied in the reverse order than they are created - entry.unshift({ + const extensionMutator = { extensionIdentifier, value: mutator.value, type: mutator.type, scope: mutator.scope, variable: mutator.variable - }); + }; + if (!extensionMutator.scope) { + delete extensionMutator.scope; // Convenient for tests + } + // Mutators get applied in the reverse order than they are created + entry.unshift(extensionMutator); next = it.next(); } diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index 7cb1ff22227..522db605583 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -902,6 +902,9 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect } 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) { From d3b1c67267c6da6d3c53d5264b37d6967483a648 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Thu, 20 Apr 2023 20:42:07 +0000 Subject: [PATCH 65/68] Fix terminal integration tests --- .../src/singlefolder-tests/terminal.test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/terminal.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/terminal.test.ts index b76e348e02e..36c1e66c852 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/terminal.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/terminal.test.ts @@ -850,17 +850,17 @@ import { assertNoRpc, poll } from '../utils'; collection.prepend('C', '~c2~'); // Verify get - deepStrictEqual(collection.get('A'), { value: '~a2~', type: EnvironmentVariableMutatorType.Replace }); - deepStrictEqual(collection.get('B'), { value: '~b2~', type: EnvironmentVariableMutatorType.Append }); - deepStrictEqual(collection.get('C'), { value: '~c2~', type: EnvironmentVariableMutatorType.Prepend }); + deepStrictEqual(collection.get('A'), { value: '~a2~', type: EnvironmentVariableMutatorType.Replace, scope: undefined }); + deepStrictEqual(collection.get('B'), { value: '~b2~', type: EnvironmentVariableMutatorType.Append, scope: undefined }); + deepStrictEqual(collection.get('C'), { value: '~c2~', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }); // Verify forEach const entries: [string, EnvironmentVariableMutator][] = []; collection.forEach((v, m) => entries.push([v, m])); deepStrictEqual(entries, [ - ['A', { value: '~a2~', type: EnvironmentVariableMutatorType.Replace }], - ['B', { value: '~b2~', type: EnvironmentVariableMutatorType.Append }], - ['C', { value: '~c2~', type: EnvironmentVariableMutatorType.Prepend }] + ['A', { value: '~a2~', type: EnvironmentVariableMutatorType.Replace, scope: undefined }], + ['B', { value: '~b2~', type: EnvironmentVariableMutatorType.Append, scope: undefined }], + ['C', { value: '~c2~', type: EnvironmentVariableMutatorType.Prepend, scope: undefined }] ]); }); }); From 39da37592d32bd16e2a5546314dcba30a3466255 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Thu, 20 Apr 2023 20:49:53 +0000 Subject: [PATCH 66/68] Attempt to fix smoke tests This reverts commit be89fd23d09ab9dbeb961c63a1208f4259f7d9b4. --- src/vs/server/node/remoteTerminalChannel.ts | 4 +--- .../contrib/terminal/common/remoteTerminalChannel.ts | 5 +---- .../configurationResolver/common/terminalResolver.ts | 4 ++-- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/vs/server/node/remoteTerminalChannel.ts b/src/vs/server/node/remoteTerminalChannel.ts index 209a33f6a6f..fddf20d605d 100644 --- a/src/vs/server/node/remoteTerminalChannel.ts +++ b/src/vs/server/node/remoteTerminalChannel.ts @@ -32,7 +32,6 @@ import { IProductService } from 'vs/platform/product/common/productService'; import { IExtensionManagementService } from 'vs/platform/extensionManagement/common/extensionManagement'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { withNullAsUndefined } from 'vs/base/common/types'; -import { getWorkspaceForTerminal } from 'vs/workbench/services/configurationResolver/common/terminalResolver'; class CustomVariableResolver extends AbstractVariableResolverService { constructor( @@ -239,9 +238,8 @@ export class RemoteTerminalChannel extends Disposable implements IServerChannel< } const envVariableCollections = new Map(entries); const mergedCollection = new MergedEnvironmentVariableCollection(envVariableCollections); - const cwdWorkspaceFolder = getWorkspaceForTerminal(shellLaunchConfig.cwd, args.workspaceContextService, undefined); const workspaceFolder = activeWorkspaceFolder ? withNullAsUndefined(activeWorkspaceFolder) : undefined; - await mergedCollection.applyToProcessEnvironment(env, { workspaceFolder: cwdWorkspaceFolder ?? workspaceFolder }, variableResolver); + await mergedCollection.applyToProcessEnvironment(env, { workspaceFolder }, variableResolver); } // Fork the process and listen for messages diff --git a/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts b/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts index 24fc081a00a..f725cd971b9 100644 --- a/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts +++ b/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts @@ -51,8 +51,6 @@ export interface ICreateTerminalProcessArguments { rows: number; unicodeVersion: '6' | '11'; resolverEnv: { [key: string]: string | null } | undefined; - // TODO: Remove this when last active workspace is fixed - workspaceContextService: IWorkspaceContextService; } export interface ICreateTerminalProcessResult { @@ -184,8 +182,7 @@ export class RemoteTerminalChannelClient implements IPtyHostController { cols, rows, unicodeVersion, - resolverEnv, - workspaceContextService: this._workspaceContextService, + resolverEnv }; return await this._channel.call('$createProcess', args); } diff --git a/src/vs/workbench/services/configurationResolver/common/terminalResolver.ts b/src/vs/workbench/services/configurationResolver/common/terminalResolver.ts index cf19d4d31f8..f6f11802790 100644 --- a/src/vs/workbench/services/configurationResolver/common/terminalResolver.ts +++ b/src/vs/workbench/services/configurationResolver/common/terminalResolver.ts @@ -8,13 +8,13 @@ import { URI } from 'vs/base/common/uri'; import { IWorkspaceContextService, IWorkspaceFolder } from 'vs/platform/workspace/common/workspace'; import { IHistoryService } from 'vs/workbench/services/history/common/history'; -export function getWorkspaceForTerminal(cwd: URI | string | undefined, workspaceContextService: IWorkspaceContextService, historyService: IHistoryService | undefined): IWorkspaceFolder | undefined { +export function getWorkspaceForTerminal(cwd: URI | string | undefined, workspaceContextService: IWorkspaceContextService, historyService: IHistoryService): IWorkspaceFolder | undefined { const cwdUri = typeof cwd === 'string' ? URI.parse(cwd) : cwd; let workspaceFolder = cwdUri ? withNullAsUndefined(workspaceContextService.getWorkspaceFolder(cwdUri)) : undefined; if (!workspaceFolder) { // fallback to last active workspace if cwd is not available or it is not in workspace // TOOD: last active workspace is known to be unreliable, we should remove this fallback eventually - const activeWorkspaceRootUri = historyService?.getLastActiveWorkspaceRoot(); + const activeWorkspaceRootUri = historyService.getLastActiveWorkspaceRoot(); workspaceFolder = activeWorkspaceRootUri ? withNullAsUndefined(workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri)) : undefined; } return workspaceFolder; From 9e4fa31a4af5bde742a14669f15976e2f7ce5c99 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Thu, 20 Apr 2023 21:30:54 +0000 Subject: [PATCH 67/68] Attempt to use correct workspace for remote terminals --- src/vs/server/node/remoteTerminalChannel.ts | 4 +++- .../contrib/terminal/common/remoteTerminalChannel.ts | 7 +++++-- .../configurationResolver/common/terminalResolver.ts | 6 +++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/vs/server/node/remoteTerminalChannel.ts b/src/vs/server/node/remoteTerminalChannel.ts index fddf20d605d..8d4688be9a3 100644 --- a/src/vs/server/node/remoteTerminalChannel.ts +++ b/src/vs/server/node/remoteTerminalChannel.ts @@ -32,6 +32,7 @@ import { IProductService } from 'vs/platform/product/common/productService'; import { IExtensionManagementService } from 'vs/platform/extensionManagement/common/extensionManagement'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { withNullAsUndefined } from 'vs/base/common/types'; +import { getWorkspaceForTerminal } from 'vs/workbench/services/configurationResolver/common/terminalResolver'; class CustomVariableResolver extends AbstractVariableResolverService { constructor( @@ -238,8 +239,9 @@ export class RemoteTerminalChannel extends Disposable implements IServerChannel< } const envVariableCollections = new Map(entries); const mergedCollection = new MergedEnvironmentVariableCollection(envVariableCollections); + const cwdWorkspaceFolder = getWorkspaceForTerminal(shellLaunchConfig.cwd, { getWorkspaceFolder: args.getWorkspaceFolder }, undefined); const workspaceFolder = activeWorkspaceFolder ? withNullAsUndefined(activeWorkspaceFolder) : undefined; - await mergedCollection.applyToProcessEnvironment(env, { workspaceFolder }, variableResolver); + await mergedCollection.applyToProcessEnvironment(env, { workspaceFolder: cwdWorkspaceFolder ?? workspaceFolder }, variableResolver); } // Fork the process and listen for messages diff --git a/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts b/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts index f725cd971b9..6ff391b5ee7 100644 --- a/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts +++ b/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts @@ -10,7 +10,7 @@ import { IChannel } from 'vs/base/parts/ipc/common/ipc'; import { IWorkbenchConfigurationService } from 'vs/workbench/services/configuration/common/configuration'; import { ILogService } from 'vs/platform/log/common/log'; import { IRemoteAuthorityResolverService } from 'vs/platform/remote/common/remoteAuthorityResolver'; -import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; +import { IWorkspaceContextService, IWorkspaceFolder } from 'vs/platform/workspace/common/workspace'; import { serializeEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableShared'; import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver'; import { SideBySideEditor, EditorResourceAccessor } from 'vs/workbench/common/editor'; @@ -51,6 +51,8 @@ export interface ICreateTerminalProcessArguments { rows: number; unicodeVersion: '6' | '11'; resolverEnv: { [key: string]: string | null } | undefined; + // TODO: Remove this when last active workspace is fixed + getWorkspaceFolder: (resource: URI) => IWorkspaceFolder | null; } export interface ICreateTerminalProcessResult { @@ -182,7 +184,8 @@ export class RemoteTerminalChannelClient implements IPtyHostController { cols, rows, unicodeVersion, - resolverEnv + resolverEnv, + getWorkspaceFolder: this._workspaceContextService.getWorkspaceFolder.bind(this._workspaceContextService), }; return await this._channel.call('$createProcess', args); } diff --git a/src/vs/workbench/services/configurationResolver/common/terminalResolver.ts b/src/vs/workbench/services/configurationResolver/common/terminalResolver.ts index f6f11802790..9e82a3420ec 100644 --- a/src/vs/workbench/services/configurationResolver/common/terminalResolver.ts +++ b/src/vs/workbench/services/configurationResolver/common/terminalResolver.ts @@ -5,16 +5,16 @@ import { withNullAsUndefined } from 'vs/base/common/types'; import { URI } from 'vs/base/common/uri'; -import { IWorkspaceContextService, IWorkspaceFolder } from 'vs/platform/workspace/common/workspace'; +import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace'; import { IHistoryService } from 'vs/workbench/services/history/common/history'; -export function getWorkspaceForTerminal(cwd: URI | string | undefined, workspaceContextService: IWorkspaceContextService, historyService: IHistoryService): IWorkspaceFolder | undefined { +export function getWorkspaceForTerminal(cwd: URI | string | undefined, workspaceContextService: { getWorkspaceFolder(resource: URI): IWorkspaceFolder | null }, historyService: IHistoryService | undefined): IWorkspaceFolder | undefined { const cwdUri = typeof cwd === 'string' ? URI.parse(cwd) : cwd; let workspaceFolder = cwdUri ? withNullAsUndefined(workspaceContextService.getWorkspaceFolder(cwdUri)) : undefined; if (!workspaceFolder) { // fallback to last active workspace if cwd is not available or it is not in workspace // TOOD: last active workspace is known to be unreliable, we should remove this fallback eventually - const activeWorkspaceRootUri = historyService.getLastActiveWorkspaceRoot(); + const activeWorkspaceRootUri = historyService?.getLastActiveWorkspaceRoot(); workspaceFolder = activeWorkspaceRootUri ? withNullAsUndefined(workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri)) : undefined; } return workspaceFolder; From 54965bba9d741948697593c585e01c5a86dd6016 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Thu, 20 Apr 2023 21:44:34 +0000 Subject: [PATCH 68/68] Revert "Attempt to use correct workspace for remote terminals" This reverts commit 9e4fa31a4af5bde742a14669f15976e2f7ce5c99. --- src/vs/server/node/remoteTerminalChannel.ts | 4 +--- .../contrib/terminal/common/remoteTerminalChannel.ts | 7 ++----- .../configurationResolver/common/terminalResolver.ts | 6 +++--- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/vs/server/node/remoteTerminalChannel.ts b/src/vs/server/node/remoteTerminalChannel.ts index 8d4688be9a3..fddf20d605d 100644 --- a/src/vs/server/node/remoteTerminalChannel.ts +++ b/src/vs/server/node/remoteTerminalChannel.ts @@ -32,7 +32,6 @@ import { IProductService } from 'vs/platform/product/common/productService'; import { IExtensionManagementService } from 'vs/platform/extensionManagement/common/extensionManagement'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { withNullAsUndefined } from 'vs/base/common/types'; -import { getWorkspaceForTerminal } from 'vs/workbench/services/configurationResolver/common/terminalResolver'; class CustomVariableResolver extends AbstractVariableResolverService { constructor( @@ -239,9 +238,8 @@ export class RemoteTerminalChannel extends Disposable implements IServerChannel< } const envVariableCollections = new Map(entries); const mergedCollection = new MergedEnvironmentVariableCollection(envVariableCollections); - const cwdWorkspaceFolder = getWorkspaceForTerminal(shellLaunchConfig.cwd, { getWorkspaceFolder: args.getWorkspaceFolder }, undefined); const workspaceFolder = activeWorkspaceFolder ? withNullAsUndefined(activeWorkspaceFolder) : undefined; - await mergedCollection.applyToProcessEnvironment(env, { workspaceFolder: cwdWorkspaceFolder ?? workspaceFolder }, variableResolver); + await mergedCollection.applyToProcessEnvironment(env, { workspaceFolder }, variableResolver); } // Fork the process and listen for messages diff --git a/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts b/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts index 6ff391b5ee7..f725cd971b9 100644 --- a/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts +++ b/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts @@ -10,7 +10,7 @@ import { IChannel } from 'vs/base/parts/ipc/common/ipc'; import { IWorkbenchConfigurationService } from 'vs/workbench/services/configuration/common/configuration'; import { ILogService } from 'vs/platform/log/common/log'; import { IRemoteAuthorityResolverService } from 'vs/platform/remote/common/remoteAuthorityResolver'; -import { IWorkspaceContextService, IWorkspaceFolder } from 'vs/platform/workspace/common/workspace'; +import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; import { serializeEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableShared'; import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver'; import { SideBySideEditor, EditorResourceAccessor } from 'vs/workbench/common/editor'; @@ -51,8 +51,6 @@ export interface ICreateTerminalProcessArguments { rows: number; unicodeVersion: '6' | '11'; resolverEnv: { [key: string]: string | null } | undefined; - // TODO: Remove this when last active workspace is fixed - getWorkspaceFolder: (resource: URI) => IWorkspaceFolder | null; } export interface ICreateTerminalProcessResult { @@ -184,8 +182,7 @@ export class RemoteTerminalChannelClient implements IPtyHostController { cols, rows, unicodeVersion, - resolverEnv, - getWorkspaceFolder: this._workspaceContextService.getWorkspaceFolder.bind(this._workspaceContextService), + resolverEnv }; return await this._channel.call('$createProcess', args); } diff --git a/src/vs/workbench/services/configurationResolver/common/terminalResolver.ts b/src/vs/workbench/services/configurationResolver/common/terminalResolver.ts index 9e82a3420ec..f6f11802790 100644 --- a/src/vs/workbench/services/configurationResolver/common/terminalResolver.ts +++ b/src/vs/workbench/services/configurationResolver/common/terminalResolver.ts @@ -5,16 +5,16 @@ import { withNullAsUndefined } from 'vs/base/common/types'; import { URI } from 'vs/base/common/uri'; -import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace'; +import { IWorkspaceContextService, IWorkspaceFolder } from 'vs/platform/workspace/common/workspace'; import { IHistoryService } from 'vs/workbench/services/history/common/history'; -export function getWorkspaceForTerminal(cwd: URI | string | undefined, workspaceContextService: { getWorkspaceFolder(resource: URI): IWorkspaceFolder | null }, historyService: IHistoryService | undefined): IWorkspaceFolder | undefined { +export function getWorkspaceForTerminal(cwd: URI | string | undefined, workspaceContextService: IWorkspaceContextService, historyService: IHistoryService): IWorkspaceFolder | undefined { const cwdUri = typeof cwd === 'string' ? URI.parse(cwd) : cwd; let workspaceFolder = cwdUri ? withNullAsUndefined(workspaceContextService.getWorkspaceFolder(cwdUri)) : undefined; if (!workspaceFolder) { // fallback to last active workspace if cwd is not available or it is not in workspace // TOOD: last active workspace is known to be unreliable, we should remove this fallback eventually - const activeWorkspaceRootUri = historyService?.getLastActiveWorkspaceRoot(); + const activeWorkspaceRootUri = historyService.getLastActiveWorkspaceRoot(); workspaceFolder = activeWorkspaceRootUri ? withNullAsUndefined(workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri)) : undefined; } return workspaceFolder;