Skip to content

Commit dc626ba

Browse files
authored
Merge pull request microsoft#183371 from microsoft/tyriar/183236
Ensure options are filled with defaults, fix equality check
2 parents fe1b2d2 + baa3e22 commit dc626ba

File tree

2 files changed

+37
-15
lines changed

2 files changed

+37
-15
lines changed

extensions/vscode-api-tests/src/singlefolder-tests/terminal.test.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { deepStrictEqual, doesNotThrow, equal, strictEqual, throws } from 'assert';
7-
import { ConfigurationTarget, Disposable, env, EnvironmentVariableCollection, EnvironmentVariableMutator, EnvironmentVariableMutatorType, EnvironmentVariableScope, EventEmitter, ExtensionContext, extensions, ExtensionTerminalOptions, Pseudoterminal, Terminal, TerminalDimensions, TerminalExitReason, TerminalOptions, TerminalState, UIKind, Uri, window, workspace } from 'vscode';
7+
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';
88
import { assertNoRpc, poll } from '../utils';
99

1010
// Disable terminal tests:
@@ -849,16 +849,20 @@ import { assertNoRpc, poll } from '../utils';
849849
collection.append('B', '~b2~');
850850
collection.prepend('C', '~c2~');
851851
// Verify get
852-
deepStrictEqual(collection.get('A'), { value: '~a2~', type: EnvironmentVariableMutatorType.Replace, options: {} });
853-
deepStrictEqual(collection.get('B'), { value: '~b2~', type: EnvironmentVariableMutatorType.Append, options: {} });
854-
deepStrictEqual(collection.get('C'), { value: '~c2~', type: EnvironmentVariableMutatorType.Prepend, options: {} });
852+
const defaultOptions: Required<EnvironmentVariableMutatorOptions> = {
853+
applyAtProcessCreation: true,
854+
applyAtShellIntegration: false
855+
};
856+
deepStrictEqual(collection.get('A'), { value: '~a2~', type: EnvironmentVariableMutatorType.Replace, options: defaultOptions });
857+
deepStrictEqual(collection.get('B'), { value: '~b2~', type: EnvironmentVariableMutatorType.Append, options: defaultOptions });
858+
deepStrictEqual(collection.get('C'), { value: '~c2~', type: EnvironmentVariableMutatorType.Prepend, options: defaultOptions });
855859
// Verify forEach
856860
const entries: [string, EnvironmentVariableMutator][] = [];
857861
collection.forEach((v, m) => entries.push([v, m]));
858862
deepStrictEqual(entries, [
859-
['A', { value: '~a2~', type: EnvironmentVariableMutatorType.Replace, options: {} }],
860-
['B', { value: '~b2~', type: EnvironmentVariableMutatorType.Append, options: {} }],
861-
['C', { value: '~c2~', type: EnvironmentVariableMutatorType.Prepend, options: {} }]
863+
['A', { value: '~a2~', type: EnvironmentVariableMutatorType.Replace, options: defaultOptions }],
864+
['B', { value: '~b2~', type: EnvironmentVariableMutatorType.Append, options: defaultOptions }],
865+
['C', { value: '~c2~', type: EnvironmentVariableMutatorType.Prepend, options: defaultOptions }]
862866
]);
863867
});
864868

@@ -875,18 +879,22 @@ import { assertNoRpc, poll } from '../utils';
875879
collection.append('B', '~b2~');
876880
collection.prepend('C', '~c2~');
877881
// Verify get for scope
882+
const defaultOptions: Required<EnvironmentVariableMutatorOptions> = {
883+
applyAtProcessCreation: true,
884+
applyAtShellIntegration: false
885+
};
878886
const expectedScopedCollection = collection.getScopedEnvironmentVariableCollection(scope);
879-
deepStrictEqual(expectedScopedCollection.get('A'), { value: 'scoped~a2~', type: EnvironmentVariableMutatorType.Replace, options: {} });
880-
deepStrictEqual(expectedScopedCollection.get('B'), { value: 'scoped~b2~', type: EnvironmentVariableMutatorType.Append, options: {} });
881-
deepStrictEqual(expectedScopedCollection.get('C'), { value: 'scoped~c2~', type: EnvironmentVariableMutatorType.Prepend, options: {} });
887+
deepStrictEqual(expectedScopedCollection.get('A'), { value: 'scoped~a2~', type: EnvironmentVariableMutatorType.Replace, options: defaultOptions });
888+
deepStrictEqual(expectedScopedCollection.get('B'), { value: 'scoped~b2~', type: EnvironmentVariableMutatorType.Append, options: defaultOptions });
889+
deepStrictEqual(expectedScopedCollection.get('C'), { value: 'scoped~c2~', type: EnvironmentVariableMutatorType.Prepend, options: defaultOptions });
882890

883891
// Verify forEach
884892
const entries: [string, EnvironmentVariableMutator][] = [];
885893
expectedScopedCollection.forEach((v, m) => entries.push([v, m]));
886894
deepStrictEqual(entries.map(v => v[1]), [
887-
{ value: 'scoped~a2~', type: EnvironmentVariableMutatorType.Replace, options: {} },
888-
{ value: 'scoped~b2~', type: EnvironmentVariableMutatorType.Append, options: {} },
889-
{ value: 'scoped~c2~', type: EnvironmentVariableMutatorType.Prepend, options: {} }
895+
{ value: 'scoped~a2~', type: EnvironmentVariableMutatorType.Replace, options: defaultOptions },
896+
{ value: 'scoped~b2~', type: EnvironmentVariableMutatorType.Append, options: defaultOptions },
897+
{ value: 'scoped~c2~', type: EnvironmentVariableMutatorType.Prepend, options: defaultOptions }
890898
]);
891899
});
892900
});

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -939,9 +939,23 @@ class UnifiedEnvironmentVariableCollection {
939939
}
940940
const key = this.getKey(variable, mutator.scope);
941941
const current = this.map.get(key);
942-
if (!current || current.value !== mutator.value || current.type !== mutator.type || current.scope?.workspaceFolder?.index !== mutator.scope?.workspaceFolder?.index) {
942+
if (
943+
!current ||
944+
current.value !== mutator.value ||
945+
current.type !== mutator.type ||
946+
current.options?.applyAtProcessCreation !== (mutator.options.applyAtProcessCreation ?? true) ||
947+
current.options?.applyAtShellIntegration !== (mutator.options.applyAtShellIntegration ?? false) ||
948+
current.scope?.workspaceFolder?.index !== mutator.scope?.workspaceFolder?.index
949+
) {
943950
const key = this.getKey(variable, mutator.scope);
944-
const value: IEnvironmentVariableMutator = { variable, ...mutator };
951+
const value: IEnvironmentVariableMutator = {
952+
variable,
953+
...mutator,
954+
options: {
955+
applyAtProcessCreation: mutator.options.applyAtProcessCreation ?? true,
956+
applyAtShellIntegration: mutator.options.applyAtShellIntegration ?? false,
957+
}
958+
};
945959
this.map.set(key, value);
946960
this._onDidChangeCollection.fire();
947961
}

0 commit comments

Comments
 (0)