Defining a ProblemMatcher in VSCode tasks -- schema disagrees with docs?

14.9k Views Asked by At

In VSCode I'm trying to create a ProblemMatcher to parse errors on a custom script of mine which I run (markdown file -> pandoc -> PDFs if you're interested).

The pretty good VSCode ProblemMatcher documentation has an example task which appears (to me) to run a command ("command": "gcc") and define a problem matcher ("problemMatcher": {...}).

When I try this for my tasks.json file with both, I get an 'the description can't be converted into a problem matcher' error, which isn't terribly helpful. I checked the tasks.json schema and it clearly says:

The problem matcher to be used if a global command is executed (e.g. no tasks are defined). A tasks.json file can either contain a global problemMatcher property or a tasks property but not both.

Is the schema wrong? In which case I'll raise an issue.

Or is my code wrong? In which case, please point me in the right direction. Code in full (minus comments):

{
  "version": "2.0.0",
  "tasks": [
    {
        "label": "md2pdf",
        "type": "shell",
        "command": "md2pdf",
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "presentation": {
            "reveal": "always",
            "panel": "shared",
            "showReuseMessage": false
        },
        "problemMatcher": {
            "owner": "Markdown",
            "fileLocation": ["absolute", "/tmp/md2pdf.log"],
            "pattern": [
                {
                    // Regular expression to match filename (on earlier line than actual warnings)
                    "regexp": "^Converting:\\s+(.*)$",
                    "kind": "location", 
                    "file": 1
                },
                {
                    // Regular expression to match: "l.45 \msg_fatal:nn {fontspec} {cannot-use-pdftex}" with a preceding line giving "Converting <filename>:"
                    "regexp": "l.(\\d+)\\s(.*):(.*)$",
                    "line": 1,
                    "severity": 2,
                    "message": 3
                }
            ]
        }
    }]
}
3

There are 3 best solutions below

0
On BEST ANSWER

I've since spent more time figuring this out, and have corresponded with VSCode team, which has led to improvements in the documentation.

The two changes needed to get something simple working were:

  1. Need to have "command": "/full/path/to/executable" not just "executable name".
  2. The "fileLocation" isn't about the location of the file to be matched, but about how to treat file paths mentioned in the task output. The file to be matched can't be specified, as it's implicitly the file or folder open in the editor at the time of the task. The setting wasn't important in my case.
1
On

Just a hunch, but I bet your fileLocation is wrong. Try something like

"fileLocation": "absolute",
1
On

If you, like me, have come here due to the description can't be converted into a problem matcher, here is what I learned:

If your problem matcher says something like "base": "$gcc", then I assume you are using the Microsoft C/C++ plugin. If you are using some other base which is not listed on the official docs webpage (search Tasks in Visual Studio Code), then assume that it is probably supplied by a plugin.

So, this error could mean that you are missing a plugin. In my case I was trying to run this task remotely in WSL/Ubuntu using VS Code's awesome WSL integration. I installed the C/C++ plugin inside WSL and the error was fixed (go to the extension panel, click Install in WSL: <Distro name>).