I was following along https://www.theia-ide.org/doc/Json_Rpc.html to define my own JSON-RPC endpoint but hit an issue, which I believe is due to my transpiling my TS files to ES6 instead of ES5 – I notice that Theia’s own tsconfig targets es5. After targeting es5, I am able to get things working.
The issue is with the way Theia is iterating through the methods to define proxies for them. See https://github.com/theia-ide/theia/blob/master/packages/core/src/common/messaging/proxy-factory.ts#L134
listen(connection: MessageConnection) {
if (this.target) {
for (const prop in this.target) {
if (typeof this.target[prop] === 'function') {
connection.onRequest(prop, (...args) => this.onRequest(prop, ...args));
connection.onNotification(prop, (...args) => this.onNotification(prop, ...args));
}
}
}
connection.onDispose(() => this.waitForConnection());
connection.listen();
this.connectionPromiseResolve(connection);
}
When transpiled to ES5, the for…in
will get you all the methods of the target.
When transpiled to ES6, the for…in
will not get you any of the methods of the target, causing the Unhandled method ${requestMessage.method} to appear when you call it from the front-end.
You can verify this yourself at this simple JSFiddle (be sure to open Developer Tools
) - https://jsfiddle.net/m62cwejv/.
I’m not a ES5 vs ES6 expert, but I believe that this is actually how ES6 enumerability works, based on http://2ality.com/2015/02/es6-classes-final.html#attributes-of-properties
Question: Is this a bug/limitation with Theia? Or does Theia specifically only support ES5? Note I don’t know of all the places where Theia might be doing ES5 specific things but this is at least one that I found.
[original thread by Nick Chen]