testConfigurationService.ts 2.0 KB
Newer Older
1 2 3 4 5 6 7 8 9
/*---------------------------------------------------------------------------------------------
 *  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 { TPromise } from 'vs/base/common/winjs.base';
import { EventEmitter } from 'vs/base/common/eventEmitter';
B
Benjamin Pasero 已提交
10
import { getConfigurationKeys } from 'vs/platform/configuration/common/model';
11
import { IConfigurationService, getConfigurationValue, IConfigurationValue, IConfigurationKeys, IConfigurationValues, IConfigurationData, Configuration, ConfigurationModel } from 'vs/platform/configuration/common/configuration';
12 13 14 15 16 17 18 19 20 21 22 23 24 25

export class TestConfigurationService extends EventEmitter implements IConfigurationService {
	public _serviceBrand: any;

	private configuration = Object.create(null);

	public reloadConfiguration<T>(section?: string): TPromise<T> {
		return TPromise.as(this.getConfiguration());
	}

	public getConfiguration(): any {
		return this.configuration;
	}

26 27
	public getConfigurationData(): IConfigurationData<any> {
		return new Configuration(new ConfigurationModel(), new ConfigurationModel(this.configuration)).toData();
28 29
	}

30 31 32 33 34 35 36 37 38 39 40 41 42
	public setUserConfiguration(key: any, value: any): Thenable<void> {
		this.configuration[key] = value;
		return TPromise.as(null);
	}

	public onDidUpdateConfiguration() {
		return { dispose() { } };
	}

	public lookup<C>(key: string): IConfigurationValue<C> {
		return {
			value: getConfigurationValue<C>(this.getConfiguration(), key),
			default: getConfigurationValue<C>(this.getConfiguration(), key),
43
			user: getConfigurationValue<C>(this.getConfiguration(), key),
S
Sandeep Somavarapu 已提交
44 45
			workspace: null,
			folder: null
46 47
		};
	}
B
Benjamin Pasero 已提交
48 49 50 51

	public keys(): IConfigurationKeys {
		return {
			default: getConfigurationKeys(),
52
			user: Object.keys(this.configuration),
53 54
			workspace: [],
			folder: []
B
Benjamin Pasero 已提交
55 56
		};
	}
57 58 59 60

	public values(): IConfigurationValues {
		return {};
	}
61
}