如何创建提供自定义问题匹配器的VS Code扩展? [英] How to create VS Code extension that provides custom problemMatcher?

查看:205
本文介绍了如何创建提供自定义问题匹配器的VS Code扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有使用自定义problemMatcher的项目.但我想将其提取为可配置的扩展.因此最终它可以像一样用在tasks.json

I have project that uses custom problemMatcher. But I would like to extract it into an extension making it configurable. So eventually it could be used in tasks.json like

{
    "problemMatcher": "$myCustomProblemMatcher"
}

该怎么做?

推荐答案

从VSCode 1.11.0(2017年3月)开始,扩展可以通过package.json 来贡献问题匹配者:

As of VSCode 1.11.0 (March 2017), 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)对其进行引用.

Tasks can then reference it with "problemMatcher": ["$name"] ($gcc in the case of this example).

除了定义匹配器的pattern内联外,它还可以在problemPatterns中提供内容,因此可重复使用(例如,如果要在多个匹配器中使用它):

Instead of defining a matcher's pattern inline, it can also contributed in problemPatterns so it's reusable (for instance if you want to use it in multiple matchers):

{
    "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"
            }
        ]
    }
}

这篇关于如何创建提供自定义问题匹配器的VS Code扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆