is there a way to work offline with vscode remote ssh to save cost? - visual-studio-code

I am using vscode ssh remote plugin https://code.visualstudio.com/docs/remote/ssh
to connect to gcp sandbox vm. gcp sandbox vm has an hourly cost if kept turned on.
most of the time I am reading or changing the code and I am not running any command in the VM's terminal. So, if I had the code offline, I would not need to keep the VM running and pay for each second of it.
Is there a way I can do this?

When using VSCode over SSH, you are running a VSCode server on the remote host which is used to read the files.
If you want to be able to open files locally, you will need to download them.
If you already have the files opened, you can disconnect from the VM and keep looking at them.
Another option to consider is mounting whatever file store you're using locally as a FUSE file system. Here is an example for git: https://github.com/presslabs/gitfs

Related

How does the local vscode client manipulate files in the remote machine?

With the remote-ssh extension, we can use vscode's remote development feature now, which means we can access the files in a remote machine from local vscode. And I found except the remote-ssh extension, there is a vscode-server working on remote machine to communicate with local vscode.
Looks like it's the bridge between local vscode and the file system in remote machine, which say vscode access remote files through the .vscode-server. But when I read vscode's source code, I still didn't find which protocol do they used to communicate, looks like it's not http, maybe it's ssh, but I still didn't get the details. Does any one know the details between local and remote on access remote file system? Such as how does the client initiate a file read, and how does the remote return the file content to the client, which protocol they use. And how remote executes command from local, such as the git commands in source control.
We can find some source code of the vscode-server in vscode:
https://github.com/microsoft/vscode/blob/main/src/server-main.js
https://github.com/microsoft/vscode/tree/main/src/vs/server/node
not a complete answer but the extension that provides the remote connection is Microsoft/Github's "remote-ssh" (https://code.visualstudio.com/docs/remote/ssh). VS Code uses the ssh channel for effectively a peer-to-peer proprietary exchange between the local and remote machines after bootstrapping the process by using the ssh connection to issue commands to install their VS Code Server and its dependencies.
VS Code extensions generally have a link in their info to a Github repo containing the source but in the case of remote-ssh the repo is for feedback only & the code does not appear to be open source.
(https://github.com/Microsoft/vscode-remote-release)
Note the remote-ssh extension is using remote code execution primarily to "take advantage of VS Code's full feature set" (presumably including remote build and debugging) rather than simple file access. That extension does provide remote file access, but there are far simpler extensions such as ftp-simple which provide only that.

Is it possible for VSCode to execute and debug via SSH, with local source code?

I am struggling to execute my codes on my Linux VM, with all files inside my local Windows machine.
So, I have my source code at for example: D:\myCodes\ and
the files are shared to my Linux VM at /media/sf_codes
I linked all my relevant files at /media/sf_codes/src/ to /opt/myCodes/src/. All other files are irrelevant, and only contains about diagrams, SQL files, etc etc that has nothing to do with the Linux VM. So I only link the src folder into the project folder at /opt/myCodes.
I have tried to use Remote-SSH extension, but it just to won't load all files. It is either load local files, and disables all SSH shell, or it opens a folder at the Linux VM. Which is not necessary because the files are local. And I need to su it under different user to be able to write the files, which complicate things a lot. I was able to do it using Docker or WSL, but their use of HyperV complicate things, and broke many things. So I am back with VirtualBox.
I don't need fancy stuffs like sync or whatever magic they provide, just open SSH shell in terminal, preferably multiple ssh terminals to multiple Linux VMs, and work the files in local folder, and that's it.
I think if they can sync the files, what I need is a basic thing to do, and somehow I missed that. How can I do that in VS Code?

Open remote folder in local VSCode like "code ."in WSL2

Is it possible to use $ code . in remote server ssh session just like I do in WSL when I want to open current working directory in remote host in local VSCode?
ADDENDUM:
In local WSL, I can issue $ code . and that would open the current directory in VSCode which is installed on Windows 10.
I am trying to get the same behavior in another remote Linux which I have connected to remotely through ssh. So when I am on that remote machine and issue $ code . it would open that directory in VSCode installed on local window.
I don't imagine this would be simple to do but I certainly share your desire to want to be able to do it.
Problem
Here's an explanation of why it doesn't work, and a hint at why it's probably quite a difficult thing to setup:
The way code . works from WSL (or PowerShell) is by launching VS Code in the given directory (passed as the first argument as the dot).
When you run code from WSL it uses wslpath to convert the path to the Windows accessible one, and the WSL magic executes code.exe (which is, after all, a Windows binary and not a Linux one) in Windows with the WSL path (\\wsl$...);
Theory
In order for this to work you need to achieve three things:
Work out which remote you're connected to, and be able to pass that information to vscode
Execute code.exe on your local machine, but from your remote terminal
Ideas
A couple of ideas you could play with if you wanted to try and implement it:
A script on your remote could output a vscode:// URL for you to click (or find a way to get your client to auto-load it).
You might be able to use a forwarded port in your SSH session to contact something on your PC (perhaps custom made, or maybe with Windows RDP or a telnet/ssh server perhaps?)
Perhaps mount a local directory as part of your SSH connection (I don't know all the edges of SSH but it does a lot of cool stuff! SCP might help?) and be able to execute/trigger things?
Just some musings! It's not something I need enough to put any effort into it, but I came across your question looking for something else and found it interesting. Hope that's helpful to anybody, any thoughts/feedback is welcome!

Can I add a remote Python interpreter (via SSH) to a local VSCode environment (i.e. a hybrid local/remote SSH setup)?

I have VSCode set up with the "Remote - SSH" extension, and I am able to run a local VSCode window as the face of a full remote environment. Really cool.
However, I would also like to be able to set up a local VSCode environment which loads files from my local filesystem but runs them on a remote Python interpreter (via an SSH connection).
I am hoping I can run all the regular interactive Python REPL stuff using the remote kernel (e.g. show variables, etc). It seems like I should be able to somehow add a remote kernel and then select it via "Python: Select Interpreter", but I can't figure out how.
In the past I was able to configure such a setup in JupyterLab using the "remote_ikernel" package.
Is this possible in VSCode? I've found tons of documentation on the full remote setup, but haven't located information on this hybrid kind of set up.
I found a related bug report which discusses mixing local and remote filesystems (not interpreters).
I suspect that the same difficulties it describes for filesystems may be similar reasons for why local files can not be easily fed into remote interpreters.
The full thread is here for reference:
https://github.com/microsoft/vscode-remote-release/issues/706
The specific quote:
Having a mixed workspace would require that a workspace extension can be active both locally and remotely. Currently an extension can only be active once, either locally or remotely. So this is currently not possible and we have no plans to support this.
The recommendation is to have separate windows open for the local and remote workspace.
So it sound like this is a feature that is not currently supported.

Remote Java Development using IntelliJ or Eclipse

I have some code that only runs on a remote Ubuntu box with a gateway in between. Every time I have make some changes I have to make the change in my local Mac and push it to git and rebuild it on the box to see if it is working. Was wondering if there is a way to configure IntelliJ or Eclipse to modify code directly on the remote box and have it running there with debug etc. so that I minimize on the roundtrip?
The solution may be to mount the remote filesystem in your local machine.
Then run the IDE off the remote file mount in the local system.
That way, the IDE will access all the files as if it is local.
The IDE can connect to the process running in remote machine.
Also the IDE can remote debug the JVM easily.
Here is the how to of mounting the remote file system locally
https://www.digitalocean.com/community/tutorials/how-to-use-sshfs-to-mount-remote-file-systems-over-ssh