How to create VS Code extension that provides custom problemMatcher?
Asked Answered
D

1

8

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?

Dafodil answered 17/1, 2017 at 19:29 Comment(0)
U
6

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"
            }
        ]
    }
}
Unbolted answered 19/1, 2017 at 19:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.