From 15cec5d94a65132117d9861d879514383283ab27 Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Fri, 13 Apr 2018 17:49:23 +0200 Subject: [PATCH] #47154 Fix Adopt from cached configuration: Shift to file based configuration only after loading --- .../configuration/node/configuration.ts | 39 +++++++++++++------ .../node/configurationService.ts | 20 ++++++---- 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/src/vs/workbench/services/configuration/node/configuration.ts b/src/vs/workbench/services/configuration/node/configuration.ts index ee01a17a931..d34e9369de0 100644 --- a/src/vs/workbench/services/configuration/node/configuration.ts +++ b/src/vs/workbench/services/configuration/node/configuration.ts @@ -457,21 +457,36 @@ export class FolderConfiguration extends Disposable implements IFolderConfigurat return this._loaded; } - adopt(fileService: IFileService): boolean { - let result = false; - if (fileService && !(this.folderConfiguration instanceof FileServiceBasedFolderConfiguration)) { + adopt(fileService: IFileService): TPromise { + if (fileService) { if (this.folderConfiguration instanceof CachedFolderConfiguration) { - this.folderConfiguration = new FileServiceBasedFolderConfiguration(this.workspaceFolder.uri, this.configFolderRelativePath, this.workbenchState, fileService); - this.updateCache(); - result = true; - } else { - const oldFolderConfiguration = this.folderConfiguration; - this.folderConfiguration = new FileServiceBasedFolderConfiguration(this.workspaceFolder.uri, this.configFolderRelativePath, this.workbenchState, fileService, oldFolderConfiguration); - oldFolderConfiguration.dispose(); + return this.adoptFromCachedConfiguration(fileService); + } + + if (this.folderConfiguration instanceof NodeBasedFolderConfiguration) { + return this.adoptFromNodeBasedConfiguration(fileService); } - this._register(this.folderConfiguration.onDidChange(e => this.onDidFolderConfigurationChange())); } - return result; + return TPromise.as(false); + } + + private adoptFromCachedConfiguration(fileService: IFileService): TPromise { + const folderConfiguration = new FileServiceBasedFolderConfiguration(this.workspaceFolder.uri, this.configFolderRelativePath, this.workbenchState, fileService); + return folderConfiguration.loadConfiguration() + .then(() => { + this.folderConfiguration = folderConfiguration; + this._register(this.folderConfiguration.onDidChange(e => this.onDidFolderConfigurationChange())); + this.updateCache(); + return true; + }); + } + + private adoptFromNodeBasedConfiguration(fileService: IFileService): TPromise { + const oldFolderConfiguration = this.folderConfiguration; + this.folderConfiguration = new FileServiceBasedFolderConfiguration(this.workspaceFolder.uri, this.configFolderRelativePath, this.workbenchState, fileService, oldFolderConfiguration); + oldFolderConfiguration.dispose(); + this._register(this.folderConfiguration.onDidChange(e => this.onDidFolderConfigurationChange())); + return TPromise.as(false); } private onDidFolderConfigurationChange(): void { diff --git a/src/vs/workbench/services/configuration/node/configurationService.ts b/src/vs/workbench/services/configuration/node/configurationService.ts index b2dde23bb54..fbd6fea2cf6 100644 --- a/src/vs/workbench/services/configuration/node/configurationService.ts +++ b/src/vs/workbench/services/configuration/node/configurationService.ts @@ -312,14 +312,18 @@ export class WorkspaceService extends Disposable implements IWorkspaceConfigurat acquireFileService(fileService: IFileService): void { this.fileService = fileService; const changedWorkspaceFolders: IWorkspaceFolder[] = []; - this.cachedFolderConfigs.forEach(folderConfiguration => { - if (folderConfiguration.adopt(fileService)) { - changedWorkspaceFolders.push(folderConfiguration.workspaceFolder); - } - }); - for (const workspaceFolder of changedWorkspaceFolders) { - this.onWorkspaceFolderConfigurationChanged(workspaceFolder); - } + TPromise.join(this.cachedFolderConfigs.values() + .map(folderConfiguration => folderConfiguration.adopt(fileService) + .then(result => { + if (result) { + changedWorkspaceFolders.push(folderConfiguration.workspaceFolder); + } + }))) + .then(() => { + for (const workspaceFolder of changedWorkspaceFolders) { + this.onWorkspaceFolderConfigurationChanged(workspaceFolder); + } + }); } acquireInstantiationService(instantiationService: IInstantiationService): void { -- GitLab