Writing a simple service for Theia

So I want to write a simple extension which have a frontend and a backend

The documentation only provide the JSON RPC based Logger example, is there any simple example to follow to create and understand services

Also is there a way to check what all the backend service running in theia?

[original thread by Soumesh Banerjee]

Search for files matching *-protocol.ts it is usually a shared interface for JSON-RPC service. Look at filesystem-watcher-protocol.ts for example, ignore reconnection part for beginning.

@vince-fugnitto Do you know whether our extension generator provides a template for such case?

[Soumesh Banerjee]

Yes I have followed that only workspace example. https://github.com/eclipse-theia/theia/blob/master/packages/workspace/src/common/workspace-protocol.ts but something is wrong the call to methods defined in interface is not passed to the implementation and in JsonRpcProxyFactory’s get(target: T, p: PropertyKey, receiver: any): any at proxy-factory.ts:232

[Soumesh Banerjee]

So whenever frontend is trying to call the method its getting this error which if I go by the code is obvious because the code checks is method name are any of the followings

  • setClient

  • onDidOpenConnection

  • onDidCloseConnection

@sudoo Do you have a code to try somewhere?

[Soumesh Banerjee]

@anton-kosyakov Yes, here is a repo with example hello world extension with a simple service added

@anton-kosyakov I don’t believe we have a template for such a case, our only cases are a simple hello-world example which provides a command and menu contribution, and the skeleton of a widget example.

Remote APIs cannot be synchronous. Please try Promise for BackendServer.sayHello

rather than that code looks good

if you are new to JS, please learn about async/await, it allow your async code without actually using Promises

[Soumesh Banerjee]

[Soumesh Banerjee]

@anton-kosyakov Changing the BackendServer.sayHello to return Promise didn’t have any effect on the error, still getting the same error, also updated the code with the promise change in github.

() => { ctx.container.get(DefaultServer); } return nothing

It should be either () => ctx.container.get(DefaultServer); or add a return statement: () => { return ctx.container.get(DefaultServer); }

[Soumesh Banerjee]

Yes this was the problem, thanks for your help.