Che: URL API to open files

Created on 3 Aug 2020  路  17Comments  路  Source: eclipse/che

My question is short: how to specify dynamically via URL which file should be opened?
Or maybe you suggest another way how it can be implemented?

aredevfilv2 arefactortheia kinquestion severitP2

Most helpful comment

@vparfonov, @benoitf, @azatsarynnyy Thank you all. I'll start with a simple variant of a plugin with query parameter, then will consider an extension

All 17 comments

@gorshkov-leonid Please take a look here: https://github.com/eclipse/che-theia/tree/master/plugins/workspace-plugin and more details in code here: https://github.com/eclipse/che-theia/blob/master/plugins/workspace-plugin/src/theia-commands.ts#L28
Probably this is that you are looking for

@vparfonov Thank you, This is almost what I need, except that path is fully dynamic and should be passed via url. In this example, path is hardcoded in the configuration the same as in welcom-page plugin, which uses workspace.openTextDocument/window.showTextDocument, but I can't understand how to get browser's URL?

Sorry, @gorshkov-leonid look like I give you wrong direction :( at the moment we not support such API. Probably it will be supported by devfile https://github.com/eclipse/che/issues/12925, but again not via URL. As solution, you can create own plugin for this.

@vparfonov Is it might be theia plugin? I think that your suggestion will work as part of plugin. But I feel a piece of puzzle is necessary as I can open files, but I cannot get URL parameter to decide which file to open.

And I feel that It is part of theia, so I asked in theia about URL: https://github.com/eclipse-theia/theia/discussions/8292.

But I am also worried about some Che specific things as workspace loader for example.

@ericwill @azatsarynnyy What do you think about that? Maybe you can help in this question?

Hello @gorshkov-leonid
Theia/VS Code Plugin doesn't have access to window JS object. But you can access it from Theia Extension.

@azatsarynnyy Thank you. Do you know any examples? It could really help me

Theia plug-ins do not have access to window object but can use API to grab query parameters of the URL

https://github.com/eclipse/che-theia/blob/master/plugins/workspace-plugin/src/factory-initializer.ts#L33

@azatsarynnyy Thank you. Do you know any examples? It could really help me

The example of simple extension is here.
Just call window.document.URL

@vparfonov, @benoitf, @azatsarynnyy Thank you all. I'll start with a simple variant of a plugin with query parameter, then will consider an extension

@vparfonov, @benoitf, @azatsarynnyy Unfortunately, way with query parameters Is not working because query parameters is not passed to iframe.

  • window.location is http://che-che.192.168.164.130.nip.io/dashboard/?f=aaa&l=12&c=14#/ide/admin/vdoc-51ae3
  • I can see that parameters is not appeared in iframe and as result getQueryParameter(...) returns undefined
<iframe class="ide-page-frame ng-scope" id="ide-application-iframe" ng-src="/workspace-loader/admin/vdoc-51ae3?uid=359755" src="/workspace-loader/admin/vdoc-51ae3?uid=359755"></iframe>

but if I change it in Chrome Devtool then it gets worked

@akurinnoy @olexii4 Can you give advice here?

I don't think that this feature is possible to implement without extending the devfile format. Maybe it could be done in devfile 2.0. CC @davidfestal @l0rd

I appreciate your help.

I as understand the main stopper is iframe, but I think as a temporary solution I can write an extension which contributes command that gets window.parent.location. But I can't understand how to build and especially deploy an extension.

At first, I decided to build che-theia with my extension. But the build fails with an error like lerna ERR! [compile] src/node/che-api-service.ts(37,56): error TS2554: Expected 0 arguments, but got 1. even without my extension, just che-theia 7.15.0. As I guess it is because of ~,^ in dependencies' versions in theia, I am not sure.

But maybe It is overkill and some simpler way exists. Could you point how I can add extension without a rebuild. Ideally, the best way for me would be to extend the existing docker image where I can add an extension into.

Could you point how I can add extension without a rebuild

One of the differences between Extension and Plugin is an Extension can be added into assembly in compile-time only. A Plugin - in run-time. So, adding an Extension requires to rebuild Che Theia.

@azatsarynnyy Thank you. I managed to build che-theia. But as I internally worried window.parent would be blocked and I have It:

ERROR Error: Blocked a frame with origin ... from accessing a cross-origin frame.

The only way is left - to pass arguments to iframe. @vparfonov, @azatsarynnyy, @benoitf, @skabashnyuk _Could you give me a hint where it is?_

PS. For history:
As I wrote above I could not build 7.15.0 - ts is not compiled.
Under Ubuntu 20.04, I had a hanged build for 7.15.x and 7.16.x, but it is ok for master. I can't understand and I wonder why it is. If you know, tell me, please. It is somehow related to a plugins' download and happens after arbitrary plugin. Last logs looked like:

$ theia download:plugins
--- downloading plugins ---
+ vscode-builtin-clojure: downloaded successfully
...
+ vscode-git: downloaded successfully
<and nothing here>

But I managed to build It under Ubuntu WSL 2

I reconsidered what I want. The dashboard is not necessary for me. Url /workspace-loader/lego/abgh-7pdch?f=/projects/22.txt&l=60&c=420&uid=516925 is working. But I do not know what uid impacts on. All uid=42 and 24 and 516925 work properly.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vanzhiganov picture vanzhiganov  路  3Comments

sleshchenko picture sleshchenko  路  3Comments

InterestedInTechAndCake picture InterestedInTechAndCake  路  3Comments

SkorikSergey picture SkorikSergey  路  3Comments

redeagle84 picture redeagle84  路  3Comments