nicer WorkspaceConfiguration creation, #1396

This commit is contained in:
Johannes Rieken
2016-08-25 12:04:25 +02:00
parent e3c810ec52
commit e006e65d19

View File

@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import {clone} from 'vs/base/common/objects';
import {mixin} from 'vs/base/common/objects';
import {illegalState} from 'vs/base/common/errors';
import Event, {Emitter} from 'vs/base/common/event';
import {WorkspaceConfiguration} from 'vscode';
@@ -43,25 +43,23 @@ export class ExtHostConfiguration extends ExtHostConfigurationShape {
? ExtHostConfiguration._lookUp(section, this._config)
: this._config;
let result: any;
if (typeof config !== 'object') {
// this catches missing config and accessing values
result = {};
} else {
result = clone(config);
}
result.has = function(key: string): boolean {
return typeof ExtHostConfiguration._lookUp(key, config) !== 'undefined';
};
result.get = function <T>(key: string, defaultValue?: T): T {
let result = ExtHostConfiguration._lookUp(key, config);
if (typeof result === 'undefined') {
result = defaultValue;
const result: WorkspaceConfiguration = {
has(key: string): boolean {
return typeof ExtHostConfiguration._lookUp(key, config) !== 'undefined';
},
get<T>(key: string, defaultValue?: T): T {
let result = ExtHostConfiguration._lookUp(key, config);
if (typeof result === 'undefined') {
result = defaultValue;
}
return result;
}
return result;
};
if (typeof config === 'object') {
mixin(result, config, false);
}
return Object.freeze(result);
}