coder / code-server

VS Code in the browser
https://coder.com
MIT License
66.47k stars 5.45k forks source link

Keep instance running after browser closing #6836

Open albertopasqualetto opened 3 weeks ago

albertopasqualetto commented 3 weeks ago

What is your suggestion?

Keep the VSCode instance up and don't close it even if browser is closed.

Why do you want this feature?

In order to setup Live Share and being able to connect to it always.

This would help in a lot of code-server use cases.

Are there any workarounds to get this functionality today?

No, AFAIK.

Are you interested in submitting a PR for this?

Don't know from where to start.

code-asher commented 3 weeks ago

Thank you for the suggestion! I agree this would be ideal.

But, I do not think this is something we would want to do in code-server, my guess is it would be a pretty significant architectural change and since code-server just wraps VS Code, we would have to maintain the change with patch files which would be tough, so that change should probably be made directly to VS Code remote/web up at https://github.com/microsoft/vscode/.

albertopasqualetto commented 3 weeks ago

@code-asher thanks, do you have any idea where to start from?

code-asher commented 2 weeks ago

I do not have any concrete code to point out, but in general I think the problem is that the extension host is killed (and consequently all extensions are also killed) when the browser connection closes. If we can persist the extension host and its extensions, I believe this issue will be solved.

So first step is to prevent the extension host from being killed, which would be easy enough, mostly a matter of deleting that code, wherever it is.

Then, instead of spawning an extension host when getting a connection, we hook it up to the existing extension host, also seems easy enough.

From there though it gets fuzzy for me. Can we just reuse the initialization code of the extension host again, do the handshake, send whatever other data the extension host normally sends on a first connect? It seems likely to me we will need to send additional data to restore various states of the extension host and its extensions, and various components may have to be reworked to accept existing state rather than always initializing from zero.

Another open question in my mind is whether extensions themselves will have to be modified to support persistence. Maybe we will need new extension API for extensions to tell when a client closes or reconnects.

I speak as mostly an outsider though, the folks that wrote all this code up at https://github.com/microsoft/vscode might have much better ideas.