visual-studio-codevscode-tasksvscode-problem-matcher

Task in Visual Studio Code - problem matches not work


I created a set of tasks with which I want to compile a program written in MAD Pascal (FreePascal compiler for 6502 processor).

Generally everything works, however I have a problem with the "Problem matcher" handling. I do not know why, it does not want to detect errors?

I admit, that I use tasks in VSC for the first time. I have looked through many different tutorials, however everything seems to be OK.

My "Problem Matcher" configuration

"problemMatcher": {
    "source": "Pascal compiler",
    "fileLocation": ["relative", "${workspaceFolder}"],
    "pattern": [
        {
            "regexp": "/^(.+)\\s\\((\\d+),(\\d+)\\):\\s(\\w+):(.+)$",
            "file": 1,
            "line": 2,
            "column": 3,
            "severity": 4,
            "message": 5
        }
    ]
}

I tested the regular expression for correctness (regex101) and it correctly matches the content from the console. Example of console content:

Mad Pascal Compiler version 1.6.6 [2021/06/08] for 6502
Compiling kret.pas
kret.pas (19,5) Error: Syntax error, ';' expected but 'identifier' found

What am I doing wrong? Where is the error in the configuration?

I will be mega grateful - I so much want to see compilation errors in the "Problems" window :)


Solution

  • I have created a .bat file to mock your Mad Pascal Compiler output as follows:
    Content of "compiler_output.bat":

    @echo off
    echo Mad Pascal Compiler version 1.6.6 [2021/06/08] for 6502
    echo Compiling kret.pas
    echo kret.pas (19,5) Error: Syntax error, ';' expected but 'identifier' found
    

    I have created following tasks.json file in .vscode folder:

    {
      "version": "2.0.0",
      "tasks": [
        {
          "label": "Mockup compile by Pascal compiler",
          "type": "shell",
          "command": "${workspaceFolder}/compiler_output.bat",
          "args": [],
          "presentation": {
            "echo": true,
            "reveal": "always",
            "focus": false,
            "panel": "shared",
            "showReuseMessage": false,
            "clear": true
          },
          "problemMatcher": {
            "owner": "pascal",
            "fileLocation": [
              "relative",
              "${workspaceFolder}"
            ],
            "pattern": {
              "regexp": "^(.+)\\s\\((\\d+|\\d+,\\d+|\\d+,\\d+,\\d+,\\d+)\\)\\s(\\w+):(.+)$",
              "file": 1,
              "location": 2,
              "severity": 3,
              "message": 4
            }
          },
          "group": {
            "kind": "build",
            "isDefault": true
          }
        }
      ]
    }
    

    My folder tree looks as follows:
    enter image description here

    After running this task I got:
    enter image description here

    Problems tab looks as expected:
    enter image description here