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
}
]
}
}]
}
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:
"command": "/full/path/to/executable"
not just "executable name"
."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.