提交 068f7bb9 编写于 作者: A Alex Dima

Simplify RPCProtocol usage (#36972)

上级 64375e46
......@@ -26,6 +26,7 @@ import { EnvironmentService } from 'vs/platform/environment/node/environmentServ
import { createLogService } from 'vs/platform/log/node/spdlogService';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { ILogService } from 'vs/platform/log/common/log';
import { IMessagePassingProtocol } from 'vs/base/parts/ipc/common/ipc';
// const nativeExit = process.exit.bind(process);
function patchProcess(allowExit: boolean) {
......@@ -80,7 +81,7 @@ export class ExtensionHostMain {
private _logService: ILogService;
private disposables: IDisposable[] = [];
constructor(rpcProtocol: RPCProtocol, initData: IInitData) {
constructor(protocol: IMessagePassingProtocol, initData: IInitData) {
this._environment = initData.environment;
this._workspace = initData.workspace;
......@@ -88,7 +89,7 @@ export class ExtensionHostMain {
patchProcess(allowExit);
// services
const threadService = new ExtHostThreadService(rpcProtocol);
const threadService = new ExtHostThreadService(new RPCProtocol(protocol));
const extHostWorkspace = new ExtHostWorkspace(threadService, initData.workspace);
const environmentService = new EnvironmentService(initData.args, initData.execPath);
this._logService = createLogService(`exthost${initData.windowId}`, environmentService);
......
......@@ -7,7 +7,6 @@
import { onUnexpectedError } from 'vs/base/common/errors';
import { ExtensionHostMain, exit } from 'vs/workbench/node/extensionHostMain';
import { RPCProtocol } from 'vs/workbench/services/extensions/node/rpcProtocol';
import { parse } from 'vs/base/common/marshalling';
import { IInitData } from 'vs/workbench/api/node/extHost.protocol';
import { IMessagePassingProtocol } from 'vs/base/parts/ipc/common/ipc';
......@@ -16,7 +15,7 @@ import { createConnection } from 'net';
import Event, { filterEvent } from 'vs/base/common/event';
interface IRendererConnection {
rpcProtocol: RPCProtocol;
protocol: IMessagePassingProtocol;
initData: IInitData;
}
......@@ -70,7 +69,6 @@ function connectToRenderer(protocol: IMessagePassingProtocol): Promise<IRenderer
first.dispose();
const initData = parse(raw);
const rpcProtocol = new RPCProtocol(protocol);
// Print a console message when rejection isn't handled within N seconds. For details:
// see https://nodejs.org/api/process.html#process_event_unhandledrejection
......@@ -111,7 +109,7 @@ function connectToRenderer(protocol: IMessagePassingProtocol): Promise<IRenderer
// Tell the outside that we are initialized
protocol.send('initialized');
c({ rpcProtocol, initData });
c({ protocol, initData });
});
// Tell the outside that we are ready to receive messages
......@@ -126,7 +124,7 @@ createExtHostProtocol().then(protocol => {
return connectToRenderer(protocol);
}).then(renderer => {
// setup things
const extensionHostMain = new ExtensionHostMain(renderer.rpcProtocol, renderer.initData);
const extensionHostMain = new ExtensionHostMain(renderer.protocol, renderer.initData);
onTerminate = () => extensionHostMain.terminate();
return extensionHostMain.start();
}).catch(err => console.error(err));
......
......@@ -41,9 +41,13 @@ import Event, { Emitter } from 'vs/base/common/event';
import { ExtensionHostProfiler } from 'vs/workbench/services/extensions/electron-browser/extensionHostProfiler';
import { ReloadWindowAction } from 'vs/workbench/electron-browser/actions';
import product from 'vs/platform/node/product';
import * as strings from 'vs/base/common/strings';
const SystemExtensionsRoot = path.normalize(path.join(URI.parse(require.toUrl('')).fsPath, '..', 'extensions'));
// Enable to see detailed message communication between window and extension host
const logExtensionHostCommunication = false;
function messageWithSource(msg: IMessage): string {
return messageWithSource2(msg.source, msg.message);
}
......@@ -230,7 +234,11 @@ export class ExtensionService extends Disposable implements IExtensionService {
private _createExtensionHostCustomers(protocol: IMessagePassingProtocol): ExtHostExtensionServiceShape {
this._extensionHostProcessThreadService = this._instantiationService.createInstance(MainThreadService, protocol);
if (logExtensionHostCommunication || this._environmentService.logExtensionHostCommunication) {
protocol = asLoggingProtocol(protocol);
}
this._extensionHostProcessThreadService = new MainThreadService(protocol);
const extHostContext: IExtHostContext = this._extensionHostProcessThreadService;
// Named customers
......@@ -695,6 +703,22 @@ export class ExtensionService extends Disposable implements IExtensionService {
}
}
function asLoggingProtocol(protocol: IMessagePassingProtocol): IMessagePassingProtocol {
protocol.onMessage(msg => {
console.log('%c[Extension \u2192 Window]%c[len: ' + strings.pad(msg.length, 5, ' ') + ']', 'color: darkgreen', 'color: grey', msg);
});
return {
onMessage: protocol.onMessage,
send(msg: any) {
protocol.send(msg);
console.log('%c[Window \u2192 Extension]%c[len: ' + strings.pad(msg.length, 5, ' ') + ']', 'color: darkgreen', 'color: grey', msg);
}
};
}
interface IExtensionCacheData {
input: ExtensionScannerInput;
result: IExtensionDescription[];
......
......@@ -5,40 +5,13 @@
'use strict';
import * as strings from 'vs/base/common/strings';
import { RPCProtocol } from 'vs/workbench/services/extensions/node/rpcProtocol';
import { AbstractThreadService } from 'vs/workbench/services/thread/node/abstractThreadService';
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IMessagePassingProtocol } from 'vs/base/parts/ipc/common/ipc';
// Enable to see detailed message communication between window and extension host
const logExtensionHostCommunication = false;
function asLoggingProtocol(protocol: IMessagePassingProtocol): IMessagePassingProtocol {
protocol.onMessage(msg => {
console.log('%c[Extension \u2192 Window]%c[len: ' + strings.pad(msg.length, 5, ' ') + ']', 'color: darkgreen', 'color: grey', msg);
});
return {
onMessage: protocol.onMessage,
send(msg: any) {
protocol.send(msg);
console.log('%c[Window \u2192 Extension]%c[len: ' + strings.pad(msg.length, 5, ' ') + ']', 'color: darkgreen', 'color: grey', msg);
}
};
}
export class MainThreadService extends AbstractThreadService implements IThreadService {
constructor(protocol: IMessagePassingProtocol, @IEnvironmentService environmentService: IEnvironmentService) {
if (logExtensionHostCommunication || environmentService.logExtensionHostCommunication) {
protocol = asLoggingProtocol(protocol);
}
constructor(protocol: IMessagePassingProtocol) {
super(new RPCProtocol(protocol), true);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册