Hypersnips C++ snippets work in Windows but not in WSL on the same machine - visual-studio-code

On creating a simple cpp.hsnips file:
snippet eq "equals" iA
=
endsnippet
and placing it in C:\users\Tryer\AppData\Roaming\Code\User\hsnips folder
and providing the following settings:
"hsnips.hsnipsPath": "%APPDATA%\Code\User\hsnips" in user settings.json that resides in C:\Users\Tryer\AppData\Roaming\Code\User
"hsnips.hsnipsPath": "/mnt/c/users/Tryer/AppData/Roaming/Code/User/hsnips/" in Remote [WSL:Ubuntu-20.04] settings.json which resides in \\wsl$\Ubuntu-20.04\home\Tryer\.vscode-server\data\Machine
the snippet file still does not seem to be loaded when the project is opened via WSL and a C++ file is open. Pressing eq does not give = . Opening the same project file in Windows works fine with eq rendering =
In WSL, the following image is obtained which seems to indicate many uncaught errors between the local installed version and the WSL installed version. The local installed version is greyed out but the WSL version is active.
Is there a way to get the snippet file to perform in WSL?

Related

Visual Studio Code with remote db (ssh) shows each file twice

I'm using VS-Code from Windows to remote Linux machine, using SSH, and each file appears twice... once with a relative path to the base project path, and once with a full path (/home/$user/...)
It causes lots of problems, such as opening the same file twice (and then being warned that 'file was changed on disk') or cannot find declarations and stuff.
How can I solve that?

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.

Visual Studio Code only compiles when launched from project folder on Linux

I have Visual Studio Code installed in Ubuntu 20.04. I love how it works. I installed it from the tar ball. Same with the SDK. I just found that those appear to work better than installing from deb packages.
I created a desktop file so I could add Visual Studio Code to the dock and launch it that way, but what I've noticed is that projects won't compile. I get errors stating it can't find the project even though the errors are listing the folder where the items exist.
The only way I can get it to work is to:
Open a terminal.
Navigate to the folder where the project files reside.
Launch code from the command line.
Then it works. Otherwise, I get a pop-up error that says "The preLaunchTask 'build' terminated with exit code -2" and then the terminal window is filled with errors.
Here's the last of the error messages and then I opened up a terminal and it shows that I'm in the folder for the project and the csproj exists there:
This also happens if I install Visual Studio code from a repository. It seems launching it from the Unity desktop breaks something. But if I launch it from the command line in a terminal session from the folder where the project resides, then the problem goes away.
I can also reproduce this error from the command line if I launch Visual Studio Code from a different folder than the project I'm trying to compile.
Is this common? Just curious. I'm wondering if because when I launch it from the Unity desktop, it's launching under a different
I got it working under 20.04. I must have done something wrong so I did a wipe of the .NET Core install and reinstalled it all using the bash shell script and then was able to install Code via Software Installer tool. Not sure why it didn't work before, but it works now.

Problem with saving and reopening a vscode workspace initiated from WSL

I open my vscode with code . command from WSL terminal because I want to work directly in my WSL. It works fine and for example, the file explorer of vscode shows directory structures based on WSL machine and not based on my Windows machine.
My problem is however that, when I save a workspace using File -> Save Workspace As, it saves it again as a workspace in my Windows machine. So when I close and open my vscode again and use Open Workspace... to open the already saved workspace(in previous step), explorer reads directories from Windows machine.
You might ask what's the difference between saving files in /mnt/c/Users/[user]/Desktop or C:\Users\[user]\Desktop, but the problem is two things:
I might open a session from a directory in WSL that is (unlike Desktop) inaccessible from Windows.
Even if my Desktop is my current working directory, I may add another directory to my workspace (using Add Folder to Workspace...) and even if it is a path accessible from Windows, the next time I open the workspace, I will get an exclamation mark and such an error near that directory in explorer:
C:\mnt\d\Files_And_Downloads\Google Drive_Code . Can not resolve workspace folder
I suspect this is a bug, vscode has mixed the WSL path and Windows path. So anyone who uses Remote - WSL extension and can tell me what's going on here?

How to open Visual Studio Code from the command line on linux?

I know I can use command "code" to open VS code or file, but I don't know what should I do to make it possible after I install VS code in Ubuntu.Thanks.
Launching from the Command Line
You can launch VS Code from the command line to quickly open a file, folder, or project. Typically, you open VS Code within the context of a folder. We find the best way to do this is to simply type:
code .
Tip: We have instructions for Mac users in our Setup topic that enable you to start VS Code from within a terminal. We add the VS Code executable to the PATH environment variable on Windows and Linux automatically during installation.
Sometimes you will want to open or create a file. If the specified files does not exist, VS Code will create them for you:
code index.html style.css readme.md
Tip: You can have as many file names as you want separated by spaces.
Source: https://code.visualstudio.com/Docs/editor/codebasics
So, there are a couple of solutions for this.
I've linked a video that shows you how to add vscode to $PATH
(which didn't work for me because I couldn't find the "shell:install path" command)
I uninstalled the vscode from my ubuntu and re-installed using sudo snap install --classic code
(This method worked for me)
Tell me which one works for you... and if you have extensions installed to your vscode then i guess you ought to make a backup or something.
Link to the video: https://youtu.be/iP5FKZXtDBs