microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.53k stars 1.56k forks source link

Scan task with Ninja shows wrong problems directory #2051

Closed phreppo closed 6 years ago

phreppo commented 6 years ago

I'm using Ninja build system to build a C project. I'm using the extension C/Cpp. When i build the project with the Scan task, the extension shows the warnings in the problems panel, but the paths to the files are wrong: they point to upper directories in the file system tree.

Steps to Reproduce:

  1. Go to the ${workspaceRoot} directory of a C project. I'm actually workign on this
  2. Create the build directory with Meson: meson build
  3. Configure the Scan task (as here)
        {
            "label": "Scan",
            "type": "shell",
            "command": "ninja scan-build",
            "group":"build",
            "options": {
                "cwd": "${workspaceRoot}/build"
            },
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": true,
                "panel": "shared"
            },
            "problemMatcher": {
                "base":"$gcc",
                "fileLocation" : ["relative", "${workspaceRoot}/build"]
            }
        }
  4. Launch Scan task
  5. Look at the output: the warnings should point to files in the ${workspaceRoot} directory, but actually for me they point to some other locations. Example:

Console output with warnings: console3

Problems panel(pointing to the wrong directory, because my project is located in /home/phreppo/CGen): problems3

Dialog window that appears when I click on one warning. In this particular example the file that should be opened is /home/phreppo/CGen/test/type.c window3

It's curious, because with the task Build the problems points to the right directory, and they have the same fileLocation property. Here's the Build task:

        {
            "label": "Build",
            "type": "shell",
            "command": "ninja",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "options": {
                "cwd": "${workspaceRoot}/build"
            },
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": true,
                "panel": "shared"
            },
            "problemMatcher": {
                "base":"$gcc",
                "fileLocation" : ["relative", "${workspaceRoot}/build"]
            }
        }

Does this issue occur when all other extensions are disabled?: Yes

Reopening in Microsoft/cpp-tools from a similar one, but now Build task is ok: the problem is the Scan task.

bobbrow commented 6 years ago

Looking at your output, /home/src/type.c looks like the correct result of combining /home/phreppo/CGen/build and ../../../src/type.c.

It would appear that the fileLocation for the Scan task should have been /home/phreppo/CGen/build/meson-private/tmpsm350_09 in order to resolve the relative path to /home/phreppo/CGen/src/type.c. Am I missing something?

phreppo commented 6 years ago

Setting the problem matcher for the Scan task as:

            "problemMatcher": {
                "base":"$gcc",
                "fileLocation" : ["relative", "${workspaceRoot}/build/meson-private/tmpsm350_09"]
            }

solves the problem, thanks!