How to create VS Code extension that provides custom problemMatcher?

隐身守侯 提交于 2019-12-22 08:57:10

问题


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

How to do that?


回答1:


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

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


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


来源:https://stackoverflow.com/questions/41705390/how-to-create-vs-code-extension-that-provides-custom-problemmatcher

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!