coder / code-server

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

Implement VS Code remote extensions #1315

Open nhooyr opened 4 years ago

nhooyr commented 4 years ago

Related https://github.com/cdr/code-server/issues/1032

LukasMasuch commented 4 years ago

In case this issue is about fixing the remote extensions to work with code-server, this related issue can be closed: #892. I would really like to see the SSH extension to work within code-server and would be happy to test it once there is any fix.

sr229 commented 4 years ago

@nhyoor if this interests you, there's a remote subfolder in the main vscode folder, wanna abuse reuse that?

frank-dspeed commented 4 years ago

The remote extension does some checks as far as i know i decompiled it some times.

There is a validation shema i think we should first automate the decompile process and check that.

nhooyr commented 4 years ago

We cannot and will not decompile the extension, that is not valid per the license terms.

Just-Insane commented 4 years ago

Is there any further plan to implement these extensions?

kirscheGIT commented 4 years ago

Is there any further plan to implement these extensions?

Would also like to know, if you have still have plans to implement this. Thanks!

code-asher commented 4 years ago

Nothing concrete at the moment.

gyzerok commented 4 years ago

I currently have a need for Remote - SSH extension and unfortunately the official one doesn't work for me (which is unlikely to be solved upstream in the near future). So I am considering implementing it myself.

At least initially I would like to have it as simple as possible. Without any fancy terminal forwarding or something like that. Just make it so that the work with the filesystem and all the language servers are running on the vm and UI is running in the vscode. Similar two what we now have with code-server in the browser, but without browser version problems (such as cmd+w for example).

Would you have some pointers as to where to start investigating from inside vscode source?

code-asher commented 4 years ago

At the moment I don't have a good idea of the full scope of what'll be required to make this work but it'll probably have to do with using and/or implementing the remote authority stuff.

There's a workspace.registerRemoteAuthorityResolver in the proposed API which might be a good starting point.

JayDoubleu commented 3 years ago

building from vscode-1.48.0 branch + adding https://github.com/cdr/code-server/pull/1779/commits/9fb33dce3d8f4854163c978ef02bdd06f1983722 , as well as adding ms-vscode-remote.remote-containers to extensionAllowedProposedApi.

This gets the remote extensions installed however it is still complaining with the error:

[ms-vscode-remote.remote-containers]: View container 'remote' requires 'enableProposedApi' turned on to be added to 'Remote'.

Tried executing via below.

code-server --enable-proposed-api ms-vscode-remote.remote-containers
code-server --enable-proposed-api=ms-vscode-remote.remote-containers

Is there any more direct way to add arguments to the vscode to execute ? I'm not sure if the enable-proposed-api switch simply does nothing or there is something else to be enabled.

code-asher commented 3 years ago

@JayDoubleu could you open a separate issue for the enable proposed API flag? It's possible we have a bug there.

I'm not confident the remote extensions will work in code-server even if we resolve that though. Unfortunately I won't be able to test since it's against the terms of service to use them in anything other than VS Code. :cry:

nhooyr commented 3 years ago

See https://github.com/cdr/code-server/pull/1779

JayDoubleu commented 3 years ago

Just tested this with ms-vscode-remote.remote-containers-0.132.0.vsix When clicking open in container it just disconnects and reloads. [server] disconnected from client {"proxies":3}

I'm assuming there is no way to get ANY remote or codespaces working with code-server ? I can see that it's already connecting to localhost as a remote

code-asher commented 3 years ago

I haven't investigated (I don't think I can since legally we can't run the extension with code-server) so I can't be sure but yeah, I think it's possible that code-server technically being a remote already might be what's causing the incompatibility.

code-asher commented 3 years ago

I'd be curious to know whether the remote extensions work in VS Code's own online offering, if anyone has given that a try. If they don't work then maybe they'll do some work to make it possible. If they do work then I think it's unlikely we'll be able to do anything about it.

JayDoubleu commented 3 years ago

The VSCode online AKA codespaces returns Cannot install 'Remote - Containers' because this extension has defined that it cannot run on the remote server when trying to install extension.

The codespace when opened already acts as a remote, and Microsoft allows for multiple of those.

The VS Code Remote - Containers extension allows you to clone a repository or open any folder mounted into (or already inside) a dev container and take advantage of VS Code's full development feature set. Visual Studio Codespaces and Codespaces in GitHub both use this same concept to quickly create customized, cloud-based development environments accessible from VS Code or the web.

It looks like it detects the devcontainer.json and automatically bootstraps into the environment as one would through remote container extension.

code-asher commented 3 years ago

Ah, we disable the remote extension check and just let every extension attempt to run which explains why code-server doesn't display that error (otherwise extensions like vscode-icons won't run even though they work).

I suppose that means the extension is not meant to work by design, at least as it currently stands, and that probably won't change if they've already coded the functionality separately in codespaces. So in the end we're basically stuck just having to re-implement these extensions.

JayDoubleu commented 3 years ago

I see, The ability to spin up multiple code-server codespaces* while using devcontainer.json as provisioner would be a very appreciated feature. In theory one could create some sort of wrapper with just docker build + bind mounts however its all about the experience.

sr229 commented 3 years ago

Investigating the remote/ folder, looks like remote implements vscode-release-reh which compiles into a whole server target. I think we can repurpose this.

JayDoubleu commented 3 years ago

Don't give me hope ... :)

sr229 commented 3 years ago

Digging more on the code I think I have a gripe on how RPC works with vscode right now

Observing this: https://github.com/microsoft/vscode/blob/master/src/vs/platform/remote/common/remoteAgentConnection.ts, I was able to deduce that:

It's not so well documented but we already have a gist on what we're dealing with.

sr229 commented 3 years ago

Additional notes: Everything in VS Code relies on a single tunnel connection. Presumably to simplify things, if I am right and all of this are done in UDP, then what we can do is basically connect and expose the same ports and implement the same functions we can expect from the remote server. That way, we have something close to Codespaces' experience.

Additional Anecdote: If that is the case, coder can also implement a official extension for VS Code itself that does the same trick at VS Remote, but using code-server.

sr229 commented 3 years ago

Again since we want the same experience as I outlined in GH-2105, there's more than just the remote server itself as well. If we are to approach this as a extension, then the extension must also replicate VS Remote's behavior which is the following:

Lestt commented 3 years ago

Any news about the possibility / feasibility to have a replica of the Remote Development extension for code-server ?

I'm using code-server on my Chromebook, as vscode itself is too laggy on it. But I need to remote develop in a Docker container. As this image is shared with my team, I don't want to alter it to add code-server inside just for my needs.

sr229 commented 3 years ago

Any news about the possibility / feasibility to have a replica of the Remote Development extension for code-server ?

I'm using code-server on my Chromebook, as vscode itself is too laggy on it. But I need to remote develop in a Docker container. As this image is shared with my team, I don't want to alter it to add code-server inside just for my needs.

Haven't been able to do this again, but refer to my findings above. I'm sure you can help out with the search :D

jsjoeio commented 3 years ago

Yes, echoing @sr229 - no updates either.

Though @bpmct may be able to suggest some workarounds since he has more experience in those kind of situations.

bpmct commented 3 years ago

Sadly I don't. This is something I would love to see as well :(

Lestt commented 3 years ago

@jsjoeio I'm keen to help on my spare time, but don't know where to start. Is there any plan to follow or something ?

jsjoeio commented 3 years ago

@Lestt that's awesome to hear!

I'm not sure exactly where to start either :( I would take a look through the comments here and see what you can learn from code-asher and sr229's comments.

If you'd like, you could do that and then share comments here as you go? We can do our best to guide/answer questions too!

sr229 commented 3 years ago

After months of analysis and some bit of RE, I'm already starting work on this. Can't assure when it'll be available since it's not something I don't see that will take off immediately + my workspace time is very limited right now due to my hardware being incapable of developing at the moment.

CC @Lestt if you're interested, let's talk on the Coder Slack, would love an additional pair of hands to help me code this :D

ArtCore7 commented 3 years ago

Would love to see this, just installed my first Code-Server and installed everything i need and it is working so perfect. Last Thing I was missing is the use of the local native VSCode with the Remote Code-Server.

Sorry for pushing this but wanted to thank you all for the great work.

bryanculver commented 3 years ago

✋ I would love to know who/how I can help. I've worked with TypeScript, Docker, and other tangentially related bits. Green behind the ears when it comes to contributing to this repo but I'm using code-server almost daily now from an iPad. Would love to leverage an almost inverse of most people's setups of remote extensions, where I have powerful machines running at home and would like to leverage them instead of massively scaling up my droplets.

jsjoeio commented 3 years ago

@bryanculver love the enthusiasm and the willingness to help ❤️

I have not looked into this myself, but maybe @code-asher can give a pointer on to where to start?

code-asher commented 3 years ago

I'm actually not sure how the remote extensions are implemented but they will need to do something like this:

  1. Connect to the remote (SSH, Docker, etc)
  2. Download code-server into the remote if necessary
  3. Start code-server in the remote if not already started
  4. Connect to code-server (not completely sure what this entails, might need to make modifications to code-server to support non-web connections)
  5. At this point things are quite fuzzy for me. Somehow the extensions provide file access (maybe through registerFileSystemProvider?) and extensions (no idea how this is done). It's possible the extensions use APIs that aren't documented.
bryanculver commented 3 years ago

The comments above are a goldmine. My old mentor's comedic relief quip "should be simple" is ringing in my head. Since they haven't published the extension with a permissive license nor the source code, a non-trivial complexity is necessary to implement this.

However seeing code-server is already being run as a server process, 🤞 this isn't that hard.

Would it be fair to say/assume that this will have to be it's own plugin (with maybe some enhanced APIs on the client side)? Trying to determine if I should fork this repo and start a new plugin project somewhere or start a new repo to build this out.

sr229 commented 3 years ago

The comments above are a goldmine. My old mentor's comedic relief quip "should be simple" is ringing in my head. Since they haven't published the extension with a permissive license nor the source code, a non-trivial complexity is necessary to implement this.

However seeing code-server is already being run as a server process, 🤞 this isn't that hard.

Would it be fair to say/assume that this will have to be it's own plugin (with maybe some enhanced APIs on the client side)? Trying to determine if I should fork this repo and start a new plugin project somewhere or start a new repo to build this out.

I was working on this under the calliope repo. I haven't gone around it for a while but I may when I have enough time. We can probably pool together and make this possible!

bryanculver commented 3 years ago

@sr229 Awesome! Please tell me how I can jump in to help. I've been trying to verify if the existing plugins leverage undocumented APIs to deliver some of the client side features at the moment.

code-asher commented 3 years ago

Would it be fair to say/assume that this will have to be it's own plugin (with maybe some enhanced APIs on the client side)?

Yup, this would need to be a separate plugin. I think a separate repo will make the most sense for that.

There may be changes we have to make to code-server itself as well; in that case you'll need to fork this repo.

sr229 commented 3 years ago

@sr229 Awesome! Please tell me how I can jump in to help. I've been trying to verify if the existing plugins leverage undocumented APIs to deliver some of the client side features at the moment.

As far as I'm aware, they use the undocumented proposed APIs for remote. Apparently they are documented but no formal documentation exists outside the vscode.proposed.d.ts file.

Lestt commented 3 years ago

@sr229 I just noticed your message... as you tagged me in the edition mode, i got no notification. I ll show up asap on the Coder Slack and see if I can be useful. Sorry again for the late reply.

vegardhw commented 3 years ago

So the idea here is to have code-server serve as the lightweight "local os", and from there ssh-remote to other systems? As in the overview image at the top here: https://code.visualstudio.com/docs/remote/remote-overview (local os -> remote os).

code-asher commented 3 years ago

Yup you'd be able to use code-server from the local OS as indicated in that diagram. But you could also use VS Code if you were so inclined (so both code-server to code-server and VS Code to code-server).

vegardhw commented 3 years ago

This sounds awesome! :) What is the expected timeline for a release...? :)

code-asher commented 2 years ago

There's no timeline unfortunately, this is just a candidate for possibly being worked on in the future.

geiseri commented 2 years ago

Given the "legal issues" surrounding this I think it would be best to just implement something "compatible" with dev containers. Currently, I run code-server in a docker, so IMHO it would be easier to just have something that will build a docker env from that dev container and run code-server from there. Then the current proxy code used for exposing web development can just forward to that instance. Thus far I have found the remote container development "clunky" at best and running code-server inside of a docker has proven a more usable experience. There is also the issue that code-server should have its own value beyond being a drop-in for MS technology that is easily replaceable. So far code-server can be instigated via ssh, it can run perfectly inside of docker. Just my 2c as someone who uses both remote VS code and code-server.

jsjoeio commented 2 years ago

^cc @bpmct @kylecarbs

jarodium commented 2 years ago

Maybe I am misintepreting the intent of the original issue, but is this issue about to use extensions on a remote location? If so, why not mount a ssh folder on the local/host machine and then run code-server to use that particular folder?

like this: " --extensions-dir="DRIVELETTER:\VSCODE\extensions"" " --user-data-dir="DRIVELETTER:\VSCODE\settings""

I have a use case in which I will need this kind of setup. I want to run code-server inside several containers, in which I want a workspace to be available, but I would like to pre-install extensions when I bootup a container.

I understand that this setup will raise a great number of issues, but for me and my team would be great, since we always use the same extensions to work and has the bonus of adding another person to the team and start him/her up without going through environment setups.

jsjoeio commented 2 years ago

I have a use case in which I will need this kind of setup. I want to run code-server inside several containers, in which I want a workspace to be available, but I would like to pre-install extensions when I bootup a container.

This basically sounds like your own version of Coder! We have many teams who do this. The most common way I've seen is installing the extension as part of the Dockerfile so that it's available when your teammates create a workspace (i.e. access code-server):

https://coder.com/docs/coder/latest/workspaces/vs-code-extensions#adding-extensions-to-custom-images

spwoodcock commented 2 years ago

Though it would be nice to have the official remote extensions working, I can't see it happening anytime soon.

I have been using code-server for a few years now deployed inside a container (Docker & Kubernetes) & recently got remote debugging working inside Docker containers for a FastAPI app. (sidenote: Docker in Docker is messy. I currently bind mount docker.sock for local development, but I'm sure using a remote TCP host via DOCKER_HOST would work too.)

For anyone looking at remote debugging, this approach should work for any language that supports a remote debug package (e.g. Python, Node...). I currently use the debugpy package in Python.

In the root of your repo, add launch.json and tasks.json into the .vscode directory.

launch.json:

{
  "configurations": [
    {
      "name": "Python - Remote Attach",
      "type": "python",
      "preLaunchTask": "docker-compose: cycle",
      "request": "attach",
      "host": "NAME_OF_YOUR_DOCKER_CONTAINER",
      "port": 5678,
      "pathMappings": [
        {
          "localRoot": "${workspaceFolder}",
          "remoteRoot": "/opt/app"
        }
      ],
      "justMyCode": false,
    }
  ]
}

tasks.json (note: you could use a dockerCompose type task, but this doesn't support V2):

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "docker-compose: cycle",
      "type": "shell",
      "command": "docker compose down && docker compose up -d api --no-build",
    }
  ],
}

Relevant part of Dockerfile to make this work:

...
...
ENTRYPOINT ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
USER appuser

FROM runtime as dev
RUN pip install debugpy
ENTRYPOINT ["python", "-m", "debugpy", "--wait-for-client", "--listen", \
            "0.0.0.0:5678", "-m", "uvicorn", "main:app", "--host", \
            "0.0.0.0", "--port", "8000"]
CMD ["--reload", "--log-level", "error", "--no-access-log"]

FROM runtime as prod
CMD ["--workers", "1", "--log-level", "error", "--no-access-log"]
archef2000 commented 10 months ago

Hello sorry if i ask, but is there currently a way to use the projects of code-server with the desktop app?