4

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 Answers 3

10

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.
Sign up to request clarification or add additional context in comments.

Comments

2

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

"fileLocation": "absolute",

1 Comment

Thanks, @lucian-wischik, for the answer. This has prompted me to add my own answer, below.
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>).

1 Comment

This will happen if you are using remote development over ssh as well. The C++ extension needs to be installed on the remote.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.