6

我有使用 custom 的项目problemMatcher。但我想将它提取到一个扩展中,使其可配置。所以最终它可以tasks.json

{
    "problemMatcher": "$myCustomProblemMatcher"
}

怎么做?

4

1 回答 1

3

从 VSCode 1.11.0(2017 年 3 月)开始,扩展可以通过以下方式贡献问题匹配器package.json

{
    "contributes": {
        "problemMatchers": [
            {
                "name": "gcc",
                "owner": "cpp",
                "fileLocation": [
                    "relative",
                    "${workspaceRoot}"
                ],
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            }
        ]
    }
}

然后任务可以使用"problemMatcher": ["$name"]($gcc在本例中) 引用它。


除了定义匹配器的pattern内联之外,它还可以贡献,problemPatterns因此它是可重用的(例如,如果你想在多个匹配器中使用它):

{
    "contributes": {
        "problemPatterns": [
            {
                "name": "gcc",
                "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
                "file": 1,
                "line": 2,
                "column": 3,
                "severity": 4,
                "message": 5
            }
        ],
        "problemMatchers": [
            {
                "name": "gcc",
                "owner": "cpp",
                "fileLocation": [
                    "relative",
                    "${workspaceRoot}"
                ],
                "pattern": "$gcc"
            }
        ]
    }
}
于 2017-01-19T19:52:33.047 回答