如何创建提供自定义问题匹配器的 VS 代码扩展?
How to create VS Code extension that provides custom problemMatcher?
我有一个使用自定义 problemMatcher
的项目。但我想将它提取到一个扩展中,使其可配置。所以最终它可以像
一样用于tasks.json
{
"problemMatcher": "$myCustomProblemMatcher"
}
怎么做?
截至 VSCode 1.11.0(2017 年 3 月),extensions can contribute problem matchers via 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"
}
]
}
}
我有一个使用自定义 problemMatcher
的项目。但我想将它提取到一个扩展中,使其可配置。所以最终它可以像
tasks.json
{
"problemMatcher": "$myCustomProblemMatcher"
}
怎么做?
截至 VSCode 1.11.0(2017 年 3 月),extensions can contribute problem matchers via 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"
}
]
}
}