skip to Main Content

When I open Visual Studio Code through Ubuntu PowerShell with "code .", I don’t have instant inline syntax checking while coding. Also all filenames are white:
First connection from PowerShell with command "code ."

The weird thing is that if I click on the lower right corner and I reopen the folder in Windows: Reopening Folder in Windows
then if I reopen it again in WSL, finally I get the filenames colored and the inline syntax check works!

Back to WSL

It seems it wasn’t properly connected the first time or something.

How can I properly boot Visual Studio Code with WSL directly with a PowerShell command without having to switch to Windows and then back to WSL?

This is how file c_cpp_properties.json looks:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c17",
            "cppStandard": "gnu++17",
            "intelliSenseMode": "linux-gcc-x64"
        }
    ],
    "version": 4
}

2

Answers


  1. Give this a try; install the following extensions:

    1. C/C++ for Visual Studio Code

    2. Code Runner

    Note: I guess you have GCC installed already

    Login or Signup to reply.
  2. Your connection to WSL is probably not being properly established.

    To ensure that the connection is established properly, you can try launching Visual Studio Code using the code command with the --remote option, like this:

    code --remote wsl+<distribution_name> .
    

    Using --remote will ensure that Visual Studio Code with the WSL instance, and should prevent the connection from breaking as easily. You should see inline syntax checking and colored filenames right away.

    [NOTICE] When you do this for the first time, you may get a prompt to install the WSL extension. Click install, close Visual Studio Code, wait about 10s, and then reopen it again using the same command. You may have to do this at least 2-3 times depending on your setup.

    If you continue to experience issues, you may want to check your Visual Studio Code settings to ensure that they are configured properly for working with WSL. For example, you can try setting the remote.WSL.useWsl setting to true to ensure that Visual Studio Code uses WSL as the default terminal.

    I haven’t used Visual Studio Code like that in quite a while though, so the settings may be different and the remote.WSL.useWsl key may not exist anymore. It’s worth trying though.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search