Visual studio code command doesn't work on WSL 2 - visual-studio-code

For some reason, when I type the command code . from a WSL terminal I have the message:
Command is only available in WSL or inside a Visual Studio Code terminal.
After some research, I tried to fix it with the following commands:
rm -r ~/.vscode-server
code .
It redownloads VS Code Server and it works correctly but just for one terminal instance. When I open a new terminal, I still have the message :
Command is only available in WSL or inside a Visual Studio Code terminal.
I don't have the issue when I use the command code in a VS code terminal.

Related

Terminal doesn't work in Visual Studio Code

When I open my visual studio code my terminal is blank, neither ubuntu, nor command prompt, nor powershell, nor JavaScript debugger work.
I tried to change the path by which vs code calls my ubuntu but it didn't work.

Can I run VSCODE in a text-only Linux terminal window similar to the way I run VIM?

I am working on a linux machine my work can benefit from VSCODE.
When I install and try to run VSCODE on an Ubuntu machine, I get this error:
root#ca012294dcc1:/tmp# code --user-data-dir /tmp
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] y
To no longer see this prompt, start Visual Studio Code with the environment variable DONT_PROMPT_WSL_INSTALL defined.
/usr/share/code/bin/../code: error while loading shared libraries: libxshmfence.so.1: cannot open shared object file: No such file or directory
WSL is out of scope. This is not a WSL senario
Remote SSH is out of scope. I know I can connect over SSH with Visual Studio Code. But I like to replace something like VIM with code
There is no Linux GUI available. Only text mode.
Is what I am trying to do possible?

Visual Studio Code not running/working on WSL 2

Somehow when I run code . inside the WSL, it simply doesn't do anything. If I which code it does return the VS Code path on windows, but still nothing happens.
Well, after some research, what really fixed the issue for me was the following:
Within the WSL terminal, type rm -r ~/.vscode-server to delete the VS Code WSL server.
Exit the terminal and from your PowerShell/Cmd, run wsl --shutdown.
Then you can log in back to your WSL and run code . and it should work normally.
I solved it following this post with slight modifications.
exit all instaces of wsl
From the power shell run wsl --shutdown
Start VS Code on Windows
Open a previously saved project which uses wsl (this is the difference)
Open wsl and run code . starts VS Code for me
Note: the issue appeared for me after upgrading to wsl2

How to open a file from terminal in a tmux session in Visual Studio Code

One can open a file from the integrated terminal in Visual Studio Code via:
code -r something.dat
Unfortunately, this does not work for me when I work in the terminal within a tmux-session. The error I get is:
-bash: code: command not found
I googled the error and it seems I have to include vscode on my Path variable (example: similar problem).
I'm now confused on what to do as it works from the normal integrated terminal but doesn't work in the tmux "environment".
Do you have any ideas?
Probably you first started the tmux server from a terminal without this in PATH and you are not adding it in any of the shell startup files that the shell uses when started from tmux (remember tmux starts login shells by default).

How can I fix the "segmentation fault" error in Visual Studio Code's terminal?

On Windows 10, I have Visual Studio Code installed.
When I open the terminal (Git Bash) and type less-watch-compiler, I get the error:
Segmentation fault
But if I go to the Git Bash terminal itself (outside Visual Studio Code) and type less-watch-compiler, the command works.
How can I fix this problem?
I reinstalled Git for Windows, but it didn't help.
I have the latest version of Visual Studio Code (1.36.1)
When I use the "cmd" editor within Visual Studio Code, it works fine as well.
Not sure if it's the same problem but I was also getting segmentation fault errors running VSCode with WSL.
What fixed it for me was:
rm -rf ~/.vscode-server
The next time I tried the command, VScode downloaded the necessary files and everything worked again.