configuration.ts 21.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
'use strict';

import URI from 'vs/base/common/uri';
import * as paths from 'vs/base/common/paths';
import { TPromise } from 'vs/base/common/winjs.base';
import Event, { Emitter } from 'vs/base/common/event';
11
import { StrictResourceMap, TrieMap } from 'vs/base/common/map';
12 13 14 15 16 17 18 19 20
import { distinct, equals } from "vs/base/common/arrays";
import * as objects from 'vs/base/common/objects';
import * as errors from 'vs/base/common/errors';
import * as collections from 'vs/base/common/collections';
import { Disposable } from "vs/base/common/lifecycle";
import { Schemas } from "vs/base/common/network";
import { RunOnceScheduler } from 'vs/base/common/async';
import { readFile } from 'vs/base/node/pfs';
import * as extfs from 'vs/base/node/extfs';
B
Benjamin Pasero 已提交
21
import { IWorkspaceContextService, IWorkspace2, Workspace as LegacyWorkspace, IWorkspace as ILegacyWorkspace } from "vs/platform/workspace/common/workspace";
22 23
import { FileChangeType, FileChangesEvent, isEqual, isEqualOrParent } from 'vs/platform/files/common/files';
import { isLinux } from 'vs/base/common/platform';
24
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
25 26
import { CustomConfigurationModel } from 'vs/platform/configuration/common/model';
import { ScopedConfigurationModel, FolderConfigurationModel, FolderSettingsModel } from 'vs/workbench/services/configuration/common/configurationModels';
27
import { IConfigurationServiceEvent, ConfigurationSource, IConfigurationKeys, IConfigurationValue, ConfigurationModel, IConfigurationOptions, Configuration as BaseConfiguration, IConfigurationValues, IConfigurationData } from 'vs/platform/configuration/common/configuration';
28
import { IWorkspaceConfigurationService, WORKSPACE_CONFIG_FOLDER_DEFAULT_NAME, WORKSPACE_STANDALONE_CONFIGURATIONS, WORKSPACE_CONFIG_DEFAULT_PATH } from 'vs/workbench/services/configuration/common/configuration';
29
import { ConfigurationService as GlobalConfigurationService } from 'vs/platform/configuration/node/configurationService';
B
Benjamin Pasero 已提交
30 31
import { createHash } from "crypto";
import { basename } from "path";
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

interface IStat {
	resource: URI;
	isDirectory?: boolean;
	children?: { resource: URI; }[];
}

interface IContent {
	resource: URI;
	value: string;
}

interface IWorkspaceConfiguration<T> {
	workspace: T;
	consolidated: any;
}

type IWorkspaceFoldersConfiguration = { [rootFolder: string]: { folders: string[]; } };

51
class Workspace implements IWorkspace2 {
B
Benjamin Pasero 已提交
52
	private _name: string;
53

54 55
	constructor(
		public readonly id: string,
B
Benjamin Pasero 已提交
56
		private _roots: URI[]
57 58
	) {
		//
59
	}
B
Benjamin Pasero 已提交
60 61 62 63 64 65 66 67 68 69 70 71

	public set roots(roots: URI[]) {
		this._roots = roots;
		this._name = null; // will be recomputed based on roots next time accessed
	}

	public get roots(): URI[] {
		return this._roots;
	}

	public get name(): string {
		if (!this._name) {
72
			this._name = this.roots.map(root => basename(root.fsPath) || root.fsPath).join(', ');
B
Benjamin Pasero 已提交
73 74 75 76
		}

		return this._name;
	}
B
Benjamin Pasero 已提交
77 78 79 80

	public toJSON(): IWorkspace2 {
		return { id: this.id, roots: this.roots, name: this.name };
	}
81 82
}

83
export class WorkspaceConfigurationService extends Disposable implements IWorkspaceContextService, IWorkspaceConfigurationService {
84 85 86

	public _serviceBrand: any;

87 88
	private readonly _onDidChangeWorkspaceRoots: Emitter<URI[]> = this._register(new Emitter<URI[]>());
	public readonly onDidChangeWorkspaceRoots: Event<URI[]> = this._onDidChangeWorkspaceRoots.event;
89 90 91 92 93 94

	private readonly _onDidUpdateConfiguration: Emitter<IConfigurationServiceEvent> = this._register(new Emitter<IConfigurationServiceEvent>());
	public readonly onDidUpdateConfiguration: Event<IConfigurationServiceEvent> = this._onDidUpdateConfiguration.event;

	private baseConfigurationService: GlobalConfigurationService<any>;

95
	private cachedFolderConfigs: StrictResourceMap<FolderConfiguration<any>>;
96

97
	private readonly workspace: Workspace;
98 99
	private rootsTrieMap: TrieMap<URI> = new TrieMap<URI>(TrieMap.PathSplitter);
	private _configuration: Configuration<any>;
100

B
Benjamin Pasero 已提交
101
	constructor(private environmentService: IEnvironmentService, private legacyWorkspace?: LegacyWorkspace, private workspaceSettingsRootFolder: string = WORKSPACE_CONFIG_FOLDER_DEFAULT_NAME) {
102 103
		super();

B
Benjamin Pasero 已提交
104 105 106
		if (legacyWorkspace) {
			const workspaceId = createHash('md5').update(legacyWorkspace.resource.fsPath).update(legacyWorkspace.ctime ? String(legacyWorkspace.ctime) : '').digest('hex');
			this.workspace = new Workspace(workspaceId, [legacyWorkspace.resource]);
107 108 109 110
		} else {
			this.workspace = null;
		}

111 112 113 114 115
		this.rootsTrieMap = new TrieMap<URI>(TrieMap.PathSplitter);
		if (this.workspace) {
			this.rootsTrieMap.insert(this.workspace.roots[0].fsPath, this.workspace.roots[0]);
		}
		this._register(this.onDidUpdateConfiguration(e => this.resolveAdditionalFolders(true)));
116 117 118

		this.baseConfigurationService = this._register(new GlobalConfigurationService(environmentService));
		this._register(this.baseConfigurationService.onDidUpdateConfiguration(e => this.onBaseConfigurationChanged(e)));
119 120 121
		this._register(this.onDidChangeWorkspaceRoots(e => this.onRootsChanged()));

		this.initCaches();
122 123 124 125 126 127 128 129
	}

	private resolveAdditionalFolders(notify?: boolean): void {
		if (!this.workspace) {
			return; // no additional folders for empty workspaces
		}

		// Resovled configured folders for workspace
130 131
		let [master] = this.workspace.roots;
		let configuredFolders: URI[] = [master];
132 133
		const config = this.getConfiguration<IWorkspaceFoldersConfiguration>('workspace');
		if (config) {
134
			const workspaceConfig = config[master.toString()];
135 136 137 138 139 140 141 142 143 144 145 146 147
			if (workspaceConfig) {
				const additionalFolders = workspaceConfig.folders
					.map(f => URI.parse(f))
					.filter(r => r.scheme === Schemas.file); // only support files for now

				configuredFolders.push(...additionalFolders);
			}
		}

		// Remove duplicates
		configuredFolders = distinct(configuredFolders, r => r.toString());

		// Find changes
148
		const changed = !equals(this.workspace.roots, configuredFolders, (r1, r2) => r1.toString() === r2.toString());
149

150
		this.workspace.roots = configuredFolders;
151

152 153 154 155 156 157 158 159 160
		if (changed) {
			this.rootsTrieMap = new TrieMap<URI>(TrieMap.PathSplitter);
			for (const folder of this.workspace.roots) {
				this.rootsTrieMap.insert(folder.fsPath, folder);
			}

			if (notify) {
				this._onDidChangeWorkspaceRoots.fire(configuredFolders);
			}
161 162 163
		}
	}

B
Benjamin Pasero 已提交
164 165
	public getWorkspace(): ILegacyWorkspace {
		return this.legacyWorkspace;
166 167
	}

168
	public getWorkspace2(): IWorkspace2 {
169 170 171 172 173 174 175
		return this.workspace;
	}

	public hasWorkspace(): boolean {
		return !!this.workspace;
	}

176 177 178 179 180 181 182 183
	public getRoot(resource: URI): URI {
		return this.rootsTrieMap.findSubstr(resource.fsPath);
	}

	private get workspaceUri(): URI {
		return this.workspace ? this.workspace.roots[0] : null;
	}

184
	public isInsideWorkspace(resource: URI): boolean {
185
		return !!this.getRoot(resource);
186 187 188
	}

	public toWorkspaceRelativePath(resource: URI, toOSPath?: boolean): string {
B
Benjamin Pasero 已提交
189
		return this.workspace ? this.legacyWorkspace.toWorkspaceRelativePath(resource, toOSPath) : null;
190 191 192
	}

	public toResource(workspaceRelativePath: string): URI {
B
Benjamin Pasero 已提交
193
		return this.workspace ? this.legacyWorkspace.toResource(workspaceRelativePath) : null;
194 195
	}

196 197 198 199 200
	public getConfigurationData<T>(): IConfigurationData<T> {
		return this._configuration.toData();
	}

	public get configuration(): BaseConfiguration<any> {
201
		return this._configuration;
202 203 204 205 206
	}

	public getConfiguration<C>(section?: string): C
	public getConfiguration<C>(options?: IConfigurationOptions): C
	public getConfiguration<C>(arg?: any): C {
207
		return this._configuration.getValue<C>(this.toOptions(arg));
208 209
	}

210 211
	public lookup<C>(key: string, overrideIdentifier?: string): IConfigurationValue<C> {
		return this._configuration.lookup<C>(key, overrideIdentifier);
212 213
	}

214 215 216
	public keys(): IConfigurationKeys {
		return this._configuration.keys();
	}
217

218
	public values<V>(): IConfigurationValues {
219
		return this._configuration.values();
220 221
	}

222 223 224
	public getUnsupportedWorkspaceKeys(): string[] {
		return this.workspace ? this._configuration.getFolderConfigurationModel(this.workspace.roots[0]).workspaceSettingsConfig.unsupportedKeys : [];
	}
225

226 227 228 229 230 231
	public reloadConfiguration(section?: string): TPromise<any> {
		const current = this._configuration;

		return this.baseConfigurationService.reloadConfiguration()
			.then(() => this.initialize()) // Reinitialize to ensure we are hitting the disk
			.then(() => !this._configuration.equals(current)) // Check if the configuration is changed
232
			.then(changed => changed ? this.trigger(ConfigurationSource.Workspace, ) : void 0) // Trigger event if changed
233 234 235 236 237 238 239 240 241 242 243
			.then(() => this.getConfiguration(section));
	}

	public handleWorkspaceFileEvents(event: FileChangesEvent): void {
		if (this.workspace) {
			TPromise.join(this.workspace.roots.map(folder => this.cachedFolderConfigs.get(folder).handleWorkspaceFileEvents(event))) // handle file event for each folder
				.then(folderConfigurations =>
					folderConfigurations.map((configuration, index) => ({ configuration, folder: this.workspace.roots[index] }))
						.filter(folderConfiguration => !!folderConfiguration.configuration) // Filter folders which are not impacted by events
						.map(folderConfiguration => this._configuration.updateFolderConfiguration(folderConfiguration.folder, folderConfiguration.configuration)) // Update the configuration of impacted folders
						.reduce((result, value) => result || value, false)) // Check if the effective configuration of folder is changed
244
				.then(changed => changed ? this.trigger(ConfigurationSource.Workspace) : void 0); // Trigger event if changed
245
		}
246
	}
247

248 249 250
	public initialize(): TPromise<any> {
		this.initCaches();
		return this.doInitialize(this.workspace ? this.workspace.roots : []);
251 252
	}

253 254 255 256
	private onRootsChanged(): void {
		if (!this.workspace) {
			return;
		}
257

258
		let configurationChanged = false;
259

260 261 262 263 264 265
		// Remove the configurations of deleted folders
		for (const key of this.cachedFolderConfigs.keys()) {
			if (!this.workspace.roots.filter(folder => folder.toString() === key.toString())[0]) {
				this.cachedFolderConfigs.delete(key);
				if (this._configuration.deleteFolderConfiguration(key)) {
					configurationChanged = true;
266
				}
267 268 269 270 271 272 273 274 275
			}
		}

		// Initialize the newly added folders
		const toInitialize = this.workspace.roots.filter(folder => !this.cachedFolderConfigs.has(folder));
		if (toInitialize.length) {
			this.initCachesForFolders(toInitialize);
			this.doInitialize(toInitialize)
				.then(changed => configurationChanged || changed)
276
				.then(changed => changed ? this.trigger(ConfigurationSource.Workspace) : void 0);
277 278 279 280 281
		}
	}

	private initCaches(): void {
		this.cachedFolderConfigs = new StrictResourceMap<FolderConfiguration<any>>();
S
Sandeep Somavarapu 已提交
282
		this._configuration = new Configuration(<any>this.baseConfigurationService.configuration(), new StrictResourceMap<FolderConfigurationModel<any>>(), this.workspaceUri);
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
		this.initCachesForFolders(this.workspace ? this.workspace.roots : []);
	}

	private initCachesForFolders(folders: URI[]): void {
		for (const folder of folders) {
			this.cachedFolderConfigs.set(folder, new FolderConfiguration(folder, this.workspaceSettingsRootFolder, this.workspace));
		}
	}

	private doInitialize(folders: URI[]): TPromise<boolean> {
		return TPromise.join(folders.map(folder => this.cachedFolderConfigs.get(folder).loadConfiguration()
			.then(configuration => this._configuration.updateFolderConfiguration(folder, configuration))))
			.then(changed => changed.reduce((result, value) => result || value, false));
	}

	private onBaseConfigurationChanged(event: IConfigurationServiceEvent): void {
		if (event.source === ConfigurationSource.Default) {
			if (this.workspace) {
				this.workspace.roots.forEach(folder => this._configuration.getFolderConfigurationModel(folder).update());
			}
		}

S
Sandeep Somavarapu 已提交
305
		if (this._configuration.updateBaseConfiguration(<any>this.baseConfigurationService.configuration())) {
306
			this.trigger(event.source, event.sourceConfig);
307 308 309
		}
	}

310 311
	private trigger(source: ConfigurationSource, sourceConfig: any = this._configuration.getFolderConfigurationModel(this.workspace.roots[0]).contents): void {
		this._onDidUpdateConfiguration.fire({ source, sourceConfig });
312 313 314 315 316 317 318 319 320 321 322
	}

	private toOptions(arg: any): IConfigurationOptions {
		if (typeof arg === 'string') {
			return { section: arg };
		}
		if (typeof arg === 'object') {
			return arg;
		}
		return {};
	}
323
}
324

325
class FolderConfiguration<T> extends Disposable {
326

327
	private static RELOAD_CONFIGURATION_DELAY = 50;
328

329 330 331 332 333 334 335 336
	private bulkFetchFromWorkspacePromise: TPromise<any>;
	private workspaceFilePathToConfiguration: { [relativeWorkspacePath: string]: TPromise<ConfigurationModel<any>> };

	private reloadConfigurationScheduler: RunOnceScheduler;
	private reloadConfigurationEventEmitter: Emitter<FolderConfigurationModel<T>> = new Emitter<FolderConfigurationModel<T>>();

	constructor(private folder: URI, private configFolderRelativePath: string, private workspace: Workspace) {
		super();
337

338 339 340
		this.workspaceFilePathToConfiguration = Object.create(null);
		this.reloadConfigurationScheduler = this._register(new RunOnceScheduler(() => this.loadConfiguration().then(configuration => this.reloadConfigurationEventEmitter.fire(configuration), errors.onUnexpectedError), FolderConfiguration.RELOAD_CONFIGURATION_DELAY));
	}
341

342
	loadConfiguration(): TPromise<FolderConfigurationModel<T>> {
343
		if (!this.workspace) {
344
			return TPromise.wrap(new FolderConfigurationModel<T>(new FolderSettingsModel<T>(null), []));
345 346
		}

347 348 349 350 351 352 353 354 355 356
		// Load workspace locals
		return this.loadWorkspaceConfigFiles().then(workspaceConfigFiles => {
			// Consolidate (support *.json files in the workspace settings folder)
			const workspaceSettingsConfig = <FolderSettingsModel<T>>workspaceConfigFiles[WORKSPACE_CONFIG_DEFAULT_PATH] || new FolderSettingsModel<T>(null);
			const otherConfigModels = Object.keys(workspaceConfigFiles).filter(key => key !== WORKSPACE_CONFIG_DEFAULT_PATH).map(key => <ScopedConfigurationModel<T>>workspaceConfigFiles[key]);
			return new FolderConfigurationModel<T>(workspaceSettingsConfig, otherConfigModels);
		});
	}

	private loadWorkspaceConfigFiles<T>(): TPromise<{ [relativeWorkspacePath: string]: ConfigurationModel<T> }> {
357 358
		// once: when invoked for the first time we fetch json files that contribute settings
		if (!this.bulkFetchFromWorkspacePromise) {
359
			this.bulkFetchFromWorkspacePromise = resolveStat(this.toResource(this.configFolderRelativePath)).then(stat => {
360 361 362 363 364 365 366 367 368 369
				if (!stat.isDirectory) {
					return TPromise.as([]);
				}

				return resolveContents(stat.children.filter(stat => {
					const isJson = paths.extname(stat.resource.fsPath) === '.json';
					if (!isJson) {
						return false; // only JSON files
					}

B
Benjamin Pasero 已提交
370
					return this.isWorkspaceConfigurationFile(this.toFolderRelativePath(stat.resource)); // only workspace config files
371 372 373
				}).map(stat => stat.resource));
			}, err => [] /* never fail this call */)
				.then((contents: IContent[]) => {
B
Benjamin Pasero 已提交
374
					contents.forEach(content => this.workspaceFilePathToConfiguration[this.toFolderRelativePath(content.resource)] = TPromise.as(this.createConfigModel(content)));
375 376 377 378 379 380 381 382
				}, errors.onUnexpectedError);
		}

		// on change: join on *all* configuration file promises so that we can merge them into a single configuration object. this
		// happens whenever a config file changes, is deleted, or added
		return this.bulkFetchFromWorkspacePromise.then(() => TPromise.join(this.workspaceFilePathToConfiguration));
	}

383
	public handleWorkspaceFileEvents(event: FileChangesEvent): TPromise<FolderConfigurationModel<T>> {
384
		if (!this.workspace) {
385
			return TPromise.wrap(null);
386 387 388 389 390 391 392 393 394
		}

		const events = event.changes;
		let affectedByChanges = false;

		// Find changes that affect workspace configuration files
		for (let i = 0, len = events.length; i < len; i++) {
			const resource = events[i].resource;
			const isJson = paths.extname(resource.fsPath) === '.json';
395
			const isDeletedSettingsFolder = (events[i].type === FileChangeType.DELETED && isEqual(paths.basename(resource.fsPath), this.configFolderRelativePath));
396 397 398 399
			if (!isJson && !isDeletedSettingsFolder) {
				continue; // only JSON files or the actual settings folder
			}

B
Benjamin Pasero 已提交
400
			const workspacePath = this.toFolderRelativePath(resource);
401 402 403 404 405
			if (!workspacePath) {
				continue; // event is not inside workspace
			}

			// Handle case where ".vscode" got deleted
406
			if (workspacePath === this.configFolderRelativePath && events[i].type === FileChangeType.DELETED) {
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428
				this.workspaceFilePathToConfiguration = Object.create(null);
				affectedByChanges = true;
			}

			// only valid workspace config files
			if (!this.isWorkspaceConfigurationFile(workspacePath)) {
				continue;
			}

			// insert 'fetch-promises' for add and update events and
			// remove promises for delete events
			switch (events[i].type) {
				case FileChangeType.DELETED:
					affectedByChanges = collections.remove(this.workspaceFilePathToConfiguration, workspacePath);
					break;
				case FileChangeType.UPDATED:
				case FileChangeType.ADDED:
					this.workspaceFilePathToConfiguration[workspacePath] = resolveContent(resource).then(content => this.createConfigModel(content), errors.onUnexpectedError);
					affectedByChanges = true;
			}
		}

429 430
		if (!affectedByChanges) {
			return TPromise.as(null);
431
		}
432 433 434 435 436 437 438 439 440 441 442

		return new TPromise((c, e) => {
			let disposable = this.reloadConfigurationEventEmitter.event(configuration => {
				disposable.dispose();
				c(configuration);
			});
			// trigger reload of the configuration if we are affected by changes
			if (!this.reloadConfigurationScheduler.isScheduled()) {
				this.reloadConfigurationScheduler.schedule();
			}
		});
443 444
	}

445
	private createConfigModel<T>(content: IContent): ConfigurationModel<T> {
B
Benjamin Pasero 已提交
446
		const path = this.toFolderRelativePath(content.resource);
447
		if (path === WORKSPACE_CONFIG_DEFAULT_PATH) {
448
			return new FolderSettingsModel<T>(content.value, content.resource.toString());
449 450 451
		} else {
			const matches = /\/([^\.]*)*\.json/.exec(path);
			if (matches && matches[1]) {
452
				return new ScopedConfigurationModel<T>(content.value, content.resource.toString(), matches[1]);
453 454 455
			}
		}

456
		return new CustomConfigurationModel<T>(null);
457 458
	}

B
Benjamin Pasero 已提交
459 460
	private isWorkspaceConfigurationFile(folderRelativePath: string): boolean {
		return [WORKSPACE_CONFIG_DEFAULT_PATH, WORKSPACE_STANDALONE_CONFIGURATIONS.launch, WORKSPACE_STANDALONE_CONFIGURATIONS.tasks].some(p => p === folderRelativePath);
461 462
	}

B
Benjamin Pasero 已提交
463 464 465
	private toResource(folderRelativePath: string): URI {
		if (typeof folderRelativePath === 'string') {
			return URI.file(paths.join(this.folder.fsPath, folderRelativePath));
466 467 468 469 470
		}

		return null;
	}

B
Benjamin Pasero 已提交
471
	private toFolderRelativePath(resource: URI, toOSPath?: boolean): string {
472 473
		if (this.contains(resource)) {
			return paths.normalize(paths.relative(this.folder.fsPath, resource.fsPath), toOSPath);
474 475
		}

476
		return null;
477 478
	}

479 480 481
	private contains(resource: URI): boolean {
		if (resource) {
			return isEqualOrParent(resource.fsPath, this.folder.fsPath, !isLinux /* ignorecase */);
482 483
		}

484
		return false;
485
	}
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521
}

// node.hs helper functions

function resolveContents(resources: URI[]): TPromise<IContent[]> {
	const contents: IContent[] = [];

	return TPromise.join(resources.map(resource => {
		return resolveContent(resource).then(content => {
			contents.push(content);
		});
	})).then(() => contents);
}

function resolveContent(resource: URI): TPromise<IContent> {
	return readFile(resource.fsPath).then(contents => ({ resource, value: contents.toString() }));
}

function resolveStat(resource: URI): TPromise<IStat> {
	return new TPromise<IStat>((c, e) => {
		extfs.readdir(resource.fsPath, (error, children) => {
			if (error) {
				if ((<any>error).code === 'ENOTDIR') {
					c({ resource });
				} else {
					e(error);
				}
			} else {
				c({
					resource,
					isDirectory: true,
					children: children.map(child => { return { resource: URI.file(paths.join(resource.fsPath, child)) }; })
				});
			}
		});
	});
522
}
523

524
class Configuration<T> extends BaseConfiguration<T> {
525

526
	constructor(private _baseConfiguration: Configuration<T>, protected folders: StrictResourceMap<FolderConfigurationModel<T>>, workspaceUri: URI) {
527 528 529
		super(_baseConfiguration.defaults, _baseConfiguration.user, folders, workspaceUri);
	}

530
	updateBaseConfiguration(baseConfiguration: Configuration<T>): boolean {
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582
		const current = new Configuration(this._baseConfiguration, this.folders, this.workspaceUri);

		this._defaults = baseConfiguration.defaults;
		this._user = baseConfiguration.user;
		this.merge();

		return !this.equals(current);
	}

	updateFolderConfiguration(resource: URI, configuration: FolderConfigurationModel<T>): boolean {
		this.folders.set(resource, configuration);
		const current = this.getValue({ resource });
		this.mergeFolder(resource);
		return !objects.equals(current, this.getValue({ resource }));
	}

	deleteFolderConfiguration(folder: URI): boolean {
		if (this.workspaceUri && this.workspaceUri.fsPath === folder.fsPath) {
			// Do not remove workspace configuration
			return false;
		}

		this.folders.delete(folder);
		return this._foldersConsolidated.delete(folder);
	}

	getFolderConfigurationModel(folder: URI): FolderConfigurationModel<T> {
		return <FolderConfigurationModel<T>>this.folders.get(folder);
	}

	equals(other: any): boolean {
		if (!other || !(other instanceof Configuration)) {
			return false;
		}

		if (!objects.equals(this.getValue(), other.getValue())) {
			return false;
		}

		if (this._foldersConsolidated.size !== other._foldersConsolidated.size) {
			return false;
		}

		for (const resource of this._foldersConsolidated.keys()) {
			if (!objects.equals(this.getValue({ resource }), other.getValue({ resource }))) {
				return false;
			}
		}

		return true;
	}
}