From f3ae32fc37c8ef40297e33b28d74e82eaa745ab8 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Wed, 21 Jun 2017 16:09:38 +0200 Subject: [PATCH] more :lipstick: --- src/vs/workbench/api/node/extHost.api.impl.ts | 2 +- .../api/node/extHostConfiguration.ts | 33 ++++++--------- .../api/extHostConfiguration.test.ts | 42 ++++++++++--------- 3 files changed, 36 insertions(+), 41 deletions(-) diff --git a/src/vs/workbench/api/node/extHost.api.impl.ts b/src/vs/workbench/api/node/extHost.api.impl.ts index 4222e4ede3d..022f6232029 100644 --- a/src/vs/workbench/api/node/extHost.api.impl.ts +++ b/src/vs/workbench/api/node/extHost.api.impl.ts @@ -90,7 +90,7 @@ export function createApiFactory( const extHostCommands = col.define(ExtHostContext.ExtHostCommands).set(new ExtHostCommands(threadService, extHostHeapService)); const extHostTreeViews = col.define(ExtHostContext.ExtHostTreeViews).set(new ExtHostTreeViews(threadService, extHostCommands)); const extHostWorkspace = col.define(ExtHostContext.ExtHostWorkspace).set(new ExtHostWorkspace(threadService, initData.workspace)); - const extHostConfiguration = col.define(ExtHostContext.ExtHostConfiguration).set(new ExtHostConfiguration(threadService.get(MainContext.MainThreadConfiguration), initData.configuration, extHostWorkspace)); + const extHostConfiguration = col.define(ExtHostContext.ExtHostConfiguration).set(new ExtHostConfiguration(threadService.get(MainContext.MainThreadConfiguration), extHostWorkspace, initData.configuration)); const extHostDiagnostics = col.define(ExtHostContext.ExtHostDiagnostics).set(new ExtHostDiagnostics(threadService)); const languageFeatures = col.define(ExtHostContext.ExtHostLanguageFeatures).set(new ExtHostLanguageFeatures(threadService, extHostDocuments, extHostCommands, extHostHeapService, extHostDiagnostics)); const extHostFileSystemEvent = col.define(ExtHostContext.ExtHostFileSystemEventService).set(new ExtHostFileSystemEventService()); diff --git a/src/vs/workbench/api/node/extHostConfiguration.ts b/src/vs/workbench/api/node/extHostConfiguration.ts index d437881c7c2..2deff83f11a 100644 --- a/src/vs/workbench/api/node/extHostConfiguration.ts +++ b/src/vs/workbench/api/node/extHostConfiguration.ts @@ -25,41 +25,32 @@ function lookUp(tree: any, key: string) { export class ExtHostConfiguration extends ExtHostConfigurationShape { - private _onDidChangeConfiguration = new Emitter(); - private _proxy: MainThreadConfigurationShape; - private _data: IConfigurationData; - private _extHostWorkspace: ExtHostWorkspace; + private readonly _onDidChangeConfiguration = new Emitter(); + private readonly _proxy: MainThreadConfigurationShape; + private readonly _extHostWorkspace: ExtHostWorkspace; private _configuration: Configuration; - constructor(proxy: MainThreadConfigurationShape, data: IConfigurationData, extWorkspace: ExtHostWorkspace) { + constructor(proxy: MainThreadConfigurationShape, extHostWorkspace: ExtHostWorkspace, data: IConfigurationData) { super(); this._proxy = proxy; - this._data = data; - this._extHostWorkspace = extWorkspace; + this._extHostWorkspace = extHostWorkspace; + this._configuration = Configuration.parse(data, extHostWorkspace.workspace); } get onDidChangeConfiguration(): Event { return this._onDidChangeConfiguration && this._onDidChangeConfiguration.event; } - public $acceptConfigurationChanged(data: IConfigurationData) { - this._configuration = null; - this._data = data; + $acceptConfigurationChanged(data: IConfigurationData) { + this._configuration = Configuration.parse(data, this._extHostWorkspace.workspace); this._onDidChangeConfiguration.fire(undefined); } - private get configuration(): Configuration { - if (!this._configuration) { - this._configuration = Configuration.parse(this._data, this._extHostWorkspace.workspace); - } - return this._configuration; - } - - public getConfiguration(section?: string): WorkspaceConfiguration { + getConfiguration(section?: string): WorkspaceConfiguration { const config = section - ? lookUp(this.configuration.getValue(), section) - : this.configuration.getValue(); + ? lookUp(this._configuration.getValue(), section) + : this._configuration.getValue(); const result: WorkspaceConfiguration = { has(key: string): boolean { @@ -83,7 +74,7 @@ export class ExtHostConfiguration extends ExtHostConfigurationShape { }, inspect: (key: string): { key: string; defaultValue?: T; globalValue?: T; workspaceValue?: T } => { key = section ? `${section}.${key}` : key; - const config = this.configuration.values()[key]; + const config = this._configuration.values()[key]; if (config) { return { key, diff --git a/src/vs/workbench/test/electron-browser/api/extHostConfiguration.test.ts b/src/vs/workbench/test/electron-browser/api/extHostConfiguration.test.ts index 2eb0cb92c07..04d6ba4badb 100644 --- a/src/vs/workbench/test/electron-browser/api/extHostConfiguration.test.ts +++ b/src/vs/workbench/test/electron-browser/api/extHostConfiguration.test.ts @@ -29,11 +29,11 @@ suite('ExtHostConfiguration', function () { if (!shape) { shape = new class extends MainThreadConfigurationShape { }; } - return new ExtHostConfiguration(shape, { + return new ExtHostConfiguration(shape, new ExtHostWorkspace(new TestThreadService(), null), { defaults: new ConfigurationModel(contents), user: new ConfigurationModel(contents), folders: Object.create(null) - }, new ExtHostWorkspace(new TestThreadService(), null)); + }); } test('getConfiguration fails regression test 1.7.1 -> 1.8 #15552', function () { @@ -91,23 +91,27 @@ suite('ExtHostConfiguration', function () { 'wordWrap': 'bounded' } }, ['editor.wordWrap']); - const testObject = new ExtHostConfiguration(new class extends MainThreadConfigurationShape { }, { - defaults: new ConfigurationModel({ - 'editor': { - 'wordWrap': 'off' - } - }, ['editor.wordWrap']), - user: new ConfigurationModel({ - 'editor': { - 'wordWrap': 'on' - } - }, ['editor.wordWrap']), - folders - }, new ExtHostWorkspace(new TestThreadService(), { - 'id': 'foo', - 'roots': [URI.file('foo')], - 'name': 'foo' - })); + const testObject = new ExtHostConfiguration( + new class extends MainThreadConfigurationShape { }, + new ExtHostWorkspace(new TestThreadService(), { + 'id': 'foo', + 'roots': [URI.file('foo')], + 'name': 'foo' + }), + { + defaults: new ConfigurationModel({ + 'editor': { + 'wordWrap': 'off' + } + }, ['editor.wordWrap']), + user: new ConfigurationModel({ + 'editor': { + 'wordWrap': 'on' + } + }, ['editor.wordWrap']), + folders + } + ); const actual = testObject.getConfiguration().inspect('editor.wordWrap'); assert.equal(actual.defaultValue, 'off'); -- GitLab