gpt4 book ai didi

windows - 如何设置 Visual Studio Code problemMatcher 以匹配 C++ 错误?

转载 作者:可可西里 更新时间:2023-11-01 14:42:31 25 4
gpt4 key购买 nike

我在 Visual Studio Code 中设置了构建代码的任务(类似于 How do I set up VSCode to compile C++ code? ),但正则表达式与 g++ 的输出不匹配。我做错了什么吗?这是在 MacOS Sierra 上。

我有一个名为 ItemAsignmentMatrix.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 中输入正则表达式和输出,而且它似乎也没有找到匹配项。

我认为这是正则表达式的问题,但我对正则表达式语法的理解还不够好,无法在此时进行调试。

这个表达式与输出不匹配的原因是什么,还是我的问题匹配器有其他问题?提前感谢您提供的任何帮助。

最佳答案

GCC 的输出有一个内置的问题匹配器。尝试以下操作:

        "problemMatcher": "$gcc"

它默认为工作区根目录的相对路径。你可以改变它使用

        "problemMatcher": {
"base": "$gcc",
"fileLocation": ["absolute"]
},

例如。

关于windows - 如何设置 Visual Studio Code problemMatcher 以匹配 C++ 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39673485/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com