繁体   English   中英

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

[英]How do I set up Visual Studio Code problemMatcher to match C++ errors?

我在Visual Studio Code中设置了一个构建代码的任务(类似于如何设置VSCode来编译C ++代码? ),但正则表达式与g ++的输出不匹配。 有什么我做错了吗? 这是在MacOS Sierra上。

我有一个名为ItemAssignmentMatrix.cpp的源文件,第15行有一个错误行。

thisisanerror;

我的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
                }
            }
        }
    ]
}

当我执行此任务时,我的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,但问题匹配器与正则表达式不匹配,所有输出只在输出窗口中显示为文本。

regexp似乎与https://code.visualstudio.com/docs/editor/tasks中给出的相同。

我尝试在https://regex101.com中输入正则表达式和输出,但它似乎也找不到匹配项。

我认为这是regexp的一个问题,但我还不了解regexp语法,以便在此时调试它。

是否有某些原因导致此表达式与输出不匹配,或者我的问题匹配器是否存在其他问题? 提前感谢您提供的任何帮助。

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

        "problemMatcher": "$gcc"

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

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

例如。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM