[英]How do I set up Visual Studio Code problemMatcher to match C++ errors?
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++. 我在Visual Studio Code中设置了一个构建代码的任务(类似于如何设置VSCode来编译C ++代码? ),但正则表达式与g ++的输出不匹配。 Is there something I am doing wrong?
有什么我做错了吗? This is on MacOS Sierra.
这是在MacOS Sierra上。
I have a source file called ItemAssignmentMatrix.cpp with an error line in it on line 15. 我有一个名为ItemAssignmentMatrix.cpp的源文件,第15行有一个错误行。
thisisanerror;
My tasks.json problemmatcher pattern regexp looks like this: 我的tasks.json problemmatcher模式regexp看起来像这样:
{
"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: 当我执行此任务时,我的Makefile(使用g ++)输出一个错误行,如:
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. 因此,任务正确执行Makefile,但问题匹配器与正则表达式不匹配,所有输出只在输出窗口中显示为文本。
The regexp seems to be the same as given in https://code.visualstudio.com/docs/editor/tasks . regexp似乎与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. 我尝试在https://regex101.com中输入正则表达式和输出,但它似乎也找不到匹配项。
I assume this is a problem with the regexp, but I don't understand regexp syntax well enough to debug this at this point. 我认为这是regexp的一个问题,但我还不了解regexp语法,以便在此时调试它。
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. GCC的输出有一个内置的问题匹配器。 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. 例如。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.