Call plugin api method from extension

I would like to add a new webview tab in the editor area. Can anyone suggest a way
to create webview and add it to editor view from an extension ? Should i use the plugin api theia.window.createWebViewPanel() ? A sample code would be very helpful.

For example, if anyone can help to call a plugin api method like theia.window.showInformationMessage(‘hello’); from an extension, i think i should be able call createWebViewPanel. Thanks in advance.

[original thread by rs]

Have you looked at this docs: https://code.visualstudio.com/api/extension-guides/webview

yes, you should call createWebViewPanel and then pass position in the editor area as one of arguments

this function returns an instance of panel

you can check on it whether instance is visible or not, also you can listen for state changes

if you don’t provide webview serializer on the page reload webview will be gone, if you provide when you will recover panel in it

shortly your extension is responsible for creating webviews and you always have references to all of them, on which you can check whether user closed them or not, which titles they have

[rs]

Thank you, @anton-kosyakov

[rs]

Hi @anton-kosyakov and all , Thank you.

I noticed that:

  1. theia plugin can add webview using : theia.window.createWebviewPanel

  2. theia extension adds webview using vscode interface shown in the example that you provided: vscode.window.createWebviewPanel

The parameters for the above two methods are different. Using vscode.window.createWebviewPanel(), I could not figure out a way to add webviews to Right Top and Bottom portions of theia.

In an extension, can I use theia.window instead of vscode.window apis?

I don’t think VS Code API allow it.

[rs]

I would like to add webview panels to Right Top and Bottom portions of theia.

[rs]

In an extension, can I use theia.window instead of vscode.window apis? Another question is are there any examples that demonstrates theia.window in an extension?

cc @artem-z @florentbenoit

[rs]

i’m trying using a custom-theia editor based on theia v0.8.0.

Hello @che-theia-new
you can use theia.window instead of vscode.window
A lot of examples can be found here https://github.com/eclipse/che-theia/tree/master/plugins
Just search for theia.window in the code. E.g. https://github.com/eclipse/che-theia/blob/e74f45baf39e951f7ffa4b2f3cdc442b06e70ee1/plugins/welcome-plugin/src/welcome-plugin.ts#L81

[rs]

Thank you, @artem-z . But the above links demonstrate how a plugin can use theia.window interface, i believe. I would like to use theia.window from an extension.

I see. I haven’t seen such examples of using it from Theia extensions.

@che-theia-new I thought you are developing VS Code extension and want to switch to Theia plugin to use some custom apis

if you are developing Theia extensions then you don’t need to deal with Webview, you can build a widget