I set up a task for building code in Visual Studio Code (similar to How do I set up VSCode to compile C++ code?), but the regex is not matching the output from g++. Is there something I am doing wrong? This is on MacOS Sierra.
I have a source file called ItemAssignmentMatrix.cpp with an error line in it on line 15.
thisisanerror;
My tasks.json problemmatcher pattern regexp looks like this:
{
"version": "0.1.0",
"command": "make",
"isShellCommand": true,
"showOutput": "always",
"echoCommand": true,
"suppressTaskName": true,
"tasks" : [
{
"taskName": "clean",
"args": ["-f" "${workspaceRoot}/Makefile" "clean"]
},
{
"taskName": "build",
"isBuildCommand": true,
"args": ["-f" "${workspaceRoot}/Makefile"],
// Use the standard less compilation problem matcher.
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}
When I execute this task, my Makefile (using g++) outputs an error line like:
g++ -g -Wall -c -o obj/Darwin_x86_64/ItemAssignmentMatrix.obj src/ItemAssignmentMatrix.cpp
src/ItemAssignmentMatrix.cpp:15:1: error: C++ requires a type specifier for all declarations
thisisanerror;
^
1 error generated.
make: *** [obj/Darwin_x86_64/ItemAssignmentMatrix.obj] Error 1
So the task executes the Makefile properly, but the Problem Matcher doesn't match the regular expression, all the output just shows up as text in the output window.
The regexp seems to be the same as given in https://code.visualstudio.com/docs/editor/tasks.
I tried entering the regexp and the output in https://regex101.com, and it also doesn't seem to find a match.
I assume this is a problem with the regexp, but I don't understand regexp syntax well enough to debug this at this point.
Is there some reason why this expression isn't matching the output, or is there something else wrong with my Problem Matcher? Thanks in advance for any help you can provide.
There's a built-in Problem Matcher for GCC's output. Try the following:
"problemMatcher": "$gcc"
It defaults to relative paths to the workspace root. You can change that using
"problemMatcher": {
"base": "$gcc",
"fileLocation": ["absolute"]
},
for example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With