【发布时间】:2017-02-02 01:33:01
【问题描述】:
我设置了在 Visual Studio Code 中构建代码的任务(类似于 How do I set up VSCode to compile C++ code?),但正则表达式与 g++ 的输出不匹配。有什么我做错了吗?这是在 MacOS Sierra 上。
我有一个名为 ItemAssignmentMatrix.cpp 的源文件,其中第 15 行有一个错误行。
thisisanerror;
我的 tasks.json 问题匹配器模式正则表达式如下所示:
{
"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
}
}
}
]
}
当我执行此任务时,我的 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
所以任务正确地执行了 Makefile,但是问题匹配器不匹配正则表达式,所有的输出只是在输出窗口中显示为文本。
正则表达式似乎与https://code.visualstudio.com/docs/editor/tasks 中给出的相同。
我尝试在https://regex101.com 中输入正则表达式和输出,但似乎也找不到匹配项。
我认为这是正则表达式的问题,但我对正则表达式语法的理解不够好,无法在这一点上进行调试。
此表达式与输出不匹配是否有某些原因,或者我的问题匹配器是否有其他问题?提前感谢您提供的任何帮助。
【问题讨论】:
-
乍一看,我在您的
args数组中发现了一个问题:"args": ["-f" "${workspaceRoot}/Makefile"]。参数之间必须有逗号。也就是说,我认为 RegEx 没有任何问题。我在浏览器控制台中对其进行了测试,它可以工作。
标签: windows visual-studio-code