Extensions on the remote machine are not recognized by Remote-SSH extension - visual-studio-code

I have a Linux machine with VSCode on it, with extensions installed at /home/myuser/.vscode/extensions/. Everything runs great. However, now I would like to connect to that machine remotely with "Remote - SSH" from a VSCode instance that runs on another computer. The connection was successful, but the extensions are all grayed-out and have "Install in SSH:..." buttons.
How can I get VSCode to find the extensions already installed on the remote (Linux) machine?
The extensions were installed using VSCode on the remote machine.
I looked through the settings for something that might have to do with it, but couldn't find. I didn't install anything remotely yet ("Install in SSH:...") because I was afraid that it might clash with the existing installation.

Related

WSL Distros not visible to VSCode or IntelliJ IDEs

For a few weeks now I have had this very strange issue and have been unable to resolve it:
I usually code on WSL2, and it used to work fine on this machine and user. But now, whenever I try to open the Remote Explorer in Visual Studio Code or try to open a "New Project from Existing Files" in an IntelliJ IDE, no WSL Distros show up.
They are still there - wsl -l -v lists them and I can open them in the terminal. Everything inside of them works (aside from opening VSCode).
In Windows Explorer, their filesystems do show up. But in Visual Studio Code the list of Distros is empty and I get an error message stating "Cannot read properties of undefined (reading 'name')" when I open the Remote Explorer. In IntelliJ IDEs, only my local drives appear where there used to be additional entries for WSL.
When I navigate to a directory in WSL in the terminal and then execute code ., it opens a VSCode window, but then I get the notification "No WSL distros found".
Interestingly, previously opened projects in IntelliJ IDEs can still be opened (but I am getting Line-Ending issues).
I have tried reinstalling the WSL extension in VSCode, restarting the LXSSManager-Service, doing a network reset with netsh winsock reset, netsh int ip reset, ipconfig /release, ipconfig /renew, ipconfig /flushdns - and I have tried reinstalling VSCode entirely... to no avail. I have also looked at the registry entries for the WSL Distros under Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\, and they look fine to me.
I have also uninstalled my non-primary distros and reinstalled them - same issue across all installed distros, old or freshly installed.
I am sadly unable to specify how to reproduce the issue as everything used to work in this setup and nothing was deliberately changed.
My Windows version is Windows 11 Version 22H2 (OS Build 22621.963).

vscode inside WSL vs Windows

In tutorial requirement is install vscode in windows and install Remote Development extension pack. Why not just install in wsl?
I've install vscode to wsl. When I run code in wsl I get message:
To use Visual Studio Code with the Windows Subsystem for Linux, please install Visual Studio Code in Windows and uninstall the Linux version in WSL. You can then use the `code` command in a WSL terminal just as you would in a normal command prompt.
Do you want to continue anyway? [y/N]
To no longer see this prompt, start Visual Studio Code with the environment variable DONT_PROMPT_WSL_INSTALL defined.
Which cons of run vscode in wsl as opposed to run it in Windows?
The WSL extension splits VS Code into a “client-server” architecture, with the client (the user interface) running on your Windows machine and the server (your code, Git, plugins, etc) running "remotely" in your WSL distribution.
When VS Code is started in WSL, no shell startup scripts are run.
The extension runs commands and other extensions directly in WSL so you can edit files located in WSL or the mounted Windows filesystem (for example /mnt/c) without worrying about pathing issues, binary compatibility, or other cross-OS challenges.
(source: MSFT DOCUMENTATION)
This is the architectural choice of Windows and - personally speaking - I feel like it's a choice to avoid conflicts and redundancies.
When running the WSL extension, selecting the 'Extensions' tab will display a list of extensions split between your local machine and your WSL distribution.
Installing a local extension, like a theme, only needs to be installed once.
Some extensions, like the Python extension or anything that handles things like linting or debugging, must be installed separately on each WSL distribution. VS Code will display a warning icon ⚠, along with a green "Install in WSL" button, if you have an extension locally installed that is not installed on your WSL distribution.

Why are VSCode extensions not working in SSH

I am using the Remote-SSH extension. When I SSH to a local VM that has Linux, or far away to my uni's pc lab, all my VSCode local extensions don't work, it doesn't show under the extensions pane -> local installed. So doing the keyboard shortcut for one says "command 'extension.advancedNewFile' not found". Why is this and how do I fix this?
The first diagram in https://code.visualstudio.com/docs/remote/ssh shows it clearly that only theme/UI extensions remain applicable when VSCode is under remote development mode,
If you want features of certain extensions, you have to install them on the remote machine (under EXTENSIONS | SSH: MACHINE_NAME - INSTALLED).

VSCode remote ssh -- how to automatically install extensions

How do I install VSCode extensions in an SSH connection without doing it through the VSCode UI? I have an environment that spins up a new VM for git branches, and it's really annoying to have to go manually install every extension for each new VM.
I've tried adding them to a devcontainer.json file, which is ignored (it only works on containers, not ssh, even in the newest release that's had some support for the file via ssh connections).
I could add a bunch of packages to vscode's settings, but I want to avoid that because what I install is different based on whether I'm looking at a rust service, node, etc and it's pretty pointless to install every conceivable package in every vm.
#get extendsions ids
cmd:
code --list-extensions
//foo.bar
//foo1.bar2
Visual Studio Code: Open settings file, add option:
"remote.SSH.defaultExtensions": [
"foo.bar",
]
ssh remote ssh rm ~/.vscode-server
vscode reconnect remote server

Is it possible to open VSCode from Windows terminal while SSH'ed into a virtual machine?

I'm working on some tutorials and trying to do something, but no idea if it can be done. I am using windows terminal in Windows 10. I have an Ubuntu virtual machine running.
I'd like to:
Open Windows terminal
SSH into the Linux Virtual Machine
Type in the code . command and have it open a version of VS Code on my Windows PC that is working on the folder in the Ubuntu VM.
I tried install code locally and on the command line in the other machine, but it doesn't work. I am sure there are other ways to do this but wanted to explain how I was doing it to show I at least tried something. Thanks for your help.
It's not quite as easy as the code . technique you get with the Remote - WSL extension, but Microsoft also provides a Remote - SSH extension that can be used to directly access the remote machine (without requiring WSL in-the-middle).
Once the Remote - SSH extension is installed in VSCode (and it may have already been installed in an extension pack with the WSL extension), and you have installed an OpenSSH client in Windows, there are several ways to access files on the remote host through SSH:
From the Command Palette (Ctrl+Shift+P), type Remote SSH to filter on those commands. From Connect to Host, you can add a new configuration, etc.
From the Activity Bar on the left, select the Remote Explorer icon, then in the dropdown at the top, select SSH Targets. You can add hosts here through the + icon.
There's a direct shortcut to Open a Remote Window at the far left of the status bar. This will give you similar filter options on the Command Palette as above.
Once a host is configured, you can browse it just as (well, almost) if it were local, open files, edit, etc. The one thing you can't do (as far as I'm aware) is any type of sudo/su editing on files that you don't have permissions to directly.
Full details in the VSCode docs here.