Can't get the simplest problem matcher to report any problem

283 Views Asked by At

I've been googling for hours, simplifying to the dumbest vs code project:

enter image description here

The task runs: enter image description here

Output is empty:

And no problem is reported.

What am I missing?

[Edit]

As requested in the comments, here I echo an actual error message, copied from https://code.visualstudio.com/docs/editor/tasks#_defining-a-problem-matcher:

echo helloWorld.c:5:3: warning: implicit declaration of function ‘prinft’

I copied the example problem matcher from the same link. Still doesn't show anything. For some reason the terminal output has some line feeds.

enter image description here

[Edit 2] Ok, thanks to help from rioV8 and Yassin Hajaj, I figured it out. That was a frustrating way to learn how problem matchers work. My lack of experience with regexp didn't help.

Turns out "shell" defaults to PowerShell, which has an echo command displaying each token to a new line. I finally got it to be one line with some escaping trickery:

"command": "echo \\\"dummy.cpp:5:3: warning: implicit declaration of function ‘prinft’\\\""

Also the file, line, and message properties are mandatory.

So here's a working example:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "echo",
            "type": "shell",
            // by default the command appears in the terminal so 2 lines will actually be matched
            "command": "echo \\\"dummy.cpp:5:3: warning: implicit declaration of function ‘prinft’\\\"",
            "problemMatcher": {
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "message": 5
                }
            }
        }
    ]
}
0

There are 0 best solutions below