From 4600555b587114e51f37f9eb48b00d0b8164f5bc Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Thu, 28 Mar 2019 12:35:45 +0100 Subject: [PATCH] change the order while entering workspace: initialise, stop and start --- .../node/configurationService.ts | 8 +-- .../workspace/node/workspaceEditingService.ts | 67 ++++++------------- 2 files changed, 23 insertions(+), 52 deletions(-) diff --git a/src/vs/workbench/services/configuration/node/configurationService.ts b/src/vs/workbench/services/configuration/node/configurationService.ts index df6d6bd1018..9a5ddba56c5 100644 --- a/src/vs/workbench/services/configuration/node/configurationService.ts +++ b/src/vs/workbench/services/configuration/node/configurationService.ts @@ -284,10 +284,10 @@ export class WorkspaceService extends Disposable implements IConfigurationServic return this._configuration.keys(); } - initialize(arg: IWorkspaceInitializationPayload, postInitialisationTask: () => void = () => null): Promise { + initialize(arg: IWorkspaceInitializationPayload): Promise { mark('willInitWorkspaceService'); return this.createWorkspace(arg) - .then(workspace => this.updateWorkspaceAndInitializeConfiguration(workspace, postInitialisationTask)).then(() => { + .then(workspace => this.updateWorkspaceAndInitializeConfiguration(workspace)).then(() => { mark('didInitWorkspaceService'); }); } @@ -382,7 +382,7 @@ export class WorkspaceService extends Disposable implements IConfigurationServic } } - private updateWorkspaceAndInitializeConfiguration(workspace: Workspace, postInitialisationTask: () => void): Promise { + private updateWorkspaceAndInitializeConfiguration(workspace: Workspace): Promise { const hasWorkspaceBefore = !!this.workspace; let previousState: WorkbenchState; let previousWorkspacePath: string | undefined; @@ -399,8 +399,6 @@ export class WorkspaceService extends Disposable implements IConfigurationServic return this.initializeConfiguration().then(() => { - postInitialisationTask(); // Post initialisation task should be run before triggering events. - // Trigger changes after configuration initialization so that configuration is up to date. if (hasWorkspaceBefore) { const newState = this.getWorkbenchState(); diff --git a/src/vs/workbench/services/workspace/node/workspaceEditingService.ts b/src/vs/workbench/services/workspace/node/workspaceEditingService.ts index 175e3b88c26..0018a239582 100644 --- a/src/vs/workbench/services/workspace/node/workspaceEditingService.ts +++ b/src/vs/workbench/services/workspace/node/workspaceEditingService.ts @@ -334,64 +334,37 @@ export class WorkspaceEditingService implements IWorkspaceEditingService { ); } - enterWorkspace(path: URI): Promise { + async enterWorkspace(path: URI): Promise { if (!!this.environmentService.extensionTestsLocationURI) { return Promise.reject(new Error('Entering a new workspace is not possible in tests.')); } + const workspace = await this.workspaceService.getWorkspaceIdentifier(path); + // Settings migration (only if we come from a folder workspace) + if (this.contextService.getWorkbenchState() === WorkbenchState.FOLDER) { + await this.migrateWorkspaceSettings(workspace); + } + const workspaceImpl = this.contextService as WorkspaceService; + await workspaceImpl.initialize(workspace); + // Restart extension host if first root folder changed (impact on deprecated workspace.rootPath API) // Stop the extension host first to give extensions most time to shutdown this.extensionService.stopExtensionHost(); - let extensionHostStarted: boolean = false; - const startExtensionHost = () => { - if (this.windowService.getConfiguration().remoteAuthority) { - this.windowService.reloadWindow(); // TODO aeschli: workaround until restarting works + const result = await this.windowService.enterWorkspace(path); + if (result) { + await this.migrateStorage(result.workspace); + // Reinitialize backup service + if (this.backupFileService instanceof BackupFileService) { + this.backupFileService.initialize(result.backupPath!); } + } + if (this.windowService.getConfiguration().remoteAuthority) { + this.windowService.reloadWindow(); // TODO aeschli: workaround until restarting works + } else { this.extensionService.startExtensionHost(); - extensionHostStarted = true; - }; - - return this.windowService.enterWorkspace(path).then(result => { - - // Migrate storage and settings if we are to enter a workspace - if (result) { - return this.migrate(result.workspace).then(() => { - - // Reinitialize backup service - if (this.backupFileService instanceof BackupFileService) { - this.backupFileService.initialize(result.backupPath!); - } - - // Reinitialize configuration service - const workspaceImpl = this.contextService as WorkspaceService; - return workspaceImpl.initialize(result.workspace, startExtensionHost); - }); - } - - return Promise.resolve(); - }).then(undefined, error => { - if (!extensionHostStarted) { - startExtensionHost(); // start the extension host if not started - } - - return Promise.reject(error); - }); - } - - private migrate(toWorkspace: IWorkspaceIdentifier): Promise { - - // Storage migration - return this.migrateStorage(toWorkspace).then(() => { - - // Settings migration (only if we come from a folder workspace) - if (this.contextService.getWorkbenchState() === WorkbenchState.FOLDER) { - return this.migrateWorkspaceSettings(toWorkspace); - } - - return undefined; - }); + } } private migrateStorage(toWorkspace: IWorkspaceIdentifier): Promise { -- GitLab