簡體   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