Vscode : Open file locally using Remote-SSH through integrated terminal - visual-studio-code

I am using Remote-SSH plugin for remote development and would like to open a file in the existing editor using an integrated terminal (which is running a remote shell). A similar issue was posted on fit repository but it doesn't seem to work now.
https://github.com/microsoft/vscode-remote-release/issues/766
Local Machine
1.41.1
26076a4de974ead31f97692a0d32f90d735645c0
Windowsx64
Remote Machine
1.41.0
9579eda04fdb3a9bba2750f15193e5fafe16b959
CentOsx64
Can you help me to debug

Copying my answer from https://stackoverflow.com/a/68090934/319542
You shouldn't have to do anything. VSCode automatically sets the path/PATH to the code in the path/PATH environment variable depending on your shell. See this response. You might be overwriting your path/PATH like I was. I was accidentally overwriting path in ~/.cshrc and PATH in ~/.bashrc and was running into the same issue. After fixing it, I can run code on the command line. which code returns the location of the command.
Until I spent time to figure it out, I was using the two methods mentioned below. Both of which worked for me in bash; you can modify it for your shell as you see fit. But really fix your path/PATH rather than using these methods.
Adding location of code to the PATH in ~/.bashrc
export PATH=${VSCODE_GIT_ASKPASS_NODE%/*}/bin:$PATH
OR
Setting alias to code in ~/.bashrc
alias code="${VSCODE_GIT_ASKPASS_NODE%/*}/bin/code"
More on path vs. PATH here and here

Related

An error in the running of kotline in vscode

enter image description here
Can anyone say how to debug it
It seems like your kotlin directory is not added to your PATH variable thus the extension/terminal may not know what to execute, when trying to execute kotlinc.
The easiest way to resolve this issue is by adding the path to your kotlin directory (path/to/your/kotlin/bin) to your PATH variable
(see here), if you are on windows, or here, if you are on a linux system.
You can check, if it works by opening a command line window and trying to execute
kotlinc -version
However, as it seems like you are using Code-Runner extension in vscode, you can also update your settings.json file:
reference here.

vscode can't find buildifier on remote instance

I'm bumping into a weird vscode issue. I use vscode to ssh into my EC2 instance. I primarily use bazel as the dependency management and build system for development. I installed buildifier, and included in my path variable however vscode still doesn't detect it. If I type buildifier <some bazel build file> in the terminal in vscode, it works perfectly, but if I try to use the formatting shortcut on the file using vscode, it doesn't. I went to the extension settings, and in the remote settings I explicitly put buildifier as the executable command. Still not working. Any help would be appreciated.
Thanks!
It's likely that the path you've set is set somewhere that the vscode remote server isn't looking. So it might be in your shell path but not the vscode remote servers path when it starts up.
As a workaround find the full path of buildifier e.g.
whereis buildifier
Then simply copy past the full path of buildifier into your settings under the Bazel: Buildifier Executable section.

Opening WSL terminal in current VSCode directory without using VSCode server

I've used Git Bash for most bash-required tasks before, but since I've found WSL to be much more feature-rich as it's basically an entirely new subsystem. However, when I used to use VSCode along with Git Bash, it would simply cd into the working directory of the project for ease of use. However, it doesn't do that here. The only solutions I've found online are to create an entirely new Remote WSL VSCode window, but this is way too high maintenance for what I'm trying to do as I'm literally just trying to get VSCode to automatically cd into the correct directory. Thanks in advance.

How does VSCode's Remote Extension open files in my local editor through its internal terminal?

I use VSCode's remote development extension fairly regularly. I can use the terminal in VS Code as if it were on my own machine, and even the code command works correctly. That is, when I'm in a remote VSCode session, I can type code path/to/some/file and it will open another editor tab with that file. The terminal session and the file being opened are on the remote machine to which I've connected.
I have VSCode installed on the remote machine, and the code executable is in my PATH. So my question is, how is this functionality implemented behind the scenes? That is, how does VSCode know that when I type code path/to/some/file it should open that file into another editor tab on my machine instead of trying to fire up VSCode on the remote machine?
Literally seconds after I wrote the question I found the answer.
If I run which code in the terminal, it doesn't resolve to the usual VSCode executable, but instead it resolves to one located at $HOME/.vscode-server/bin/a5d1cc28bb5da32ec67e86cc50f84c67cc690321/bin/code.
If I echo $PATH I can see that $HOME/.config/bin and $HOME/.vscode-server/bin/a5d1cc28bb5da32ec67e86cc50f84c67cc690321/bin has been appended to the beginning of the PATH env var that my bash profile generates.
I assume this means that VSCode is executing bash with a different profile script that
Sources my usual bash profile
Creates the directories above and copies some helper programs into them
Modifies my path to include these directories
I also assume that the injected code executable is communicating with my local instance of VSCode in some way, instructing it to open the file in its editor.

How is the PATH variable defined for the vscode process itself (not the integrated terminal)?

I'm currently using a vscode over a remote ssh connection and cannot figure out how to set the search PATH for the vscode process itself. I have set the PATH for processes run in the terminal in my .bashrc file, which is also sourced from .bash_profile.
In spite of this, vscode complains that pipenv is not on the path although it is visible to my integrated terminal session. In my .bashrc I am loading environment modules to load versions of needed libraries, which get put on the PATH. Since I created my virtualenv using pipenv in the terminal, it knows which python version to use and makes a link to it in the environment definition. Because of the way python virtual environments work, the actual python binary is copied to the virtual environment. And because vscode has hardcoded paths where to look for virtual environments it is able to find the correct version of python that is in use (despite it not seeing it in the PATH).
In addition, hardcoding the path to pipenv using the extension setting python.pipenvPath still produces a "not found" error.
Solutions that I have seen elsewhere suggest launching vscode from the command line so that the process inherits the PATH settings. However, this will not work over a remote connection.