Commands that stop/restart theia server

“yarn theia start” starts theia. Are there any commands that restarts /shuts down the server?

[original thread by Nicholas Han]

Hi @nicholasl00 . Not that I know-of. However it should be possible to implement this in a Theia extension. Before we had plugin (VS Code extensions) support, we had a Theia extension manager that permitted changing the extensions used in a Theia application. Whenever the list extensions changed, the app was recompiled on-the-fly and the backend restarted.

stop and start the process :slight_smile:

[Nicholas Han]

could you further elaborate on this ? I know ctrl-c and typing “yarn theia start” does this

I am not sure if changing root directory can be done on runtime, I intend to change root directory by restarting the server

I’m using a script os.system(“yarn theia start -/example-workspace-A”) to start a Theia server. I want to change the root directory to example-workspace-B. Therefore I have to stop the existing server before os.system(“yarn theia start -/example-workspace-B”)

I am open to any suggestions

I am not sure if changing root directory can be done on runtime

A root directory is a per user, if a user opened some directory next time the same directory will be opened, regardless what is the default directory of the server (one which you pass to cli).

See https://github.com/eclipse-theia/theia/blob/d54c2f0d7307ef504e9c46e490f4ebd0ac06ef51/packages/workspace/src/browser/workspace-service.ts#L90-L111 and https://github.com/eclipse-theia/theia/blob/d54c2f0d7307ef504e9c46e490f4ebd0ac06ef51/packages/workspace/src/node/default-workspace-server.ts#L75-L84

One can change use workspace programmatically with WorkspaceService.open: https://github.com/eclipse-theia/theia/blob/d54c2f0d7307ef504e9c46e490f4ebd0ac06ef51/packages/workspace/src/browser/workspace-service.ts#L294-L299

Also if a user opens a new page and adjust a fragment to point to another workspace path, then it should work.

[Nicholas Han]

thanks, i’ll have a look into it

[Nicholas Han]

@anton-kosyakov could you suggest how to implement this?

On my Django web app, the user will have to choose a workspace folder. Theia would then load up with the selected folder. I’m thinking of passing the file uri to WorkspaceService.open but unsure how to implement it

What do you mean by load up? Will be a user redirected to a new window? Or a user already has a window and you need to open another workspace in it?

[Nicholas Han]

The 2nd one, user already has a window and you need to open another workspace in it

So you can only do a remote call to Theia backend, no way to talk to this window?

If so, backend will need to notify a proper frontend window and then it should use WorkspaceService.open.

How do you identify which window client should it be is up to you.

[Nicholas Han]

I appreciate your response, but I’m not entirely sure what you mean by this “remote call to Theia backend, no way to talk to this window?”

Do you mean that my web app frontend has to communicate and send WorkspaceServcie.open to Theia’s backend?

Theia is embedded via iframes in my django web app.

If it is embedded then you should be able to establish communication between your web app and iframe via https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

[Nicholas Han]

I hate to ask again, but i’m assuming that using postMessage alone won’t make this work.

The web app communicates with the iframe via postMessage. The iframe has to pass this to theia’s backend. So i’m guessing a theia’s backend extension is need. Am i on the right path ?

it is fine, we are here for it.