vscode can't find buildifier on remote instance - visual-studio-code

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.

Related

Add VSCode portable location to PATH

I am using a portable version of VSCode, which means that the VSCode installation directory is not on PATH. However, quite a few VSCode extensions, scripts, etc., assume that if you run the command "code" or "code.exe" you will get a VSCode from somewhere. Generally you won't find one, or worse, if there is a default version install, you will find the wrong one. How can I add VSCode's base directory to PATH? It seems like there is a way in MacOS, with the "Install code in PATH" command, but there doesn't seem to be one for Windows.

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.

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

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

Git Bash wit Visual Studio Code: how to set permanent PATH

I'm using VSCode with git bash and minGW. Every time I restart VSCode the PATH is reset to default. I add my path to mingw with export PATH=$PATH:/c/mingw/bin
How can be permanent changed? I created .bashrc in my code folder but it doesn't works
Thanks
Search for "path" in the windows control panel. you can then "edit the system environment variables". You can edit it in to the system path.
You will need to restart VSCode after you change it, then it will be there every time..
Note that in the future this may cause problems if you have a separate version of something using mingw dlls.