Tiodani
Tiodani

Reputation: 125

VS Code unable to open files in the "PROBLEMS" tab because the path is badly constructed

I'm developing in C++ using Visual Studio Code, and I noticed that, when the build of the program fails, I cannot quickly access the line of an error displayed in the "PROBLEMS" tab by clicking on it, because VS Code tries to read the file in a wrong path, then thinks the file doesn't exist. Example below:

Example

As you can see, it's like VS Code is always searching for a file in ${workspaceFolder}/${workspaceFolder}/, where it actually should be in ${workspaceFolder}/. Is there any configuration area where I can check and fix this?

Here is my c_cpp_properties.json:

{
"configurations": [
    {
        "name": "Win32",
        "includePath": [
            "${workspaceFolder}/**",
            "C:/SFML-2.5.1/include"
        ],
        "defines": [
            "_DEBUG",
            "UNICODE",
            "_UNICODE"
        ],
        "compilerPath": "C:\\MinGW\\bin\\g++.exe",
        "cStandard": "c11",
        "cppStandard": "c++17",
        "intelliSenseMode": "clang-x86",
        "browse": {
            "path": [
                "C:/SFML/SFML-2.5.1/include"
            ]
        }
    }
],
"version": 4
}

Here is the build task in tasks.json:

{
"version": "2.0.0",
"tasks": [
    {
        "type": "shell",
        "label": "Build BASIC Debug",
        "command": "C:\\MinGW\\bin\\g++.exe",
        "args": [
            "-g",
            "${workspaceFolder}\\mainBASIC.cpp",
            "-o",
            "${workspaceFolder}\\bin-debug\\DaniHash_BASIC 1.0.3d.exe",
            "-IC:\\SFML-2.5.1\\include",
            "-LC:\\SFML-2.5.1\\lib",
            "-lsfml-graphics-d",
            "-lsfml-window-d",
            "-lsfml-system-d",
        ],
        "options": {
            "cwd": "C:\\MinGW\\bin"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": "build"
    }
}

Upvotes: 2

Views: 1156

Answers (1)

Tiodani
Tiodani

Reputation: 125

I found out that this behaviour is related to the problemMatcher field of tasks.json. Adding a property to auto-detect the file location fixes the problem:

"problemMatcher": [
    {
        "base":"$gcc",
        "fileLocation": ["autoDetect", "${workspaceFolder}"]
    }
],

Reference: https://code.visualstudio.com/docs/editor/tasks

Upvotes: 3

Related Questions