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

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.

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?

Is there any extension in Visual Studio Code , which is similar to Tramp Mode in Emacs?

TRAMP (Transparent Remote Access, Multiple Protocols) is a package for editing remote files, similar to AngeFtp or efs. Whereas the others use FTP to connect to the remote host and to transfer the files, TRAMP uses a remote shell connection (rlogin, telnet, ssh). It can transfer the files using rcp or a similar program, or it can encode the file contents (using uuencode or base64) and transfer them right through the shell connection.
It seems like as of now there is at least one similar package to Tramp mode for VSCode. I couldn't directly find in the documentation how you would open a remote shell inside VSCode, but it seems like it would have to be possible given the rest of the plugin.
https://code.visualstudio.com/docs/remote/ssh
https://code.visualstudio.com/blogs/2019/10/03/remote-ssh-tips-and-tricks
I have a terminal menu in VSCode that I can open up and directly ssh to stuff, so that seems to cover both sides of the "Tramp" mode usage
You can use FUSE for a somewhat similar effect. It's not editor specific, but mounts remote file systems via SSH, FTP and whatnot directly to your local file system so you can use it with any Editor.
You didn't mention on what operating system you, but here's the link to the version for macOS: https://osxfuse.github.io

Open remote Server Files in local emacs

I used to be a comfortable emacs user and for close to 10 years I completely got away from using emacs (I know its a shame) but I have a wage memory of setting something in .emacs to open remote files in a server via local emacs.
Just to make the scenario clear:
Login to a remote server (ssh) -> emacs somefileInRemoreServer.file &
File get open using the local version of emacs.
My questions are:
Is this possible?
how can I accomplish this?
I have both mac and ubuntu on mac I use Aquamacs. It would be a great help if I can get instructions on both versions.
I'm not sure whether you want to ssh prior to using emacs or ssh using (in) emacs.
If you want to let emacs do all the work check out the links added by phils, TRAMP mode is the way to go for remote editing IN emacs.
If you want to use ssh to mount a remote filesystem (resulting in "local" editing with emacs) you should check out sshfs (man, wiki).
I think it comes with pretty much any of the current distros (or can be installed easily otherwise). It is a fuse extension which allows to mount a remote directory to a local one without any further requirements on the remote side than ssh.
I do like TRAMP for editing one or two files but using sshfs is great for working on a whole project directory which is placed remotely and which you do not want to sync using another method.

Using a single emacs instance from multiple (virtual) machines

I love emacsclient. It allows me to use a single Emacs frame for all my editing, also when programs want to open an editor (i.e. export EDITOR=emacsclient).
I'd like to have it work like this with virtual machines, too. I can use tramp to edit remote files with Emacs in my single-frame setup, and it works very well, but it's not enough. When I invoke git commit or sudoedit, I'll have to use the crappy terminal-based editor that happens to be installed on the remote machine.
So, is there anything like emacsclient that works across multiple machines?
Speculation: If you can ssh from the VM back to your local machine then the VM could probably invoke emacsclient on your local machine, with the appropriate tramp prefix to the remote file? Set up a script for that, and configure your remote EDITOR environment variable to match.
It could be you can do more with TRAMP than you think. First off, you may have noticed that /sudo: doesn't work for remote boxes, but TRAMP allows you to proxy to a remote box and then use any supported protocol, so in effect you can use /sudo: on a remote box. See tramp-default-proxies-alist.
You mentioned invoking git commit on a remote box. Have you considered using one of the Emacs git interfaces such as magit? They will work through TRAMP as well.