@codingame/monaco-vscode-configuration-service-override 4.1.0 → 4.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1201 @@
1
+ import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
2
+ import { URI } from 'vscode/vscode/vs/base/common/uri';
3
+ import { Event, Emitter } from 'vscode/vscode/vs/base/common/event';
4
+ import { ResourceMap } from 'vscode/vscode/vs/base/common/map';
5
+ import { equals } from 'vscode/vscode/vs/base/common/objects';
6
+ import { Disposable, DisposableStore } from 'vscode/vscode/vs/base/common/lifecycle';
7
+ import { Delayer, Barrier, Queue, Promises } from 'vscode/vscode/vs/base/common/async';
8
+ import { Extensions as Extensions$2 } from 'vscode/vscode/vs/platform/jsonschemas/common/jsonContributionRegistry';
9
+ import { IWorkspaceContextService, isWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier, isWorkspaceFolder, toWorkspaceFolder, Workspace as Workspace$1 } from 'vscode/vscode/vs/platform/workspace/common/workspace';
10
+ import { ConfigurationModel, mergeChanges, ConfigurationChangeEvent } from 'vscode/vscode/vs/platform/configuration/common/configurationModels';
11
+ import { IConfigurationService, isConfigurationOverrides, isConfigurationUpdateOverrides, ConfigurationTargetToString } from 'vscode/vscode/vs/platform/configuration/common/configuration';
12
+ import { NullPolicyConfiguration, PolicyConfiguration } from 'vscode/vscode/vs/platform/configuration/common/configurations';
13
+ import { Configuration } from '../common/configurationModels.js';
14
+ import { APPLY_ALL_PROFILES_SETTING, defaultSettingsSchemaId, userSettingsSchemaId, profileSettingsSchemaId, machineSettingsSchemaId, workspaceSettingsSchemaId, folderSettingsSchemaId, FOLDER_CONFIG_FOLDER_NAME, LOCAL_MACHINE_SCOPES, LOCAL_MACHINE_PROFILE_SCOPES, PROFILE_SCOPES } from 'vscode/vscode/vs/workbench/services/configuration/common/configuration';
15
+ import { Registry } from 'vscode/vscode/vs/platform/registry/common/platform';
16
+ import { Extensions, allSettings, applicationSettings, windowSettings, resourceSettings, machineSettings, machineOverridableSettings, OVERRIDE_PROPERTY_PATTERN, resourceLanguageSettingsSchemaId, configurationDefaultsSchemaId, keyFromOverrideIdentifiers } from 'vscode/vscode/vs/platform/configuration/common/configurationRegistry';
17
+ import { isStoredWorkspaceFolder, toWorkspaceFolders, getStoredWorkspaceFolder } from 'vscode/vscode/vs/platform/workspaces/common/workspaces';
18
+ import { ConfigurationEditing } from '../common/configurationEditing.js';
19
+ import { DefaultConfiguration, UserConfiguration, RemoteUserConfiguration, WorkspaceConfiguration, ApplicationConfiguration, FolderConfiguration } from './configuration.js';
20
+ import { mark } from 'vscode/vscode/vs/base/common/performance';
21
+ import { IWorkbenchEnvironmentService } from 'vscode/vscode/vs/workbench/services/environment/common/environmentService';
22
+ import { Extensions as Extensions$1, registerWorkbenchContribution2 } from 'vscode/vscode/vs/workbench/common/contributions';
23
+ import { ILifecycleService } from 'vscode/vscode/vs/workbench/services/lifecycle/common/lifecycle';
24
+ import { toErrorMessage } from 'vscode/vscode/vs/base/common/errorMessage';
25
+ import { IWorkspaceTrustManagementService } from 'vscode/vscode/vs/platform/workspace/common/workspaceTrust';
26
+ import { distinct, delta, equals as equals$1 } from 'vscode/vscode/vs/base/common/arrays';
27
+ import { IExtensionService } from 'vscode/vscode/vs/workbench/services/extensions/common/extensions';
28
+ import { IWorkbenchAssignmentService } from 'vscode/vscode/vs/workbench/services/assignment/common/assignmentService';
29
+ import { isUndefined } from 'vscode/vscode/vs/base/common/types';
30
+ import { localizeWithPath } from 'vscode/vscode/vs/nls';
31
+ import { NullPolicyService } from 'vscode/vscode/vs/platform/policy/common/policy';
32
+ import { IJSONEditingService } from 'vscode/vscode/vs/workbench/services/configuration/common/jsonEditing';
33
+ import { workbenchConfigurationNodeBase } from 'vscode/vscode/vs/workbench/common/configuration';
34
+ import { mainWindow } from 'vscode/vscode/vs/base/browser/window';
35
+ import { runWhenWindowIdle } from 'vscode/vscode/vs/base/browser/dom';
36
+
37
+ function getLocalUserConfigurationScopes(userDataProfile, hasRemote) {
38
+ return (userDataProfile.isDefault || userDataProfile.useDefaultFlags?.settings)
39
+ ? hasRemote ? LOCAL_MACHINE_SCOPES : undefined
40
+ : hasRemote ? LOCAL_MACHINE_PROFILE_SCOPES : PROFILE_SCOPES;
41
+ }
42
+ class Workspace extends Workspace$1 {
43
+ constructor() {
44
+ super(...arguments);
45
+ this.initialized = false;
46
+ }
47
+ }
48
+ class WorkspaceService extends Disposable {
49
+ get restrictedSettings() { return this._restrictedSettings; }
50
+ constructor({ remoteAuthority, configurationCache }, environmentService, userDataProfileService, userDataProfilesService, fileService, remoteAgentService, uriIdentityService, logService, policyService) {
51
+ super();
52
+ this.userDataProfileService = userDataProfileService;
53
+ this.userDataProfilesService = userDataProfilesService;
54
+ this.fileService = fileService;
55
+ this.remoteAgentService = remoteAgentService;
56
+ this.uriIdentityService = uriIdentityService;
57
+ this.logService = logService;
58
+ this.initialized = false;
59
+ this.applicationConfiguration = null;
60
+ this.remoteUserConfiguration = null;
61
+ this._onDidChangeConfiguration = this._register(( new Emitter()));
62
+ this.onDidChangeConfiguration = this._onDidChangeConfiguration.event;
63
+ this._onWillChangeWorkspaceFolders = this._register(( new Emitter()));
64
+ this.onWillChangeWorkspaceFolders = this._onWillChangeWorkspaceFolders.event;
65
+ this._onDidChangeWorkspaceFolders = this._register(( new Emitter()));
66
+ this.onDidChangeWorkspaceFolders = this._onDidChangeWorkspaceFolders.event;
67
+ this._onDidChangeWorkspaceName = this._register(( new Emitter()));
68
+ this.onDidChangeWorkspaceName = this._onDidChangeWorkspaceName.event;
69
+ this._onDidChangeWorkbenchState = this._register(( new Emitter()));
70
+ this.onDidChangeWorkbenchState = this._onDidChangeWorkbenchState.event;
71
+ this.isWorkspaceTrusted = true;
72
+ this._restrictedSettings = { default: [] };
73
+ this._onDidChangeRestrictedSettings = this._register(( new Emitter()));
74
+ this.onDidChangeRestrictedSettings = this._onDidChangeRestrictedSettings.event;
75
+ this.configurationRegistry = ( Registry.as(Extensions.Configuration));
76
+ this.initRemoteUserConfigurationBarrier = ( new Barrier());
77
+ this.completeWorkspaceBarrier = ( new Barrier());
78
+ this.defaultConfiguration = this._register(( new DefaultConfiguration(configurationCache, environmentService)));
79
+ this.policyConfiguration = policyService instanceof NullPolicyService ? ( new NullPolicyConfiguration()) : this._register(( new PolicyConfiguration(this.defaultConfiguration, policyService, logService)));
80
+ this.configurationCache = configurationCache;
81
+ this._configuration = ( new Configuration(
82
+ this.defaultConfiguration.configurationModel,
83
+ this.policyConfiguration.configurationModel,
84
+ ( new ConfigurationModel()),
85
+ ( new ConfigurationModel()),
86
+ ( new ConfigurationModel()),
87
+ ( new ConfigurationModel()),
88
+ ( new ResourceMap()),
89
+ ( new ConfigurationModel()),
90
+ ( new ResourceMap()),
91
+ this.workspace
92
+ ));
93
+ this.applicationConfigurationDisposables = this._register(( new DisposableStore()));
94
+ this.createApplicationConfiguration();
95
+ this.localUserConfiguration = this._register(( new UserConfiguration(
96
+ userDataProfileService.currentProfile.settingsResource,
97
+ userDataProfileService.currentProfile.tasksResource,
98
+ { scopes: getLocalUserConfigurationScopes(userDataProfileService.currentProfile, !!remoteAuthority) },
99
+ fileService,
100
+ uriIdentityService,
101
+ logService
102
+ )));
103
+ this.cachedFolderConfigs = ( new ResourceMap());
104
+ this._register(this.localUserConfiguration.onDidChangeConfiguration(userConfiguration => this.onLocalUserConfigurationChanged(userConfiguration)));
105
+ if (remoteAuthority) {
106
+ const remoteUserConfiguration = this.remoteUserConfiguration = this._register(( new RemoteUserConfiguration(
107
+ remoteAuthority,
108
+ configurationCache,
109
+ fileService,
110
+ uriIdentityService,
111
+ remoteAgentService
112
+ )));
113
+ this._register(remoteUserConfiguration.onDidInitialize(remoteUserConfigurationModel => {
114
+ this._register(remoteUserConfiguration.onDidChangeConfiguration(remoteUserConfigurationModel => this.onRemoteUserConfigurationChanged(remoteUserConfigurationModel)));
115
+ this.onRemoteUserConfigurationChanged(remoteUserConfigurationModel);
116
+ this.initRemoteUserConfigurationBarrier.open();
117
+ }));
118
+ }
119
+ else {
120
+ this.initRemoteUserConfigurationBarrier.open();
121
+ }
122
+ this.workspaceConfiguration = this._register(( new WorkspaceConfiguration(configurationCache, fileService, uriIdentityService, logService)));
123
+ this._register(this.workspaceConfiguration.onDidUpdateConfiguration(fromCache => {
124
+ this.onWorkspaceConfigurationChanged(fromCache).then(() => {
125
+ this.workspace.initialized = this.workspaceConfiguration.initialized;
126
+ this.checkAndMarkWorkspaceComplete(fromCache);
127
+ });
128
+ }));
129
+ this._register(this.defaultConfiguration.onDidChangeConfiguration(({ properties, defaults }) => this.onDefaultConfigurationChanged(defaults, properties)));
130
+ this._register(this.policyConfiguration.onDidChangeConfiguration(configurationModel => this.onPolicyConfigurationChanged(configurationModel)));
131
+ this._register(userDataProfileService.onDidChangeCurrentProfile(e => this.onUserDataProfileChanged(e)));
132
+ this.workspaceEditingQueue = ( new Queue());
133
+ }
134
+ createApplicationConfiguration() {
135
+ this.applicationConfigurationDisposables.clear();
136
+ if (this.userDataProfileService.currentProfile.isDefault || this.userDataProfileService.currentProfile.useDefaultFlags?.settings) {
137
+ this.applicationConfiguration = null;
138
+ }
139
+ else {
140
+ this.applicationConfiguration = this.applicationConfigurationDisposables.add(this._register(( new ApplicationConfiguration(this.userDataProfilesService, this.fileService, this.uriIdentityService))));
141
+ this.applicationConfigurationDisposables.add(this.applicationConfiguration.onDidChangeConfiguration(configurationModel => this.onApplicationConfigurationChanged(configurationModel)));
142
+ }
143
+ }
144
+ async getCompleteWorkspace() {
145
+ await this.completeWorkspaceBarrier.wait();
146
+ return this.getWorkspace();
147
+ }
148
+ getWorkspace() {
149
+ return this.workspace;
150
+ }
151
+ getWorkbenchState() {
152
+ if (this.workspace.configuration) {
153
+ return 3 ;
154
+ }
155
+ if (this.workspace.folders.length === 1) {
156
+ return 2 ;
157
+ }
158
+ return 1 ;
159
+ }
160
+ getWorkspaceFolder(resource) {
161
+ return this.workspace.getFolder(resource);
162
+ }
163
+ addFolders(foldersToAdd, index) {
164
+ return this.updateFolders(foldersToAdd, [], index);
165
+ }
166
+ removeFolders(foldersToRemove) {
167
+ return this.updateFolders([], foldersToRemove);
168
+ }
169
+ async updateFolders(foldersToAdd, foldersToRemove, index) {
170
+ return this.workspaceEditingQueue.queue(() => this.doUpdateFolders(foldersToAdd, foldersToRemove, index));
171
+ }
172
+ isInsideWorkspace(resource) {
173
+ return !!this.getWorkspaceFolder(resource);
174
+ }
175
+ isCurrentWorkspace(workspaceIdOrFolder) {
176
+ switch (this.getWorkbenchState()) {
177
+ case 2 : {
178
+ let folderUri = undefined;
179
+ if (URI.isUri(workspaceIdOrFolder)) {
180
+ folderUri = workspaceIdOrFolder;
181
+ }
182
+ else if (isSingleFolderWorkspaceIdentifier(workspaceIdOrFolder)) {
183
+ folderUri = workspaceIdOrFolder.uri;
184
+ }
185
+ return URI.isUri(folderUri) && this.uriIdentityService.extUri.isEqual(folderUri, this.workspace.folders[0].uri);
186
+ }
187
+ case 3 :
188
+ return isWorkspaceIdentifier(workspaceIdOrFolder) && this.workspace.id === workspaceIdOrFolder.id;
189
+ }
190
+ return false;
191
+ }
192
+ async doUpdateFolders(foldersToAdd, foldersToRemove, index) {
193
+ if (this.getWorkbenchState() !== 3 ) {
194
+ return Promise.resolve(undefined);
195
+ }
196
+ if (foldersToAdd.length + foldersToRemove.length === 0) {
197
+ return Promise.resolve(undefined);
198
+ }
199
+ let foldersHaveChanged = false;
200
+ let currentWorkspaceFolders = this.getWorkspace().folders;
201
+ let newStoredFolders = ( currentWorkspaceFolders.map(f => f.raw)).filter((folder, index) => {
202
+ if (!isStoredWorkspaceFolder(folder)) {
203
+ return true;
204
+ }
205
+ return !this.contains(foldersToRemove, currentWorkspaceFolders[index].uri);
206
+ });
207
+ foldersHaveChanged = currentWorkspaceFolders.length !== newStoredFolders.length;
208
+ if (foldersToAdd.length) {
209
+ const workspaceConfigPath = this.getWorkspace().configuration;
210
+ const workspaceConfigFolder = this.uriIdentityService.extUri.dirname(workspaceConfigPath);
211
+ currentWorkspaceFolders = toWorkspaceFolders(newStoredFolders, workspaceConfigPath, this.uriIdentityService.extUri);
212
+ const currentWorkspaceFolderUris = ( currentWorkspaceFolders.map(folder => folder.uri));
213
+ const storedFoldersToAdd = [];
214
+ for (const folderToAdd of foldersToAdd) {
215
+ const folderURI = folderToAdd.uri;
216
+ if (this.contains(currentWorkspaceFolderUris, folderURI)) {
217
+ continue;
218
+ }
219
+ try {
220
+ const result = await this.fileService.stat(folderURI);
221
+ if (!result.isDirectory) {
222
+ continue;
223
+ }
224
+ }
225
+ catch (e) { }
226
+ storedFoldersToAdd.push(getStoredWorkspaceFolder(folderURI, false, folderToAdd.name, workspaceConfigFolder, this.uriIdentityService.extUri));
227
+ }
228
+ if (storedFoldersToAdd.length > 0) {
229
+ foldersHaveChanged = true;
230
+ if (typeof index === 'number' && index >= 0 && index < newStoredFolders.length) {
231
+ newStoredFolders = newStoredFolders.slice(0);
232
+ newStoredFolders.splice(index, 0, ...storedFoldersToAdd);
233
+ }
234
+ else {
235
+ newStoredFolders = [...newStoredFolders, ...storedFoldersToAdd];
236
+ }
237
+ }
238
+ }
239
+ if (foldersHaveChanged) {
240
+ return this.setFolders(newStoredFolders);
241
+ }
242
+ return Promise.resolve(undefined);
243
+ }
244
+ async setFolders(folders) {
245
+ if (!this.instantiationService) {
246
+ throw new Error('Cannot update workspace folders because workspace service is not yet ready to accept writes.');
247
+ }
248
+ await this.instantiationService.invokeFunction(accessor => this.workspaceConfiguration.setFolders(folders, accessor.get(IJSONEditingService)));
249
+ return this.onWorkspaceConfigurationChanged(false);
250
+ }
251
+ contains(resources, toCheck) {
252
+ return ( resources.some(resource => this.uriIdentityService.extUri.isEqual(resource, toCheck)));
253
+ }
254
+ getConfigurationData() {
255
+ return this._configuration.toData();
256
+ }
257
+ getValue(arg1, arg2) {
258
+ const section = typeof arg1 === 'string' ? arg1 : undefined;
259
+ const overrides = isConfigurationOverrides(arg1) ? arg1 : isConfigurationOverrides(arg2) ? arg2 : undefined;
260
+ return this._configuration.getValue(section, overrides);
261
+ }
262
+ async updateValue(key, value, arg3, arg4, options) {
263
+ const overrides = isConfigurationUpdateOverrides(arg3) ? arg3
264
+ : isConfigurationOverrides(arg3) ? { resource: arg3.resource, overrideIdentifiers: arg3.overrideIdentifier ? [arg3.overrideIdentifier] : undefined } : undefined;
265
+ const target = overrides ? arg4 : arg3;
266
+ const targets = target ? [target] : [];
267
+ if (overrides?.overrideIdentifiers) {
268
+ overrides.overrideIdentifiers = distinct(overrides.overrideIdentifiers);
269
+ overrides.overrideIdentifiers = overrides.overrideIdentifiers.length ? overrides.overrideIdentifiers : undefined;
270
+ }
271
+ if (!targets.length) {
272
+ if (overrides?.overrideIdentifiers && overrides.overrideIdentifiers.length > 1) {
273
+ throw new Error('Configuration Target is required while updating the value for multiple override identifiers');
274
+ }
275
+ const inspect = this.inspect(key, { resource: overrides?.resource, overrideIdentifier: overrides?.overrideIdentifiers ? overrides.overrideIdentifiers[0] : undefined });
276
+ targets.push(...this.deriveConfigurationTargets(key, value, inspect));
277
+ if (equals(value, inspect.defaultValue) && targets.length === 1 && ((targets[0] === 2 || targets[0] === 3) )) {
278
+ value = undefined;
279
+ }
280
+ }
281
+ await Promises.settled(( targets.map(
282
+ target => this.writeConfigurationValue(key, value, target, overrides, options)
283
+ )));
284
+ }
285
+ async reloadConfiguration(target) {
286
+ if (target === undefined) {
287
+ this.reloadDefaultConfiguration();
288
+ const application = await this.reloadApplicationConfiguration(true);
289
+ const { local, remote } = await this.reloadUserConfiguration();
290
+ await this.reloadWorkspaceConfiguration();
291
+ await this.loadConfiguration(application, local, remote, true);
292
+ return;
293
+ }
294
+ if (isWorkspaceFolder(target)) {
295
+ await this.reloadWorkspaceFolderConfiguration(target);
296
+ return;
297
+ }
298
+ switch (target) {
299
+ case 7 :
300
+ this.reloadDefaultConfiguration();
301
+ return;
302
+ case 2 : {
303
+ const { local, remote } = await this.reloadUserConfiguration();
304
+ await this.loadConfiguration(this._configuration.applicationConfiguration, local, remote, true);
305
+ return;
306
+ }
307
+ case 3 :
308
+ await this.reloadLocalUserConfiguration();
309
+ return;
310
+ case 4 :
311
+ await this.reloadRemoteUserConfiguration();
312
+ return;
313
+ case 5 :
314
+ case 6 :
315
+ await this.reloadWorkspaceConfiguration();
316
+ return;
317
+ }
318
+ }
319
+ hasCachedConfigurationDefaultsOverrides() {
320
+ return this.defaultConfiguration.hasCachedConfigurationDefaultsOverrides();
321
+ }
322
+ inspect(key, overrides) {
323
+ return this._configuration.inspect(key, overrides);
324
+ }
325
+ keys() {
326
+ return ( this._configuration.keys());
327
+ }
328
+ async whenRemoteConfigurationLoaded() {
329
+ await this.initRemoteUserConfigurationBarrier.wait();
330
+ }
331
+ async initialize(arg) {
332
+ mark('code/willInitWorkspaceService');
333
+ const trigger = this.initialized;
334
+ this.initialized = false;
335
+ const workspace = await this.createWorkspace(arg);
336
+ await this.updateWorkspaceAndInitializeConfiguration(workspace, trigger);
337
+ this.checkAndMarkWorkspaceComplete(false);
338
+ mark('code/didInitWorkspaceService');
339
+ }
340
+ updateWorkspaceTrust(trusted) {
341
+ if (this.isWorkspaceTrusted !== trusted) {
342
+ this.isWorkspaceTrusted = trusted;
343
+ const data = this._configuration.toData();
344
+ const folderConfigurationModels = [];
345
+ for (const folder of this.workspace.folders) {
346
+ const folderConfiguration = this.cachedFolderConfigs.get(folder.uri);
347
+ let configurationModel;
348
+ if (folderConfiguration) {
349
+ configurationModel = folderConfiguration.updateWorkspaceTrust(this.isWorkspaceTrusted);
350
+ this._configuration.updateFolderConfiguration(folder.uri, configurationModel);
351
+ }
352
+ folderConfigurationModels.push(configurationModel);
353
+ }
354
+ if (this.getWorkbenchState() === 2 ) {
355
+ if (folderConfigurationModels[0]) {
356
+ this._configuration.updateWorkspaceConfiguration(folderConfigurationModels[0]);
357
+ }
358
+ }
359
+ else {
360
+ this._configuration.updateWorkspaceConfiguration(this.workspaceConfiguration.updateWorkspaceTrust(this.isWorkspaceTrusted));
361
+ }
362
+ this.updateRestrictedSettings();
363
+ let keys = [];
364
+ if (this.restrictedSettings.userLocal) {
365
+ keys.push(...this.restrictedSettings.userLocal);
366
+ }
367
+ if (this.restrictedSettings.userRemote) {
368
+ keys.push(...this.restrictedSettings.userRemote);
369
+ }
370
+ if (this.restrictedSettings.workspace) {
371
+ keys.push(...this.restrictedSettings.workspace);
372
+ }
373
+ this.restrictedSettings.workspaceFolder?.forEach((value) => keys.push(...value));
374
+ keys = distinct(keys);
375
+ if (keys.length) {
376
+ this.triggerConfigurationChange({ keys, overrides: [] }, { data, workspace: this.workspace }, 5 );
377
+ }
378
+ }
379
+ }
380
+ acquireInstantiationService(instantiationService) {
381
+ this.instantiationService = instantiationService;
382
+ }
383
+ isSettingAppliedForAllProfiles(key) {
384
+ if (this.configurationRegistry.getConfigurationProperties()[key]?.scope === 1 ) {
385
+ return true;
386
+ }
387
+ const allProfilesSettings = this.getValue(APPLY_ALL_PROFILES_SETTING) ?? [];
388
+ return Array.isArray(allProfilesSettings) && allProfilesSettings.includes(key);
389
+ }
390
+ async createWorkspace(arg) {
391
+ if (isWorkspaceIdentifier(arg)) {
392
+ return this.createMultiFolderWorkspace(arg);
393
+ }
394
+ if (isSingleFolderWorkspaceIdentifier(arg)) {
395
+ return this.createSingleFolderWorkspace(arg);
396
+ }
397
+ return this.createEmptyWorkspace(arg);
398
+ }
399
+ async createMultiFolderWorkspace(workspaceIdentifier) {
400
+ await this.workspaceConfiguration.initialize({ id: workspaceIdentifier.id, configPath: workspaceIdentifier.configPath }, this.isWorkspaceTrusted);
401
+ const workspaceConfigPath = workspaceIdentifier.configPath;
402
+ const workspaceFolders = toWorkspaceFolders(this.workspaceConfiguration.getFolders(), workspaceConfigPath, this.uriIdentityService.extUri);
403
+ const workspaceId = workspaceIdentifier.id;
404
+ const workspace = ( new Workspace(
405
+ workspaceId,
406
+ workspaceFolders,
407
+ this.workspaceConfiguration.isTransient(),
408
+ workspaceConfigPath,
409
+ uri => this.uriIdentityService.extUri.ignorePathCasing(uri)
410
+ ));
411
+ workspace.initialized = this.workspaceConfiguration.initialized;
412
+ return workspace;
413
+ }
414
+ createSingleFolderWorkspace(singleFolderWorkspaceIdentifier) {
415
+ const workspace = ( new Workspace(
416
+ singleFolderWorkspaceIdentifier.id,
417
+ [toWorkspaceFolder(singleFolderWorkspaceIdentifier.uri)],
418
+ false,
419
+ null,
420
+ uri => this.uriIdentityService.extUri.ignorePathCasing(uri)
421
+ ));
422
+ workspace.initialized = true;
423
+ return workspace;
424
+ }
425
+ createEmptyWorkspace(emptyWorkspaceIdentifier) {
426
+ const workspace = ( new Workspace(
427
+ emptyWorkspaceIdentifier.id,
428
+ [],
429
+ false,
430
+ null,
431
+ uri => this.uriIdentityService.extUri.ignorePathCasing(uri)
432
+ ));
433
+ workspace.initialized = true;
434
+ return Promise.resolve(workspace);
435
+ }
436
+ checkAndMarkWorkspaceComplete(fromCache) {
437
+ if (!this.completeWorkspaceBarrier.isOpen() && this.workspace.initialized) {
438
+ this.completeWorkspaceBarrier.open();
439
+ this.validateWorkspaceFoldersAndReload(fromCache);
440
+ }
441
+ }
442
+ async updateWorkspaceAndInitializeConfiguration(workspace, trigger) {
443
+ const hasWorkspaceBefore = !!this.workspace;
444
+ let previousState;
445
+ let previousWorkspacePath;
446
+ let previousFolders = [];
447
+ if (hasWorkspaceBefore) {
448
+ previousState = this.getWorkbenchState();
449
+ previousWorkspacePath = this.workspace.configuration ? this.workspace.configuration.fsPath : undefined;
450
+ previousFolders = this.workspace.folders;
451
+ this.workspace.update(workspace);
452
+ }
453
+ else {
454
+ this.workspace = workspace;
455
+ }
456
+ await this.initializeConfiguration(trigger);
457
+ if (hasWorkspaceBefore) {
458
+ const newState = this.getWorkbenchState();
459
+ if (previousState && newState !== previousState) {
460
+ this._onDidChangeWorkbenchState.fire(newState);
461
+ }
462
+ const newWorkspacePath = this.workspace.configuration ? this.workspace.configuration.fsPath : undefined;
463
+ if (previousWorkspacePath && newWorkspacePath !== previousWorkspacePath || newState !== previousState) {
464
+ this._onDidChangeWorkspaceName.fire();
465
+ }
466
+ const folderChanges = this.compareFolders(previousFolders, this.workspace.folders);
467
+ if (folderChanges && (folderChanges.added.length || folderChanges.removed.length || folderChanges.changed.length)) {
468
+ await this.handleWillChangeWorkspaceFolders(folderChanges, false);
469
+ this._onDidChangeWorkspaceFolders.fire(folderChanges);
470
+ }
471
+ }
472
+ if (!this.localUserConfiguration.hasTasksLoaded) {
473
+ this._register(runWhenWindowIdle(mainWindow, () => this.reloadLocalUserConfiguration(false, this._configuration.localUserConfiguration)));
474
+ }
475
+ }
476
+ compareFolders(currentFolders, newFolders) {
477
+ const result = { added: [], removed: [], changed: [] };
478
+ result.added = newFolders.filter(newFolder => !( currentFolders.some(currentFolder => ( newFolder.uri.toString()) === ( currentFolder.uri.toString()))));
479
+ for (let currentIndex = 0; currentIndex < currentFolders.length; currentIndex++) {
480
+ const currentFolder = currentFolders[currentIndex];
481
+ let newIndex = 0;
482
+ for (newIndex = 0; newIndex < newFolders.length && ( currentFolder.uri.toString()) !== ( newFolders[newIndex].uri.toString()); newIndex++) { }
483
+ if (newIndex < newFolders.length) {
484
+ if (currentIndex !== newIndex || currentFolder.name !== newFolders[newIndex].name) {
485
+ result.changed.push(currentFolder);
486
+ }
487
+ }
488
+ else {
489
+ result.removed.push(currentFolder);
490
+ }
491
+ }
492
+ return result;
493
+ }
494
+ async initializeConfiguration(trigger) {
495
+ await this.defaultConfiguration.initialize();
496
+ const initPolicyConfigurationPromise = this.policyConfiguration.initialize();
497
+ const initApplicationConfigurationPromise = this.applicationConfiguration ? this.applicationConfiguration.initialize() : Promise.resolve(( new ConfigurationModel()));
498
+ const initUserConfiguration = async () => {
499
+ mark('code/willInitUserConfiguration');
500
+ const result = await Promise.all([this.localUserConfiguration.initialize(), this.remoteUserConfiguration ? this.remoteUserConfiguration.initialize() : Promise.resolve(( new ConfigurationModel()))]);
501
+ if (this.applicationConfiguration) {
502
+ const applicationConfigurationModel = await initApplicationConfigurationPromise;
503
+ result[0] = this.localUserConfiguration.reparse({ exclude: applicationConfigurationModel.getValue(APPLY_ALL_PROFILES_SETTING) });
504
+ }
505
+ mark('code/didInitUserConfiguration');
506
+ return result;
507
+ };
508
+ const [, application, [local, remote]] = await Promise.all([
509
+ initPolicyConfigurationPromise,
510
+ initApplicationConfigurationPromise,
511
+ initUserConfiguration()
512
+ ]);
513
+ mark('code/willInitWorkspaceConfiguration');
514
+ await this.loadConfiguration(application, local, remote, trigger);
515
+ mark('code/didInitWorkspaceConfiguration');
516
+ }
517
+ reloadDefaultConfiguration() {
518
+ this.onDefaultConfigurationChanged(this.defaultConfiguration.reload());
519
+ }
520
+ async reloadApplicationConfiguration(donotTrigger) {
521
+ if (!this.applicationConfiguration) {
522
+ return ( new ConfigurationModel());
523
+ }
524
+ const model = await this.applicationConfiguration.loadConfiguration();
525
+ if (!donotTrigger) {
526
+ this.onApplicationConfigurationChanged(model);
527
+ }
528
+ return model;
529
+ }
530
+ async reloadUserConfiguration() {
531
+ const [local, remote] = await Promise.all([this.reloadLocalUserConfiguration(true), this.reloadRemoteUserConfiguration(true)]);
532
+ return { local, remote };
533
+ }
534
+ async reloadLocalUserConfiguration(donotTrigger, settingsConfiguration) {
535
+ const model = await this.localUserConfiguration.reload(settingsConfiguration);
536
+ if (!donotTrigger) {
537
+ this.onLocalUserConfigurationChanged(model);
538
+ }
539
+ return model;
540
+ }
541
+ async reloadRemoteUserConfiguration(donotTrigger) {
542
+ if (this.remoteUserConfiguration) {
543
+ const model = await this.remoteUserConfiguration.reload();
544
+ if (!donotTrigger) {
545
+ this.onRemoteUserConfigurationChanged(model);
546
+ }
547
+ return model;
548
+ }
549
+ return ( new ConfigurationModel());
550
+ }
551
+ async reloadWorkspaceConfiguration() {
552
+ const workbenchState = this.getWorkbenchState();
553
+ if (workbenchState === 2 ) {
554
+ return this.onWorkspaceFolderConfigurationChanged(this.workspace.folders[0]);
555
+ }
556
+ if (workbenchState === 3 ) {
557
+ return this.workspaceConfiguration.reload().then(() => this.onWorkspaceConfigurationChanged(false));
558
+ }
559
+ }
560
+ reloadWorkspaceFolderConfiguration(folder) {
561
+ return this.onWorkspaceFolderConfigurationChanged(folder);
562
+ }
563
+ async loadConfiguration(applicationConfigurationModel, userConfigurationModel, remoteUserConfigurationModel, trigger) {
564
+ this.cachedFolderConfigs = ( new ResourceMap());
565
+ const folders = this.workspace.folders;
566
+ const folderConfigurations = await this.loadFolderConfigurations(folders);
567
+ const workspaceConfiguration = this.getWorkspaceConfigurationModel(folderConfigurations);
568
+ const folderConfigurationModels = ( new ResourceMap());
569
+ folderConfigurations.forEach((folderConfiguration, index) => folderConfigurationModels.set(folders[index].uri, folderConfiguration));
570
+ const currentConfiguration = this._configuration;
571
+ this._configuration = ( new Configuration(
572
+ this.defaultConfiguration.configurationModel,
573
+ this.policyConfiguration.configurationModel,
574
+ applicationConfigurationModel,
575
+ userConfigurationModel,
576
+ remoteUserConfigurationModel,
577
+ workspaceConfiguration,
578
+ folderConfigurationModels,
579
+ ( new ConfigurationModel()),
580
+ ( new ResourceMap()),
581
+ this.workspace
582
+ ));
583
+ this.initialized = true;
584
+ if (trigger) {
585
+ const change = this._configuration.compare(currentConfiguration);
586
+ this.triggerConfigurationChange(change, { data: currentConfiguration.toData(), workspace: this.workspace }, 5 );
587
+ }
588
+ this.updateRestrictedSettings();
589
+ }
590
+ getWorkspaceConfigurationModel(folderConfigurations) {
591
+ switch (this.getWorkbenchState()) {
592
+ case 2 :
593
+ return folderConfigurations[0];
594
+ case 3 :
595
+ return this.workspaceConfiguration.getConfiguration();
596
+ default:
597
+ return ( new ConfigurationModel());
598
+ }
599
+ }
600
+ onUserDataProfileChanged(e) {
601
+ e.join((async () => {
602
+ const promises = [];
603
+ promises.push(this.localUserConfiguration.reset(e.profile.settingsResource, e.profile.tasksResource, { scopes: getLocalUserConfigurationScopes(e.profile, !!this.remoteUserConfiguration) }));
604
+ if (e.previous.isDefault !== e.profile.isDefault
605
+ || !!e.previous.useDefaultFlags?.settings !== !!e.profile.useDefaultFlags?.settings) {
606
+ this.createApplicationConfiguration();
607
+ if (this.applicationConfiguration) {
608
+ promises.push(this.reloadApplicationConfiguration(true));
609
+ }
610
+ }
611
+ let [localUser, application] = await Promise.all(promises);
612
+ application = application ?? this._configuration.applicationConfiguration;
613
+ if (this.applicationConfiguration) {
614
+ localUser = this.localUserConfiguration.reparse({ exclude: application.getValue(APPLY_ALL_PROFILES_SETTING) });
615
+ }
616
+ await this.loadConfiguration(application, localUser, this._configuration.remoteUserConfiguration, true);
617
+ })());
618
+ }
619
+ onDefaultConfigurationChanged(configurationModel, properties) {
620
+ if (this.workspace) {
621
+ const previousData = this._configuration.toData();
622
+ const change = this._configuration.compareAndUpdateDefaultConfiguration(configurationModel, properties);
623
+ if (this.applicationConfiguration) {
624
+ this._configuration.updateApplicationConfiguration(this.applicationConfiguration.reparse());
625
+ }
626
+ if (this.remoteUserConfiguration) {
627
+ this._configuration.updateLocalUserConfiguration(this.localUserConfiguration.reparse());
628
+ this._configuration.updateRemoteUserConfiguration(this.remoteUserConfiguration.reparse());
629
+ }
630
+ if (this.getWorkbenchState() === 2 ) {
631
+ const folderConfiguration = this.cachedFolderConfigs.get(this.workspace.folders[0].uri);
632
+ if (folderConfiguration) {
633
+ this._configuration.updateWorkspaceConfiguration(folderConfiguration.reparse());
634
+ this._configuration.updateFolderConfiguration(this.workspace.folders[0].uri, folderConfiguration.reparse());
635
+ }
636
+ }
637
+ else {
638
+ this._configuration.updateWorkspaceConfiguration(this.workspaceConfiguration.reparseWorkspaceSettings());
639
+ for (const folder of this.workspace.folders) {
640
+ const folderConfiguration = this.cachedFolderConfigs.get(folder.uri);
641
+ if (folderConfiguration) {
642
+ this._configuration.updateFolderConfiguration(folder.uri, folderConfiguration.reparse());
643
+ }
644
+ }
645
+ }
646
+ this.triggerConfigurationChange(change, { data: previousData, workspace: this.workspace }, 7 );
647
+ this.updateRestrictedSettings();
648
+ }
649
+ }
650
+ onPolicyConfigurationChanged(policyConfiguration) {
651
+ const previous = { data: this._configuration.toData(), workspace: this.workspace };
652
+ const change = this._configuration.compareAndUpdatePolicyConfiguration(policyConfiguration);
653
+ this.triggerConfigurationChange(change, previous, 7 );
654
+ }
655
+ onApplicationConfigurationChanged(applicationConfiguration) {
656
+ const previous = { data: this._configuration.toData(), workspace: this.workspace };
657
+ const previousAllProfilesSettings = this._configuration.applicationConfiguration.getValue(APPLY_ALL_PROFILES_SETTING) ?? [];
658
+ const change = this._configuration.compareAndUpdateApplicationConfiguration(applicationConfiguration);
659
+ const currentAllProfilesSettings = this.getValue(APPLY_ALL_PROFILES_SETTING) ?? [];
660
+ const configurationProperties = this.configurationRegistry.getConfigurationProperties();
661
+ const changedKeys = [];
662
+ for (const changedKey of change.keys) {
663
+ if (configurationProperties[changedKey]?.scope === 1 ) {
664
+ changedKeys.push(changedKey);
665
+ if (changedKey === APPLY_ALL_PROFILES_SETTING) {
666
+ for (const previousAllProfileSetting of previousAllProfilesSettings) {
667
+ if (!currentAllProfilesSettings.includes(previousAllProfileSetting)) {
668
+ changedKeys.push(previousAllProfileSetting);
669
+ }
670
+ }
671
+ for (const currentAllProfileSetting of currentAllProfilesSettings) {
672
+ if (!previousAllProfilesSettings.includes(currentAllProfileSetting)) {
673
+ changedKeys.push(currentAllProfileSetting);
674
+ }
675
+ }
676
+ }
677
+ }
678
+ else if (currentAllProfilesSettings.includes(changedKey)) {
679
+ changedKeys.push(changedKey);
680
+ }
681
+ }
682
+ change.keys = changedKeys;
683
+ if (change.keys.includes(APPLY_ALL_PROFILES_SETTING)) {
684
+ this._configuration.updateLocalUserConfiguration(this.localUserConfiguration.reparse({ exclude: currentAllProfilesSettings }));
685
+ }
686
+ this.triggerConfigurationChange(change, previous, 2 );
687
+ }
688
+ onLocalUserConfigurationChanged(userConfiguration) {
689
+ const previous = { data: this._configuration.toData(), workspace: this.workspace };
690
+ const change = this._configuration.compareAndUpdateLocalUserConfiguration(userConfiguration);
691
+ this.triggerConfigurationChange(change, previous, 2 );
692
+ }
693
+ onRemoteUserConfigurationChanged(userConfiguration) {
694
+ const previous = { data: this._configuration.toData(), workspace: this.workspace };
695
+ const change = this._configuration.compareAndUpdateRemoteUserConfiguration(userConfiguration);
696
+ this.triggerConfigurationChange(change, previous, 2 );
697
+ }
698
+ async onWorkspaceConfigurationChanged(fromCache) {
699
+ if (this.workspace && this.workspace.configuration) {
700
+ let newFolders = toWorkspaceFolders(this.workspaceConfiguration.getFolders(), this.workspace.configuration, this.uriIdentityService.extUri);
701
+ if (this.workspace.initialized) {
702
+ const { added, removed, changed } = this.compareFolders(this.workspace.folders, newFolders);
703
+ if (added.length || removed.length || changed.length) {
704
+ newFolders = await this.toValidWorkspaceFolders(newFolders);
705
+ }
706
+ else {
707
+ newFolders = this.workspace.folders;
708
+ }
709
+ }
710
+ await this.updateWorkspaceConfiguration(newFolders, this.workspaceConfiguration.getConfiguration(), fromCache);
711
+ }
712
+ }
713
+ updateRestrictedSettings() {
714
+ const changed = [];
715
+ const allProperties = this.configurationRegistry.getConfigurationProperties();
716
+ const defaultRestrictedSettings = ( Object.keys(allProperties)).filter(key => allProperties[key].restricted).sort((a, b) => a.localeCompare(b));
717
+ const defaultDelta = delta(defaultRestrictedSettings, this._restrictedSettings.default, (a, b) => a.localeCompare(b));
718
+ changed.push(...defaultDelta.added, ...defaultDelta.removed);
719
+ const application = (this.applicationConfiguration?.getRestrictedSettings() || []).sort((a, b) => a.localeCompare(b));
720
+ const applicationDelta = delta(application, this._restrictedSettings.application || [], (a, b) => a.localeCompare(b));
721
+ changed.push(...applicationDelta.added, ...applicationDelta.removed);
722
+ const userLocal = this.localUserConfiguration.getRestrictedSettings().sort((a, b) => a.localeCompare(b));
723
+ const userLocalDelta = delta(userLocal, this._restrictedSettings.userLocal || [], (a, b) => a.localeCompare(b));
724
+ changed.push(...userLocalDelta.added, ...userLocalDelta.removed);
725
+ const userRemote = (this.remoteUserConfiguration?.getRestrictedSettings() || []).sort((a, b) => a.localeCompare(b));
726
+ const userRemoteDelta = delta(userRemote, this._restrictedSettings.userRemote || [], (a, b) => a.localeCompare(b));
727
+ changed.push(...userRemoteDelta.added, ...userRemoteDelta.removed);
728
+ const workspaceFolderMap = ( new ResourceMap());
729
+ for (const workspaceFolder of this.workspace.folders) {
730
+ const cachedFolderConfig = this.cachedFolderConfigs.get(workspaceFolder.uri);
731
+ const folderRestrictedSettings = (cachedFolderConfig?.getRestrictedSettings() || []).sort((a, b) => a.localeCompare(b));
732
+ if (folderRestrictedSettings.length) {
733
+ workspaceFolderMap.set(workspaceFolder.uri, folderRestrictedSettings);
734
+ }
735
+ const previous = this._restrictedSettings.workspaceFolder?.get(workspaceFolder.uri) || [];
736
+ const workspaceFolderDelta = delta(folderRestrictedSettings, previous, (a, b) => a.localeCompare(b));
737
+ changed.push(...workspaceFolderDelta.added, ...workspaceFolderDelta.removed);
738
+ }
739
+ const workspace = this.getWorkbenchState() === 3 ? this.workspaceConfiguration.getRestrictedSettings().sort((a, b) => a.localeCompare(b))
740
+ : this.workspace.folders[0] ? (workspaceFolderMap.get(this.workspace.folders[0].uri) || []) : [];
741
+ const workspaceDelta = delta(workspace, this._restrictedSettings.workspace || [], (a, b) => a.localeCompare(b));
742
+ changed.push(...workspaceDelta.added, ...workspaceDelta.removed);
743
+ if (changed.length) {
744
+ this._restrictedSettings = {
745
+ default: defaultRestrictedSettings,
746
+ application: application.length ? application : undefined,
747
+ userLocal: userLocal.length ? userLocal : undefined,
748
+ userRemote: userRemote.length ? userRemote : undefined,
749
+ workspace: workspace.length ? workspace : undefined,
750
+ workspaceFolder: workspaceFolderMap.size ? workspaceFolderMap : undefined,
751
+ };
752
+ this._onDidChangeRestrictedSettings.fire(this.restrictedSettings);
753
+ }
754
+ }
755
+ async updateWorkspaceConfiguration(workspaceFolders, configuration, fromCache) {
756
+ const previous = { data: this._configuration.toData(), workspace: this.workspace };
757
+ const change = this._configuration.compareAndUpdateWorkspaceConfiguration(configuration);
758
+ const changes = this.compareFolders(this.workspace.folders, workspaceFolders);
759
+ if (changes.added.length || changes.removed.length || changes.changed.length) {
760
+ this.workspace.folders = workspaceFolders;
761
+ const change = await this.onFoldersChanged();
762
+ await this.handleWillChangeWorkspaceFolders(changes, fromCache);
763
+ this.triggerConfigurationChange(change, previous, 6 );
764
+ this._onDidChangeWorkspaceFolders.fire(changes);
765
+ }
766
+ else {
767
+ this.triggerConfigurationChange(change, previous, 5 );
768
+ }
769
+ this.updateRestrictedSettings();
770
+ }
771
+ async handleWillChangeWorkspaceFolders(changes, fromCache) {
772
+ const joiners = [];
773
+ this._onWillChangeWorkspaceFolders.fire({
774
+ join(updateWorkspaceTrustStatePromise) {
775
+ joiners.push(updateWorkspaceTrustStatePromise);
776
+ },
777
+ changes,
778
+ fromCache
779
+ });
780
+ try {
781
+ await Promises.settled(joiners);
782
+ }
783
+ catch (error) { }
784
+ }
785
+ async onWorkspaceFolderConfigurationChanged(folder) {
786
+ const [folderConfiguration] = await this.loadFolderConfigurations([folder]);
787
+ const previous = { data: this._configuration.toData(), workspace: this.workspace };
788
+ const folderConfigurationChange = this._configuration.compareAndUpdateFolderConfiguration(folder.uri, folderConfiguration);
789
+ if (this.getWorkbenchState() === 2 ) {
790
+ const workspaceConfigurationChange = this._configuration.compareAndUpdateWorkspaceConfiguration(folderConfiguration);
791
+ this.triggerConfigurationChange(mergeChanges(folderConfigurationChange, workspaceConfigurationChange), previous, 5 );
792
+ }
793
+ else {
794
+ this.triggerConfigurationChange(folderConfigurationChange, previous, 6 );
795
+ }
796
+ this.updateRestrictedSettings();
797
+ }
798
+ async onFoldersChanged() {
799
+ const changes = [];
800
+ for (const key of ( this.cachedFolderConfigs.keys())) {
801
+ if (!this.workspace.folders.filter(folder => ( folder.uri.toString()) === ( key.toString()))[0]) {
802
+ const folderConfiguration = this.cachedFolderConfigs.get(key);
803
+ folderConfiguration.dispose();
804
+ this.cachedFolderConfigs.delete(key);
805
+ changes.push(this._configuration.compareAndDeleteFolderConfiguration(key));
806
+ }
807
+ }
808
+ const toInitialize = this.workspace.folders.filter(folder => !( this.cachedFolderConfigs.has(folder.uri)));
809
+ if (toInitialize.length) {
810
+ const folderConfigurations = await this.loadFolderConfigurations(toInitialize);
811
+ folderConfigurations.forEach((folderConfiguration, index) => {
812
+ changes.push(this._configuration.compareAndUpdateFolderConfiguration(toInitialize[index].uri, folderConfiguration));
813
+ });
814
+ }
815
+ return mergeChanges(...changes);
816
+ }
817
+ loadFolderConfigurations(folders) {
818
+ return Promise.all([...( folders.map(folder => {
819
+ let folderConfiguration = this.cachedFolderConfigs.get(folder.uri);
820
+ if (!folderConfiguration) {
821
+ folderConfiguration = ( new FolderConfiguration(
822
+ !this.initialized,
823
+ folder,
824
+ FOLDER_CONFIG_FOLDER_NAME,
825
+ this.getWorkbenchState(),
826
+ this.isWorkspaceTrusted,
827
+ this.fileService,
828
+ this.uriIdentityService,
829
+ this.logService,
830
+ this.configurationCache
831
+ ));
832
+ this._register(folderConfiguration.onDidChange(() => this.onWorkspaceFolderConfigurationChanged(folder)));
833
+ this.cachedFolderConfigs.set(folder.uri, this._register(folderConfiguration));
834
+ }
835
+ return folderConfiguration.loadConfiguration();
836
+ }))]);
837
+ }
838
+ async validateWorkspaceFoldersAndReload(fromCache) {
839
+ const validWorkspaceFolders = await this.toValidWorkspaceFolders(this.workspace.folders);
840
+ const { removed } = this.compareFolders(this.workspace.folders, validWorkspaceFolders);
841
+ if (removed.length) {
842
+ await this.updateWorkspaceConfiguration(validWorkspaceFolders, this.workspaceConfiguration.getConfiguration(), fromCache);
843
+ }
844
+ }
845
+ async toValidWorkspaceFolders(workspaceFolders) {
846
+ const validWorkspaceFolders = [];
847
+ for (const workspaceFolder of workspaceFolders) {
848
+ try {
849
+ const result = await this.fileService.stat(workspaceFolder.uri);
850
+ if (!result.isDirectory) {
851
+ continue;
852
+ }
853
+ }
854
+ catch (e) {
855
+ this.logService.warn(`Ignoring the error while validating workspace folder ${( workspaceFolder.uri.toString())} - ${toErrorMessage(e)}`);
856
+ }
857
+ validWorkspaceFolders.push(workspaceFolder);
858
+ }
859
+ return validWorkspaceFolders;
860
+ }
861
+ async writeConfigurationValue(key, value, target, overrides, options) {
862
+ if (!this.instantiationService) {
863
+ throw new Error('Cannot write configuration because the configuration service is not yet ready to accept writes.');
864
+ }
865
+ if (target === 7 ) {
866
+ throw new Error('Invalid configuration target');
867
+ }
868
+ if (target === 8 ) {
869
+ const previous = { data: this._configuration.toData(), workspace: this.workspace };
870
+ this._configuration.updateValue(key, value, overrides);
871
+ this.triggerConfigurationChange({ keys: overrides?.overrideIdentifiers?.length ? [keyFromOverrideIdentifiers(overrides.overrideIdentifiers), key] : [key], overrides: overrides?.overrideIdentifiers?.length ? ( overrides.overrideIdentifiers.map(overrideIdentifier => ([overrideIdentifier, [key]]))) : [] }, previous, target);
872
+ return;
873
+ }
874
+ const editableConfigurationTarget = this.toEditableConfigurationTarget(target, key);
875
+ if (!editableConfigurationTarget) {
876
+ throw new Error('Invalid configuration target');
877
+ }
878
+ if (editableConfigurationTarget === 2 && !this.remoteUserConfiguration) {
879
+ throw new Error('Invalid configuration target');
880
+ }
881
+ if (overrides?.overrideIdentifiers?.length && overrides.overrideIdentifiers.length > 1) {
882
+ const configurationModel = this.getConfigurationModelForEditableConfigurationTarget(editableConfigurationTarget, overrides.resource);
883
+ if (configurationModel) {
884
+ const overrideIdentifiers = overrides.overrideIdentifiers.sort();
885
+ const existingOverrides = configurationModel.overrides.find(override => equals$1([...override.identifiers].sort(), overrideIdentifiers));
886
+ if (existingOverrides) {
887
+ overrides.overrideIdentifiers = existingOverrides.identifiers;
888
+ }
889
+ }
890
+ }
891
+ this.configurationEditing = this.configurationEditing ?? this.createConfigurationEditingService(this.instantiationService);
892
+ await (await this.configurationEditing).writeConfiguration(editableConfigurationTarget, { key, value }, { scopes: overrides, ...options });
893
+ switch (editableConfigurationTarget) {
894
+ case 1 :
895
+ if (this.applicationConfiguration && this.isSettingAppliedForAllProfiles(key)) {
896
+ await this.reloadApplicationConfiguration();
897
+ }
898
+ else {
899
+ await this.reloadLocalUserConfiguration();
900
+ }
901
+ return;
902
+ case 2 :
903
+ return this.reloadRemoteUserConfiguration().then(() => undefined);
904
+ case 3 :
905
+ return this.reloadWorkspaceConfiguration();
906
+ case 4 : {
907
+ const workspaceFolder = overrides && overrides.resource ? this.workspace.getFolder(overrides.resource) : null;
908
+ if (workspaceFolder) {
909
+ return this.reloadWorkspaceFolderConfiguration(workspaceFolder);
910
+ }
911
+ }
912
+ }
913
+ }
914
+ async createConfigurationEditingService(instantiationService) {
915
+ const remoteSettingsResource = (await this.remoteAgentService.getEnvironment())?.settingsPath ?? null;
916
+ return instantiationService.createInstance(ConfigurationEditing, remoteSettingsResource);
917
+ }
918
+ getConfigurationModelForEditableConfigurationTarget(target, resource) {
919
+ switch (target) {
920
+ case 1 : return this._configuration.localUserConfiguration;
921
+ case 2 : return this._configuration.remoteUserConfiguration;
922
+ case 3 : return this._configuration.workspaceConfiguration;
923
+ case 4 : return resource ? this._configuration.folderConfigurations.get(resource) : undefined;
924
+ }
925
+ }
926
+ getConfigurationModel(target, resource) {
927
+ switch (target) {
928
+ case 3 : return this._configuration.localUserConfiguration;
929
+ case 4 : return this._configuration.remoteUserConfiguration;
930
+ case 5 : return this._configuration.workspaceConfiguration;
931
+ case 6 : return resource ? this._configuration.folderConfigurations.get(resource) : undefined;
932
+ default: return undefined;
933
+ }
934
+ }
935
+ deriveConfigurationTargets(key, value, inspect) {
936
+ if (equals(value, inspect.value)) {
937
+ return [];
938
+ }
939
+ const definedTargets = [];
940
+ if (inspect.workspaceFolderValue !== undefined) {
941
+ definedTargets.push(6 );
942
+ }
943
+ if (inspect.workspaceValue !== undefined) {
944
+ definedTargets.push(5 );
945
+ }
946
+ if (inspect.userRemoteValue !== undefined) {
947
+ definedTargets.push(4 );
948
+ }
949
+ if (inspect.userLocalValue !== undefined) {
950
+ definedTargets.push(3 );
951
+ }
952
+ if (value === undefined) {
953
+ return definedTargets;
954
+ }
955
+ return [definedTargets[0] || 2 ];
956
+ }
957
+ triggerConfigurationChange(change, previous, target) {
958
+ if (change.keys.length) {
959
+ if (target !== 7 ) {
960
+ this.logService.debug(`Configuration keys changed in ${ConfigurationTargetToString(target)} target`, ...change.keys);
961
+ }
962
+ const configurationChangeEvent = ( new ConfigurationChangeEvent(change, previous, this._configuration, this.workspace));
963
+ configurationChangeEvent.source = target;
964
+ this._onDidChangeConfiguration.fire(configurationChangeEvent);
965
+ }
966
+ }
967
+ toEditableConfigurationTarget(target, key) {
968
+ if (target === 2 ) {
969
+ if (this.remoteUserConfiguration) {
970
+ const scope = this.configurationRegistry.getConfigurationProperties()[key]?.scope;
971
+ if (scope === 2 || scope === 6 ) {
972
+ return 2 ;
973
+ }
974
+ if (this.inspect(key).userRemoteValue !== undefined) {
975
+ return 2 ;
976
+ }
977
+ }
978
+ return 1 ;
979
+ }
980
+ if (target === 3 ) {
981
+ return 1 ;
982
+ }
983
+ if (target === 4 ) {
984
+ return 2 ;
985
+ }
986
+ if (target === 5 ) {
987
+ return 3 ;
988
+ }
989
+ if (target === 6 ) {
990
+ return 4 ;
991
+ }
992
+ return null;
993
+ }
994
+ }
995
+ let RegisterConfigurationSchemasContribution = class RegisterConfigurationSchemasContribution extends Disposable {
996
+ constructor(workspaceContextService, environmentService, workspaceTrustManagementService, extensionService, lifecycleService) {
997
+ super();
998
+ this.workspaceContextService = workspaceContextService;
999
+ this.environmentService = environmentService;
1000
+ this.workspaceTrustManagementService = workspaceTrustManagementService;
1001
+ extensionService.whenInstalledExtensionsRegistered().then(() => {
1002
+ this.registerConfigurationSchemas();
1003
+ const configurationRegistry = ( Registry.as(Extensions.Configuration));
1004
+ const delayer = this._register(( new Delayer(50)));
1005
+ this._register(Event.any(configurationRegistry.onDidUpdateConfiguration, configurationRegistry.onDidSchemaChange, workspaceTrustManagementService.onDidChangeTrust)(() => delayer.trigger(() => this.registerConfigurationSchemas(), lifecycleService.phase === 4 ? undefined : 2500 )));
1006
+ });
1007
+ }
1008
+ registerConfigurationSchemas() {
1009
+ const allSettingsSchema = {
1010
+ properties: allSettings.properties,
1011
+ patternProperties: allSettings.patternProperties,
1012
+ additionalProperties: true,
1013
+ allowTrailingCommas: true,
1014
+ allowComments: true
1015
+ };
1016
+ const userSettingsSchema = this.environmentService.remoteAuthority ?
1017
+ {
1018
+ properties: Object.assign({}, applicationSettings.properties, windowSettings.properties, resourceSettings.properties),
1019
+ patternProperties: allSettings.patternProperties,
1020
+ additionalProperties: true,
1021
+ allowTrailingCommas: true,
1022
+ allowComments: true
1023
+ }
1024
+ : allSettingsSchema;
1025
+ const profileSettingsSchema = {
1026
+ properties: Object.assign({}, machineSettings.properties, machineOverridableSettings.properties, windowSettings.properties, resourceSettings.properties),
1027
+ patternProperties: allSettings.patternProperties,
1028
+ additionalProperties: true,
1029
+ allowTrailingCommas: true,
1030
+ allowComments: true
1031
+ };
1032
+ const machineSettingsSchema = {
1033
+ properties: Object.assign({}, machineSettings.properties, machineOverridableSettings.properties, windowSettings.properties, resourceSettings.properties),
1034
+ patternProperties: allSettings.patternProperties,
1035
+ additionalProperties: true,
1036
+ allowTrailingCommas: true,
1037
+ allowComments: true
1038
+ };
1039
+ const workspaceSettingsSchema = {
1040
+ properties: Object.assign({}, this.checkAndFilterPropertiesRequiringTrust(machineOverridableSettings.properties), this.checkAndFilterPropertiesRequiringTrust(windowSettings.properties), this.checkAndFilterPropertiesRequiringTrust(resourceSettings.properties)),
1041
+ patternProperties: allSettings.patternProperties,
1042
+ additionalProperties: true,
1043
+ allowTrailingCommas: true,
1044
+ allowComments: true
1045
+ };
1046
+ const defaultSettingsSchema = {
1047
+ properties: ( Object.keys(allSettings.properties)).reduce((result, key) => {
1048
+ result[key] = Object.assign({ deprecationMessage: undefined }, allSettings.properties[key]);
1049
+ return result;
1050
+ }, {}),
1051
+ patternProperties: ( Object.keys(allSettings.patternProperties)).reduce((result, key) => {
1052
+ result[key] = Object.assign({ deprecationMessage: undefined }, allSettings.patternProperties[key]);
1053
+ return result;
1054
+ }, {}),
1055
+ additionalProperties: true,
1056
+ allowTrailingCommas: true,
1057
+ allowComments: true
1058
+ };
1059
+ const folderSettingsSchema = 3 === this.workspaceContextService.getWorkbenchState() ?
1060
+ {
1061
+ properties: Object.assign({}, this.checkAndFilterPropertiesRequiringTrust(machineOverridableSettings.properties), this.checkAndFilterPropertiesRequiringTrust(resourceSettings.properties)),
1062
+ patternProperties: allSettings.patternProperties,
1063
+ additionalProperties: true,
1064
+ allowTrailingCommas: true,
1065
+ allowComments: true
1066
+ } : workspaceSettingsSchema;
1067
+ const configDefaultsSchema = {
1068
+ type: 'object',
1069
+ description: ( localizeWithPath(
1070
+ 'vs/workbench/services/configuration/browser/configurationService',
1071
+ 'configurationDefaults.description',
1072
+ 'Contribute defaults for configurations'
1073
+ )),
1074
+ properties: Object.assign({}, machineOverridableSettings.properties, windowSettings.properties, resourceSettings.properties),
1075
+ patternProperties: {
1076
+ [OVERRIDE_PROPERTY_PATTERN]: {
1077
+ type: 'object',
1078
+ default: {},
1079
+ $ref: resourceLanguageSettingsSchemaId,
1080
+ }
1081
+ },
1082
+ additionalProperties: false
1083
+ };
1084
+ this.registerSchemas({
1085
+ defaultSettingsSchema,
1086
+ userSettingsSchema,
1087
+ profileSettingsSchema,
1088
+ machineSettingsSchema,
1089
+ workspaceSettingsSchema,
1090
+ folderSettingsSchema,
1091
+ configDefaultsSchema,
1092
+ });
1093
+ }
1094
+ registerSchemas(schemas) {
1095
+ const jsonRegistry = ( Registry.as(Extensions$2.JSONContribution));
1096
+ jsonRegistry.registerSchema(defaultSettingsSchemaId, schemas.defaultSettingsSchema);
1097
+ jsonRegistry.registerSchema(userSettingsSchemaId, schemas.userSettingsSchema);
1098
+ jsonRegistry.registerSchema(profileSettingsSchemaId, schemas.profileSettingsSchema);
1099
+ jsonRegistry.registerSchema(machineSettingsSchemaId, schemas.machineSettingsSchema);
1100
+ jsonRegistry.registerSchema(workspaceSettingsSchemaId, schemas.workspaceSettingsSchema);
1101
+ jsonRegistry.registerSchema(folderSettingsSchemaId, schemas.folderSettingsSchema);
1102
+ jsonRegistry.registerSchema(configurationDefaultsSchemaId, schemas.configDefaultsSchema);
1103
+ }
1104
+ checkAndFilterPropertiesRequiringTrust(properties) {
1105
+ if (this.workspaceTrustManagementService.isWorkspaceTrusted()) {
1106
+ return properties;
1107
+ }
1108
+ const result = {};
1109
+ Object.entries(properties).forEach(([key, value]) => {
1110
+ if (!value.restricted) {
1111
+ result[key] = value;
1112
+ }
1113
+ });
1114
+ return result;
1115
+ }
1116
+ };
1117
+ RegisterConfigurationSchemasContribution = ( __decorate([
1118
+ ( __param(0, IWorkspaceContextService)),
1119
+ ( __param(1, IWorkbenchEnvironmentService)),
1120
+ ( __param(2, IWorkspaceTrustManagementService)),
1121
+ ( __param(3, IExtensionService)),
1122
+ ( __param(4, ILifecycleService))
1123
+ ], RegisterConfigurationSchemasContribution));
1124
+ let ResetConfigurationDefaultsOverridesCache = class ResetConfigurationDefaultsOverridesCache extends Disposable {
1125
+ constructor(configurationService, extensionService) {
1126
+ super();
1127
+ if (configurationService.hasCachedConfigurationDefaultsOverrides()) {
1128
+ extensionService.whenInstalledExtensionsRegistered().then(() => configurationService.reloadConfiguration(7 ));
1129
+ }
1130
+ }
1131
+ };
1132
+ ResetConfigurationDefaultsOverridesCache = ( __decorate([
1133
+ ( __param(0, IConfigurationService)),
1134
+ ( __param(1, IExtensionService))
1135
+ ], ResetConfigurationDefaultsOverridesCache));
1136
+ let UpdateExperimentalSettingsDefaults = class UpdateExperimentalSettingsDefaults extends Disposable {
1137
+ static { this.ID = 'workbench.contrib.updateExperimentalSettingsDefaults'; }
1138
+ constructor(workbenchAssignmentService) {
1139
+ super();
1140
+ this.workbenchAssignmentService = workbenchAssignmentService;
1141
+ this.processedExperimentalSettings = ( new Set());
1142
+ this.configurationRegistry = ( Registry.as(Extensions.Configuration));
1143
+ this.processExperimentalSettings(( Object.keys(this.configurationRegistry.getConfigurationProperties())));
1144
+ this._register(this.configurationRegistry.onDidUpdateConfiguration(({ properties }) => this.processExperimentalSettings(properties)));
1145
+ }
1146
+ async processExperimentalSettings(properties) {
1147
+ const overrides = {};
1148
+ const allProperties = this.configurationRegistry.getConfigurationProperties();
1149
+ for (const property of properties) {
1150
+ const schema = allProperties[property];
1151
+ if (!schema?.tags?.includes('experimental')) {
1152
+ continue;
1153
+ }
1154
+ if (( this.processedExperimentalSettings.has(property))) {
1155
+ continue;
1156
+ }
1157
+ this.processedExperimentalSettings.add(property);
1158
+ try {
1159
+ const value = await this.workbenchAssignmentService.getTreatment(`config.${property}`);
1160
+ if (!isUndefined(value) && !equals(value, schema.default)) {
1161
+ overrides[property] = value;
1162
+ }
1163
+ }
1164
+ catch (error) { }
1165
+ }
1166
+ if (( Object.keys(overrides)).length) {
1167
+ this.configurationRegistry.registerDefaultConfigurations([{ overrides, source: ( localizeWithPath(
1168
+ 'vs/workbench/services/configuration/browser/configurationService',
1169
+ 'experimental',
1170
+ "Experiments"
1171
+ )) }]);
1172
+ }
1173
+ }
1174
+ };
1175
+ UpdateExperimentalSettingsDefaults = ( __decorate([
1176
+ ( __param(0, IWorkbenchAssignmentService))
1177
+ ], UpdateExperimentalSettingsDefaults));
1178
+ const workbenchContributionsRegistry = ( Registry.as(Extensions$1.Workbench));
1179
+ workbenchContributionsRegistry.registerWorkbenchContribution(RegisterConfigurationSchemasContribution, 3 );
1180
+ workbenchContributionsRegistry.registerWorkbenchContribution(ResetConfigurationDefaultsOverridesCache, 4 );
1181
+ registerWorkbenchContribution2(UpdateExperimentalSettingsDefaults.ID, UpdateExperimentalSettingsDefaults, 2 );
1182
+ const configurationRegistry = ( Registry.as(Extensions.Configuration));
1183
+ configurationRegistry.registerConfiguration({
1184
+ ...workbenchConfigurationNodeBase,
1185
+ properties: {
1186
+ [APPLY_ALL_PROFILES_SETTING]: {
1187
+ 'type': 'array',
1188
+ description: ( localizeWithPath(
1189
+ 'vs/workbench/services/configuration/browser/configurationService',
1190
+ 'setting description',
1191
+ "Configure settings to be applied for all profiles."
1192
+ )),
1193
+ 'default': [],
1194
+ 'scope': 1 ,
1195
+ additionalProperties: true,
1196
+ uniqueItems: true,
1197
+ }
1198
+ }
1199
+ });
1200
+
1201
+ export { WorkspaceService };