Mike Slinn
Mike Slinn

Visual Studio Code Workspace Settings

Published 2021-04-11. Last modified 2021-04-12.

This article is categorized under Visual Studio Code.

For me, the killer feature that Visual Studio Code is how it integrates the Windows user interface with working on WSL and WSL2. Programs residing on the active WSL OS image execute natively on that OS, while VSCode continues to run as a native Windows application. This is possible because VSCode installs a proxy on the target OS. The proxy does the bidding of the Windows executable.

Getting a project to execute on the target OS instead of the host OS can be tricky. I have found that using a workspace to hold a collection of VSCode projects is very helpful, because the definition of the collection also defines how they are handled.

WSL projects have different types of VSCode workspace entries than Windows entries do. They are easy to recognize and change once you know what to look for. The two possibile types of VSCode workspace project entries in a .workspace file are:

  • WSL Project"uri": "vscode-remote://wsl+ubuntu/path/to/vscode/project"
  • Windows Project"path": "C:\\path\\to\\vscode\\project"

The following VSCode workspace file has both types of entries. For me, this is an error; I only want WSL projects. My task is to change the yellow highlighted Windows project and make it look like the other WSL projects.

aw.workspace.code-workspace
{
  "folders": [
          {
                  "uri": "vscode-remote://wsl+ubuntu/var/sitesUbuntu/www.ancientwarmth.com"
          },
          {
                  "uri": "vscode-remote://wsl+ubuntu/var/work/django/django"
          },
          {
                  "uri": "vscode-remote://wsl+ubuntu/var/work/django/oscar"
          },
          {
                  "uri": "vscode-remote://wsl+ubuntu/var/work/ancientWarmth/ancientWarmth"
          },
          {
                  "path": "../../var/work/django/main"
          }
  ],
  "remoteAuthority": "wsl+Ubuntu",
  "settings": {
          "liveServer.settings.multiRootWorkspaceName": "www.mslinn.com",
          "python.pythonPath": "/var/work/django/oscar/bin/python",
          "git.ignoreLimitWarning": true,
          "sqltools.connections": [
                  {
                          "previewLimit": 50,
                          "server": "localhost",
                          "port": 5432,
                          "driver": "PostgreSQL",
                          "name": "Ancient Warmth on Camille",
                          "database": "ancient_warmth",
                          "username": "postgres",
                          "password": "hithere"
                  }
          ]
  }
}

All I need to do is change this entry:

"path": "../../var/work/django/main"

To:

"uri": "vscode-remote://wsl+ubuntu/var/var/work/django/main"
😁

The modified entry will cause VSCode to launch the project from WSL, instead of Windows.