microsoft / vscode-cpptools

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

Visual C++ problem matcher #3815

Closed gildor2 closed 4 years ago

gildor2 commented 5 years ago

Hi team,

I'm using VS Code cpptools extension with CL.exe compiler backend, and I never understood why only GCC problem matcher exists in settings. I've created own problemMatcher, and using it for a few months already with no troubles. I'd like to contribute it, however I'm C++ programmer and doing a pull request for extension is quite difficult for me. Hopefully you can integrate the following piece of json into relevant place (probably package.json?)

Here's what I use:

    "problemMatcher": {
        "owner": "cpp",
        "fileLocation": [
            "relative",
            "${workspaceRoot}"
        ],
        "pattern": {
            "regexp": "^(.*)\\((\\d+)\\)\\s+:\\s+(error|warning)\\s+(\\w+\\s*:\\s+.*)$",
            "file": 1,
            "line": 2,
            "severity": 3,
            "message": 4
        }
    }

I'm not sure what "owner" should use - possibly "cpptools". It should work with all Visual Studio compiler versions as it didn't get major changes in compiler output for years. I used it with VS2013, and now using with VS2019 compiler.

Hope these changes will be considered for merging.

Thanks, Konstantin

sean-mcmanus commented 5 years ago

VS Code already ships with a $msCompile problem matcher. Can you try using that as your "base" problem matcher? You shouldn't need to set the pattern. Let us know if that is insufficient.

gildor2 commented 5 years ago

Hi Sean, Thanks, $msCompile works well. I think it should be explicitly mentioned somewhere that Visual Studio (especially CL.EXE) may use this problem matcher, otherwise I had to read everything everywhere to find correct words - I think you'll agree that the word "Microsoft" in description of another Microsoft's product are too hard for being recognized as description of VS build system. Any description of cpptools explains how to work with GCC, but not with Microsoft's compiler.

sean-mcmanus commented 5 years ago

We have docs at https://code.visualstudio.com/docs/cpp/config-msvc that use the $msCompile problem matcher. What exactly are you suggesting should be changed?

gildor2 commented 5 years ago

Thank you for the link. It seems this page appeared months later than I started to use VS Code for MSVC compiler (page shows April 2019 date, WebArchive confirms that). I've read tons of documentation, spent hours trying to google information, and penetrated through all things myself. The only help was available is for gcc/linux.

I think such significant documentation updates should be mentioned somewhere, e.g. in VSCode blog. Personally I subscribed to blog's RSS, and the only things which appears there are monthly update notes and information for web developers.

sean-mcmanus commented 5 years ago

Maybe we can blog about the new docs for the June/July blog -- @tara-raj ?

sketch34 commented 5 years ago

I can't seem to get the problemMatcher to work for MSVC builds at all. I've tried $msCompile as well as the custom pattern suggested here. The batch file actually calls a python script that uses CMake / Ninja / CL. I don't think those details matter (?) because there is regular old CL output in the terminal amongst all the CMake stuff.

    "tasks": [
        {
            "label": "Build (build plugin)",
            "type": "shell",
            "command": "${workspaceFolder}/../build.bat",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "reveal": "always",
                "panel": "dedicated",
                "clear": true
            },
            "problemMatcher": "$msCompile"
        },

Example error output that isn't being detected:

    C:\Dev\src\blah\test.cpp(583): error C2065: 'asdasd': undeclared identifier
sean-mcmanus commented 5 years ago

@sketch34 I'm not able to repro that bug. Any ideas what is required for the repro? You could try filing a bug with VS Code as well, since we don't ship the "$msCompile" problemMatcher.

sketch34 commented 5 years ago

Any ideas what is required for the repro?

Hmm that's the extent of the setup it I think. Unless there is some issue with how the output is coming via:

.bat script -> python -> cmake/ninja -> cl.exe

And maybe the problemMatcher somehow doesn't see the output.

photex commented 4 years ago

I have a similar situation. Output from another tool seems to prevent the problem matcher from working. The task runs a tool (tmbuild) which runs premake, which runs msbuild I guess, which runs cl.exe. The paths appear correct and the output is colored correctly. I can ctrl+click on the file and jump to the line. But there is no output in the "Problems" tool window.

VS Code 1.47.3 (June 2020)

photex commented 4 years ago

Also, the documentation only demonstrates functionality if a person uses cl.exe directly in the task definition window.

If I try this with a CMake project, using the CMake-tools extension the output window is used instead of the terminal since it builds without a task. I can't ctrl+click on the file path, but I do get errors and warnings listed in the Problems tool window.

However, if I create a tasks.json and run that build then I do not get the warnings and errors in the problems window.

photex commented 4 years ago

Howdy! I've determined the problem to be something that occurs when you're using a *.code-workspace instead of just opening a folder. For whatever reason, task output in a workspace is delivered to the Terminal tab instead of the Output tab. That's most obvious difference and the result is that I'm seeing errors and warnings in the Problems tab correctly again and can cycle through issues using F8.

Colengms commented 4 years ago

Since docs are available (and no longer new), and the $msCompile problem matcher is part of VS Code, this would seem to not be an issue specific to the C/C++ Extension. If there is something here specific to the C/C++ Extension, please let us know, and we can reactivate or open a more specific bug.