3

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
                }
            ]
        }
    }]
}
Simson
  • 3,373
  • 2
  • 24
  • 38
JGC
  • 505
  • 1
  • 4
  • 12

3 Answers3

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:

  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.
JGC
  • 505
  • 1
  • 4
  • 12
2

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>).

Wayne Uroda
  • 5,025
  • 4
  • 30
  • 35
  • This will happen if you are using remote development over ssh as well. The C++ extension needs to be installed on the remote. – TTimo Nov 10 '22 at 15:30
0

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

"fileLocation": "absolute",
Lucian Wischik
  • 2,160
  • 1
  • 20
  • 25
  • Thanks, @lucian-wischik, for the answer. This has prompted me to add my own answer, below. – JGC Jul 19 '20 at 21:18