Enhancing plugin APIs

Hi, I would like to implement a service in an Extension and expose that service through the plugin API to other plugins. Please guide me regarding this.

[original thread by rs]

[rs]

@tsmaeder , is this related post? - https://github.com/eclipse/che/wiki/Writing-Theia-plugin-API

[Oleksandr Andriienko]

Commonly Plugin api has namespace theia or vscode. In the che-theia we extends plugin api by namespace che. Plugin api has d.ts file with definition https://github.com/eclipse-theia/theia/blob/master/packages/plugin/src/theia.d.ts. You can apply proposed plugin api. For Eclipse CHE we have https://github.com/eclipse/che-theia/blob/master/extensions/eclipse-che-theia-plugin/src/che-proposed.d.ts and implementation located in the https://github.com/eclipse/che-theia/tree/master/extensions/eclipse-che-theia-plugin-ext. Also I see even in the theia project we have extended api part: https://github.com/eclipse-theia/theia/blob/master/packages/plugin/src/theia-proposed.d.ts - maybe it will be easier to learn. So you can write own api definition and in the implementation you can use and expose your own service.

[rs]

Thank you, @andriienko-oleksandr. I shall have a look at those links.

[rs]

Hi @andriienko-oleksandr , Thank you, i looked into the file that you suggested : https://github.com/eclipse-theia/theia/blob/master/packages/plugin/src/theia-proposed.d.ts.
Hope I can declare the new plugin interfaces in and it’s implementation in a separate extension? and i should ensure that the namespace is same as that of the plugin api?
Could you please guide me if the above approach works?

[rs]

Hi @andriienko-oleksandr & all, please refer to the code https://github.com/cherxp/my-theia.

A sample plugin is under the folder my-plugins/theia-hello-world-plugin and the plugin binary is under my-theia/plugins.

I have added this in https://github.com/cherxp/my-theia/blob/master/packages/plugin/src/theia.d.ts:

    export namespace myServer {

        export function sayHello(): void;

    }

also, please refer to the implementation that shows ‚ÄėHello‚Äô information message.

Is it possible to move the above declaration to another extension and implement it in that extension, as the above myServer implementation would have methods unique to my implementation and do not want to add all those into theia.d.ts.
I would like to have those in my extension, such as my-theia/my-extension/my-plugin-interfaces.d.ts and implement it as part of my extension.

Please help.

[Oleksandr Andriienko]

We have a little doc https://github.com/eclipse-theia/theia/blob/master/packages/plugin-ext/doc/how-to-add-new-plugin-namespace.md

[rs]

Thank you, @andriienko-oleksandr.

[rs]

Hi @andriienko-oleksandr & others, I have added the new api implementation here : https://github.com/cherxp/my-theia

1st step:
Added theia.myServer api to theia/plugin and theia/plugin-ext
Used that api in plugin my-plugins/newplugin. Works fine !

2nd step:
Added new api definition myServerNew in: packages/test-service
implementation : packages/test-service-ext
Tried to use that api in the plugin my-plugins/newplugin. This doesnt seem to work. :frowning:

Could you please review and help. Thanks in advance.

1 Like

[rs]

I get the following error in console when i perform yarn start:

[rs]

root ERROR [hosted-plugin: 12975] { Error: Cannot find module ‚Äė@theia/plugin-ext/src/common/rpc-protocol‚Äô
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15) at Function.Module._load (internal/modules/cjs/loader.js:508:25) at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object. (/home/xpress1/Xpress/theia/packages/test-service-ext/lib/node/testservice-api-node-provider.js:19:22)
at Module._compile (internal/modules/cjs/loader.js:701:30) at Object.Module._extensions…js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3) code: ‚ÄėMODULE_NOT_FOUND‚Äô }
root INFO [hosted-plugin: 12975]
PLUGIN_HOST(12975): PluginManagerExtImpl/init() PLUGIN_HOST(12975): initializing(newplugin@0.0.1 with /home/xpress1/Xpress/theia/packages/plugin-ext/lib/hosted/node/scanners/backend-init-theia.js)
root INFO [hosted-plugin: 12975] PLUGIN_HOST(12975): PluginManagerExtImpl/loadPlugin(/tmp/theia-unpacked/newplugin.theia/lib/newplugin-backend.js)
root ERROR [hosted-plugin: 12975] { Error: Cannot find module ‚Äė@theia/testservice‚Äô at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
at Function.Module._load (internal/modules/cjs/loader.js:508:25)
at Function.module._load (/home/xpress1/Xpress/theia/packages/plugin-ext/lib/hosted/node/scanners/backend-init-theia.js:42:33)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18) at Object. (/tmp/theia-unpacked/newplugin.theia/lib/newplugin-backend.js:7:15)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12) code: ‚ÄėMODULE_NOT_FOUND‚Äô }
root INFO [hosted-plugin: 12975] plugin theia.newplugin, start method is undefined so the module is the extension’s exports

[rs]

please note : Error: Cannot find module ‚Äė@theia/testservice‚Äô at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)

[rs]

the issue mentioned above has been resolved. but, when i try to call the new api method from plugin, myServerNew.SayHello(), an error thrown that says myServerNew is undefined. The plugin component is available in the folder my-plugins/newplugin