Problem with saving and reopening a vscode workspace initiated from WSL - visual-studio-code

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?

Related

How Do I Set Default Launch Folder?

I want VSCode to always open the same folder when I launch it. The current behavior is to launch whatever folder VSCode thinks I last visited.
I maintain notes that are kept in folders on the same system that I run my local VSCode instance from. All of my development is on remote systems that are often not running when I launch VM. In a development session, I often have many (5-10) files open in VSCode on various source, config, and data files -- often on multiple remote systems. These remote systems are frequently not even running when I next launch VSCode.
When I launch VSCode, I want VSCode to always open (from the desktop) my local "notes" folder, where I keep my daily journal files. I want to then open folders on remote systems -- most often using the "File -> Open Recent" command.
I do not see anything in settings.json or in preferences that lets me control what folder is open on startup.
How do I configure VSCode so that it always opens the same (local) folder on startup, regardless of what files I was editing when I last closed it?

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.

Opening local folders in VS Code from WSL

I use WSL as my main command-line for all my git interactions.
I have the habit to open VS Code in the current folder by typing code . &
Recently VS Code started to open the folder as a remote folder instead of as a local folder.
The same thing happens even if I pass a full windows path like
code x:\\repos\\test. Instead of opening the specified folder, a new empty file is opened at ./x:/repos/test

VSCode can't write to files in Bash for Windows

I've been using Bash for Windows recently (its the Ubuntu "app") and I can open VSCode from the bash command line but when I try to save any modifications I've made to the file, it just says permission denied.
I've tried creating the files directly from VS Code's terminal but in that case it doesn't print out an error message but it also doesn't save anything.
That happens because you dont have permissions to write in the system32 folder. If you run the Ubuntu application as an administrator, you'll get the permissions to write. However, you won't be really in that file, because of the way that the virtualization of files and errors might happear doing so, and I do not recommend to run the console in a privilege mode (for seccurity issues).
Fortunately, in version 1903 of Windows 10, this will change, and you'll be able to navigate the WSL folders via Windows Explorer, and for sure that issue will disappear.
Edit: the best practice, you do the work in a folder in the Windows File System, and cd to there in the WSL console. VSCode has this integrated very well, if you have an open file in VSCode you can just do New Terminal and choose a WSL terminal. The terminal will already be in the folder where you file is.