web.main.ts 4.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import { mark } from 'vs/base/common/performance';
import { domContentLoaded, addDisposableListener, EventType } from 'vs/base/browser/dom';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { ILogService } from 'vs/platform/log/common/log';
import { Disposable } from 'vs/base/common/lifecycle';
11
import { SimpleLogService, SimpleProductService, SimpleWorkbenchEnvironmentService } from 'vs/workbench/browser/web.simpleservices';
12
import { Workbench } from 'vs/workbench/browser/workbench';
A
Alex Dima 已提交
13 14
import { IChannel } from 'vs/base/parts/ipc/common/ipc';
import { REMOTE_FILE_SYSTEM_CHANNEL_NAME, RemoteExtensionsFileSystemProvider } from 'vs/platform/remote/common/remoteAgentFileSystemChannel';
B
Benjamin Pasero 已提交
15 16
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { IProductService } from 'vs/platform/product/common/product';
A
Alex Dima 已提交
17
import { RemoteAgentService } from 'vs/workbench/services/remote/browser/remoteAgentServiceImpl';
B
Benjamin Pasero 已提交
18 19
import { RemoteAuthorityResolverService } from 'vs/platform/remote/browser/remoteAuthorityResolverService';
import { IRemoteAuthorityResolverService } from 'vs/platform/remote/common/remoteAuthorityResolver';
A
Alex Dima 已提交
20
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
B
Benjamin Pasero 已提交
21
import { IFileService } from 'vs/platform/files/common/files';
B
Benjamin Pasero 已提交
22
import { FileService } from 'vs/workbench/services/files/common/fileService';
A
Alex Dima 已提交
23
import { Schemas } from 'vs/base/common/network';
24 25 26 27 28

class CodeRendererMain extends Disposable {

	private workbench: Workbench;

29
	async open(): Promise<void> {
30 31
		const services = this.initServices();

32 33
		await domContentLoaded();
		mark('willStartWorkbench');
34

35 36 37 38 39 40
		// Create Workbench
		this.workbench = new Workbench(
			document.body,
			services.serviceCollection,
			services.logService
		);
41

42 43
		// Layout
		this._register(addDisposableListener(window, EventType.RESIZE, () => this.workbench.layout()));
44

45 46
		// Workbench Lifecycle
		this._register(this.workbench.onShutdown(() => this.dispose()));
47

48 49
		// Startup
		this.workbench.startup();
50 51 52 53 54
	}

	private initServices(): { serviceCollection: ServiceCollection, logService: ILogService } {
		const serviceCollection = new ServiceCollection();

55 56 57 58 59
		// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
		// NOTE: DO NOT ADD ANY OTHER SERVICE INTO THE COLLECTION HERE.
		// CONTRIBUTE IT VIA WORKBENCH.MAIN.TS AND registerSingleton().
		// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

B
Benjamin Pasero 已提交
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
		// Log
		const logService = new SimpleLogService();
		serviceCollection.set(ILogService, logService);

		// Environment
		const environmentService = new SimpleWorkbenchEnvironmentService();
		serviceCollection.set(IWorkbenchEnvironmentService, environmentService);

		// Product
		const productService = new SimpleProductService();
		serviceCollection.set(IProductService, productService);

		// Remote
		const remoteAuthorityResolverService = new RemoteAuthorityResolverService();
		serviceCollection.set(IRemoteAuthorityResolverService, remoteAuthorityResolverService);

A
Alex Dima 已提交
76 77 78
		const remoteAgentService = this._register(new RemoteAgentService(environmentService, productService, remoteAuthorityResolverService));
		serviceCollection.set(IRemoteAgentService, remoteAgentService);

B
Benjamin Pasero 已提交
79
		// Files
B
Benjamin Pasero 已提交
80
		const fileService = this._register(new FileService(logService));
B
Benjamin Pasero 已提交
81 82
		serviceCollection.set(IFileService, fileService);

A
Alex Dima 已提交
83 84 85 86
		const connection = remoteAgentService.getConnection();
		if (connection) {
			const channel = connection.getChannel<IChannel>(REMOTE_FILE_SYSTEM_CHANNEL_NAME);
			const remoteFileSystemProvider = this._register(new RemoteExtensionsFileSystemProvider(channel, remoteAgentService.getEnvironment()));
A
Alex Dima 已提交
87
			fileService.registerProvider(Schemas.vscodeRemote, remoteFileSystemProvider);
A
Alex Dima 已提交
88 89
		}

90 91 92 93 94 95 96 97 98
		return { serviceCollection, logService };
	}
}

export function main(): Promise<void> {
	const renderer = new CodeRendererMain();

	return renderer.open();
}