From 66bd1bce0100b52660db06d3a22549b19ef22934 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Tue, 12 Feb 2019 19:23:45 +0100 Subject: [PATCH] debt - get rid of Shell --- src/vs/workbench/electron-browser/main.ts | 44 +++++-- src/vs/workbench/electron-browser/shell.ts | 108 ------------------ .../workbench/electron-browser/workbench.ts | 4 + 3 files changed, 36 insertions(+), 120 deletions(-) delete mode 100644 src/vs/workbench/electron-browser/shell.ts diff --git a/src/vs/workbench/electron-browser/main.ts b/src/vs/workbench/electron-browser/main.ts index 6c1c066a5d5..01050131ed4 100644 --- a/src/vs/workbench/electron-browser/main.ts +++ b/src/vs/workbench/electron-browser/main.ts @@ -5,7 +5,8 @@ import * as nls from 'vs/nls'; import * as perf from 'vs/base/common/performance'; -import { Shell } from 'vs/workbench/electron-browser/shell'; +import { Workbench } from 'vs/workbench/electron-browser/workbench'; +import { ElectronWindow } from 'vs/workbench/electron-browser/window'; import * as browser from 'vs/base/browser/browser'; import { domContentLoaded } from 'vs/base/browser/dom'; import { onUnexpectedError } from 'vs/base/common/errors'; @@ -47,6 +48,10 @@ import { createHash } from 'crypto'; import { IdleValue } from 'vs/base/common/async'; import { setGlobalLeakWarningThreshold } from 'vs/base/common/event'; import { GlobalStorageDatabaseChannelClient } from 'vs/platform/storage/node/storageIpc'; +import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; +import { IStorageService } from 'vs/platform/storage/common/storage'; +import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService'; gracefulFs.gracefulify(fs); // enable gracefulFs @@ -126,20 +131,35 @@ function openWorkbench(configuration: IWindowConfiguration): Promise { const workspaceService = services[0]; const storageService = services[1]; + // Core services + const serviceCollection = new ServiceCollection(); + serviceCollection.set(IWorkspaceContextService, workspaceService); + serviceCollection.set(IConfigurationService, workspaceService); + serviceCollection.set(IEnvironmentService, environmentService); + serviceCollection.set(ILogService, logService); + serviceCollection.set(IStorageService, storageService); + + mainServices.forEach((serviceIdentifier, serviceInstance) => { + serviceCollection.set(serviceIdentifier, serviceInstance); + }); + + const instantiationService = new InstantiationService(serviceCollection, true); + return domContentLoaded().then(() => { perf.mark('willStartWorkbench'); - // Create Shell - const shell = new Shell(document.body, { - contextService: workspaceService, - configurationService: workspaceService, - environmentService, - logService, - storageService - }, mainServices, mainProcessClient, configuration); - - // Open Shell - shell.open(); + // Startup Workbench + const workbench = instantiationService.createInstance( + Workbench, + document.body, + configuration, + serviceCollection, + mainProcessClient + ); + workbench.startup(); + + // Window + workbench.getInstantiationService().createInstance(ElectronWindow); // Inform user about loading issues from the loader (self).require.config({ diff --git a/src/vs/workbench/electron-browser/shell.ts b/src/vs/workbench/electron-browser/shell.ts deleted file mode 100644 index 54f1f63e6b0..00000000000 --- a/src/vs/workbench/electron-browser/shell.ts +++ /dev/null @@ -1,108 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import { Disposable } from 'vs/base/common/lifecycle'; -import { IWindowConfiguration } from 'vs/platform/windows/common/windows'; -import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; -import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; -import { IEnvironmentService } from 'vs/platform/environment/common/environment'; -import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; -import { ILogService } from 'vs/platform/log/common/log'; -import { IStorageService } from 'vs/platform/storage/common/storage'; - -// import@node -import { InstantiationService } from 'vs/platform/instantiation/node/instantiationService'; -import { IPCClient } from 'vs/base/parts/ipc/node/ipc'; - -// import@electron-browser -import { Workbench } from 'vs/workbench/electron-browser/workbench'; -import { ElectronWindow } from 'vs/workbench/electron-browser/window'; - -/** - * Services that we require for the Shell - */ -export interface ICoreServices { - contextService: IWorkspaceContextService; - configurationService: IConfigurationService; - environmentService: IEnvironmentService; - logService: ILogService; - storageService: IStorageService; -} - -/** - * The workbench shell contains the workbench with a rich header containing navigation and the activity bar. - * With the Shell being the top level element in the page, it is also responsible for driving the layouting. - */ -export class Shell extends Disposable { - private storageService: IStorageService; - private environmentService: IEnvironmentService; - private logService: ILogService; - private configurationService: IConfigurationService; - private contextService: IWorkspaceContextService; - - private container: HTMLElement; - private mainProcessClient: IPCClient; - private mainProcessServices: ServiceCollection; - - private configuration: IWindowConfiguration; - - constructor( - container: HTMLElement, - coreServices: ICoreServices, - mainProcessServices: ServiceCollection, - mainProcessClient: IPCClient, - configuration: IWindowConfiguration - ) { - super(); - - this.container = container; - this.mainProcessClient = this._register(mainProcessClient); - - this.configuration = configuration; - - this.contextService = coreServices.contextService; - this.configurationService = coreServices.configurationService; - this.environmentService = coreServices.environmentService; - this.logService = coreServices.logService; - this.storageService = coreServices.storageService; - - this.mainProcessServices = mainProcessServices; - } - - open(): void { - - // Instantiation service with services - const serviceCollection = this.initServiceCollection(); - const instantiationService = new InstantiationService(serviceCollection, true); - - // Workbench - const workbench = this._register(instantiationService.createInstance( - Workbench, - this.container, - this.configuration, - serviceCollection, - this.mainProcessClient - )); - workbench.startup(); - - // Window - workbench.getInstantiationService().createInstance(ElectronWindow); - } - - private initServiceCollection(): ServiceCollection { - const serviceCollection = new ServiceCollection(); - serviceCollection.set(IWorkspaceContextService, this.contextService); - serviceCollection.set(IConfigurationService, this.configurationService); - serviceCollection.set(IEnvironmentService, this.environmentService); - serviceCollection.set(ILogService, this._register(this.logService)); - serviceCollection.set(IStorageService, this.storageService); - - this.mainProcessServices.forEach((serviceIdentifier, serviceInstance) => { - serviceCollection.set(serviceIdentifier, serviceInstance); - }); - - return serviceCollection; - } -} diff --git a/src/vs/workbench/electron-browser/workbench.ts b/src/vs/workbench/electron-browser/workbench.ts index 01cd5f2870c..a3097dd1e29 100644 --- a/src/vs/workbench/electron-browser/workbench.ts +++ b/src/vs/workbench/electron-browser/workbench.ts @@ -351,6 +351,10 @@ export class Workbench extends Disposable implements IPartService { (configuration.filesToOpen && configuration.filesToOpen.length > 0) || (configuration.filesToDiff && configuration.filesToDiff.length > 0); + // TODO@Ben debt + this._register(mainProcessClient); + this._register(logService); + this.registerErrorHandler(); } -- GitLab