从 VSCode 1.11.0(2017 年 3 月)开始,扩展可以通过以下方式贡献问题匹配器package.json https://code.visualstudio.com/updates/v1_11#_tasks:
{
"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"
}
]
}
}