src/vs/workbench/contrib/terminal/common/environmentVariableService.ts

126 LOC · 114 covered · 12 uncovered · 10 ranges · 5 concepts · 2 introducers · 4 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the filesrc/vs/base/common/decorators.ts · 131 LOCcommon/decorators.tssrc/vs/platform/instantiation/test/common/instantiationServiceMock.ts · 198 LOCcommon/instantiationServ…src/vs/platform/terminal/common/environmentVariableShared.ts · 42 LOCcommon/environmentVariab…src/vs/workbench/contrib/terminal/common/terminalStorageKeys.ts · 17 LOCcommon/terminalStorageKe…src/vs/workbench/services/history/common/history.ts · 142 LOCcommon/history.tsenvironmentVariableService.test|title=EnvironmentVariable - EnvironmentVariableService mergedCollection should correctly apply the workspace specific environment values from multiple extension contributions in the correct order|occurrence=1 · 0 introduced LOCenvironmentVariableServi…environmentVariableService.test|title=EnvironmentVariable - EnvironmentVariableService mergedCollection should correctly apply the environment values from multiple extension contributions in the correct order|occurrence=1 · 0 introduced LOCenvironmentVariableServi…environmentVariableService.ts ×4 · 21 introduced LOCenvironmentVariableServi…environmentVariableService.test|title=EnvironmentVariable - EnvironmentVariableService mergedCollection should overwrite any other variable with the first extension that replaces|occurrence=1 · 0 introduced LOCenvironmentVariableServi…environmentVariableService.ts ×6 · 275 introduced LOCenvironmentVariableServi…environmentVariableService.test|title=EnvironmentVariable - EnvironmentVariableService mergedCollection should correctly apply the environment values from multiple extension contributions in the correct order|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/terminal/test/common/environmentVariableService.test|title=EnvironmentVariable - EnvironmentVariableService mergedCollection should correctly apply the environment values from multiple extension contributions in the correct order|occurrence=1environmentVariableServi…environmentVariableService.test|title=EnvironmentVariable - EnvironmentVariableService mergedCollection should correctly apply the workspace specific environment values from multiple extension contributions in the correct order|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/terminal/test/common/environmentVariableService.test|title=EnvironmentVariable - EnvironmentVariableService mergedCollection should correctly apply the workspace specific environment values from multiple extension contributions in the correct order|occurrence=1environmentVariableServi…environmentVariableService.test|title=EnvironmentVariable - EnvironmentVariableService mergedCollection should overwrite any other variable with the first extension that replaces|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/terminal/test/common/environmentVariableService.test|title=EnvironmentVariable - EnvironmentVariableService mergedCollection should overwrite any other variable with the first extension that replaces|occurrence=1environmentVariableServi…environmentVariableService.test|title=EnvironmentVariable - EnvironmentVariableService should persist collections to the storage service and be able to restore from them|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/terminal/test/common/environmentVariableService.test|title=EnvironmentVariable - EnvironmentVariableService should persist collections to the storage service and be able to restore from them|occurrence=1environmentVariableServi…Focused file · src/vs/workbench/contrib/terminal/common/environmentVariableService.ts · 126 LOCcommon/environmentVariab…

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- environmentVariableService.ts ×6
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { Event, Emitter } from '../../../../base/common/event.js';
7 > import { debounce, throttle } from '../../../../base/common/decorators.js';
8 > import { IStorageService, StorageScope, StorageTarget } from '../../../../platform/storage/common/storage.js';
9 > import { IExtensionService } from '../../../services/extensions/common/extensions.js';
10 > import { MergedEnvironmentVariableCollection } from '../../../../platform/terminal/common/environmentVariableCollection.js';
11 > import { deserializeEnvironmentDescriptionMap, deserializeEnvironmentVariableCollection, serializeEnvironmentDescriptionMap, serializeEnvironmentVariableCollection } from '../../../../platform/terminal/common/environmentVariableShared.js';
12 > import { IEnvironmentVariableCollectionWithPersistence, IEnvironmentVariableService } from './environmentVariable.js';
13 > import { TerminalStorageKeys } from './terminalStorageKeys.js';
14 > import { IMergedEnvironmentVariableCollection, ISerializableEnvironmentDescriptionMap, ISerializableEnvironmentVariableCollection } from '../../../../platform/terminal/common/environmentVariable.js';
15 > import { Disposable } from '../../../../base/common/lifecycle.js';
16 >
17 > interface ISerializableExtensionEnvironmentVariableCollection {
18 > extensionIdentifier: string;
19 > collection: ISerializableEnvironmentVariableCollection;
20 > description?: ISerializableEnvironmentDescriptionMap;
21 > }
22 >
23 > /**
24 > * Tracks and persists environment variable collections as defined by extensions.
25 > */
26 > export class EnvironmentVariableService extends Disposable implements IEnvironmentVariableService {
27 > declare readonly _serviceBrand: undefined;
28 >
29 > collections: Map<string, IEnvironmentVariableCollectionWithPersistence> = new Map();
30 > mergedCollection: IMergedEnvironmentVariableCollection;
31 >
32 > private readonly _onDidChangeCollections = this._register(new Emitter<IMergedEnvironmentVariableCollection>());
33 > get onDidChangeCollections(): Event<IMergedEnvironmentVariableCollection> { return this._onDidChangeCollections.event; }
34 >
35 > constructor(
36 > @IExtensionService private readonly _extensionService: IExtensionService,
37 > @IStorageService private readonly _storageService: IStorageService
38 > ) {
39 > super();
40 >
41 > this._storageService.remove(TerminalStorageKeys.DeprecatedEnvironmentVariableCollections, StorageScope.WORKSPACE);
42 > const serializedPersistedCollections = this._storageService.get(TerminalStorageKeys.EnvironmentVariableCollections, StorageScope.WORKSPACE);
43 > if (serializedPersistedCollections) {
44 > const collectionsJson: ISerializableExtensionEnvironmentVariableCollection[] = JSON.parse(serializedPersistedCollections); environmentVariableService.ts ×4
45 > collectionsJson.forEach(c => this.collections.set(c.extensionIdentifier, {
46 > persistent: true,
47 > map: deserializeEnvironmentVariableCollection(c.collection),
48 > descriptionMap: deserializeEnvironmentDescriptionMap(c.description)
49 > }));
50 >
51 > // Asynchronously invalidate collections where extensions have been uninstalled, this is
52 > // async to avoid making all functions on the service synchronous and because extensions
53 > // being uninstalled is rare.
54 > this._invalidateExtensionCollections();
55 > }
56 > this.mergedCollection = this._resolveMergedCollection(); environmentVariableService.ts ×6
57 >
58 > // Listen for uninstalled/disabled extensions
59 > this._register(this._extensionService.onDidChangeExtensions(() => this._invalidateExtensionCollections()));
60 > }
61 >
62 > set(extensionIdentifier: string, collection: IEnvironmentVariableCollectionWithPersistence): void {
63 > this.collections.set(extensionIdentifier, collection);
64 > this._updateCollections();
65 > }
66 >
67 > delete(extensionIdentifier: string): void {
68 this.collections.delete(extensionIdentifier);
69 this._updateCollections();
70 }
72 > private _updateCollections(): void {
73 > this._persistCollectionsEventually();
74 > this.mergedCollection = this._resolveMergedCollection();
75 > this._notifyCollectionUpdatesEventually();
76 > }
77 >
78 > @throttle(1000)
79 > private _persistCollectionsEventually(): void {
80 > this._persistCollections();
81 > }
82 >
83 > protected _persistCollections(): void {
84 > const collectionsJson: ISerializableExtensionEnvironmentVariableCollection[] = [];
85 > this.collections.forEach((collection, extensionIdentifier) => {
86 > if (collection.persistent) {
87 > collectionsJson.push({
88 > extensionIdentifier,
89 > collection: serializeEnvironmentVariableCollection(this.collections.get(extensionIdentifier)!.map),
90 > description: serializeEnvironmentDescriptionMap(collection.descriptionMap)
91 > });
92 > }
93 > });
94 > const stringifiedJson = JSON.stringify(collectionsJson);
95 > this._storageService.store(TerminalStorageKeys.EnvironmentVariableCollections, stringifiedJson, StorageScope.WORKSPACE, StorageTarget.MACHINE);
96 > }
97 >
98 > @debounce(1000)
99 > private _notifyCollectionUpdatesEventually(): void {
100 this._notifyCollectionUpdates();
101 }
103 > protected _notifyCollectionUpdates(): void {
104 this._onDidChangeCollections.fire(this.mergedCollection);
105 }
107 > private _resolveMergedCollection(): IMergedEnvironmentVariableCollection {
108 > return new MergedEnvironmentVariableCollection(this.collections);
109 > }
110 >
111 > private async _invalidateExtensionCollections(): Promise<void> {
112 > await this._extensionService.whenInstalledExtensionsRegistered(); environmentVariableService.ts ×4
113 > const registeredExtensions = this._extensionService.extensions;
114 > let changes = false;
115 > this.collections.forEach((_, extensionIdentifier) => {
116 > const isExtensionRegistered = registeredExtensions.some(r => r.identifier.value === extensionIdentifier);
117 > if (!isExtensionRegistered) {
118 this.collections.delete(extensionIdentifier);
119 changes = true;
120 }
122 > if (changes) {
123 this._updateCollections();
124 }