From 37ad81ccd96b6f814edce6b427ba202c8d98b42e Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Wed, 24 May 2023 15:02:18 -0700 Subject: [PATCH] Ensure options are filled with defaults, fix equality check Fixes #183236 --- .../src/singlefolder-tests/terminal.test.ts | 18 +++++++++++------- .../api/common/extHostTerminalService.ts | 18 ++++++++++++++++-- 2 files changed, 27 insertions(+), 9 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 869db491059..ec60b5568ef 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/terminal.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/terminal.test.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { deepStrictEqual, doesNotThrow, equal, strictEqual, throws } from 'assert'; -import { ConfigurationTarget, Disposable, env, EnvironmentVariableCollection, EnvironmentVariableMutator, EnvironmentVariableMutatorType, EnvironmentVariableScope, EventEmitter, ExtensionContext, extensions, ExtensionTerminalOptions, Pseudoterminal, Terminal, TerminalDimensions, TerminalExitReason, TerminalOptions, TerminalState, UIKind, Uri, window, workspace } from 'vscode'; +import { ConfigurationTarget, Disposable, env, EnvironmentVariableCollection, EnvironmentVariableMutator, EnvironmentVariableMutatorOptions, EnvironmentVariableMutatorType, EnvironmentVariableScope, EventEmitter, ExtensionContext, extensions, ExtensionTerminalOptions, Pseudoterminal, Terminal, TerminalDimensions, TerminalExitReason, TerminalOptions, TerminalState, UIKind, Uri, window, workspace } from 'vscode'; import { assertNoRpc, poll } from '../utils'; // Disable terminal tests: @@ -849,16 +849,20 @@ import { assertNoRpc, poll } from '../utils'; collection.append('B', '~b2~'); collection.prepend('C', '~c2~'); // Verify get - deepStrictEqual(collection.get('A'), { value: '~a2~', type: EnvironmentVariableMutatorType.Replace, options: {} }); - deepStrictEqual(collection.get('B'), { value: '~b2~', type: EnvironmentVariableMutatorType.Append, options: {} }); - deepStrictEqual(collection.get('C'), { value: '~c2~', type: EnvironmentVariableMutatorType.Prepend, options: {} }); + const defaultOptions: Required = { + applyAtProcessCreation: true, + applyAtShellIntegration: false + }; + deepStrictEqual(collection.get('A'), { value: '~a2~', type: EnvironmentVariableMutatorType.Replace, options: defaultOptions }); + deepStrictEqual(collection.get('B'), { value: '~b2~', type: EnvironmentVariableMutatorType.Append, options: defaultOptions }); + deepStrictEqual(collection.get('C'), { value: '~c2~', type: EnvironmentVariableMutatorType.Prepend, options: defaultOptions }); // Verify forEach const entries: [string, EnvironmentVariableMutator][] = []; collection.forEach((v, m) => entries.push([v, m])); deepStrictEqual(entries, [ - ['A', { value: '~a2~', type: EnvironmentVariableMutatorType.Replace, options: {} }], - ['B', { value: '~b2~', type: EnvironmentVariableMutatorType.Append, options: {} }], - ['C', { value: '~c2~', type: EnvironmentVariableMutatorType.Prepend, options: {} }] + ['A', { value: '~a2~', type: EnvironmentVariableMutatorType.Replace, options: defaultOptions }], + ['B', { value: '~b2~', type: EnvironmentVariableMutatorType.Append, options: defaultOptions }], + ['C', { value: '~c2~', type: EnvironmentVariableMutatorType.Prepend, options: defaultOptions }] ]); }); diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index d20f3a89f67..1cb4c5890d1 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -935,9 +935,23 @@ class UnifiedEnvironmentVariableCollection { } 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) { + if ( + !current || + current.value !== mutator.value || + current.type !== mutator.type || + current.options?.applyAtProcessCreation !== (mutator.options.applyAtProcessCreation ?? true) || + current.options?.applyAtShellIntegration !== (mutator.options.applyAtShellIntegration ?? false) || + current.scope?.workspaceFolder?.index !== mutator.scope?.workspaceFolder?.index + ) { const key = this.getKey(variable, mutator.scope); - const value: IEnvironmentVariableMutator = { variable, ...mutator }; + const value: IEnvironmentVariableMutator = { + variable, + ...mutator, + options: { + applyAtProcessCreation: mutator.options.applyAtProcessCreation ?? true, + applyAtShellIntegration: mutator.options.applyAtShellIntegration ?? false, + } + }; this.map.set(key, value); this._onDidChangeCollection.fire(); }