3

I have a task for Powershell in VSCode, but can't figure out how to make the problemMatch work

{
    "version": "0.1.0",
    "command": "PowerShell.exe",
    "isShellCommand": true,
    "suppressTaskName": true,
    "args": [
        "& '${file}'"
    ],
    "tasks": [
    {
        "taskName": "Build",
        "isBuildCommand": true,
        "showOutput": "always",
        "fileLocation": ["absolute"],
        "problemMatcher": [
        {
            "pattern": {
            "regexp": "At (.*\\.ps1):(\\d*) char:(\\d*)(.*)\\n\\+(.*)\\n\\+(.*)\\n(.*)",
            "file": 1,
            "line": 2,
            "column": 3,
            "message": 7
            }
        }]
    }]
}

Regex targets as so :

At C:\tmp\C1-INT to C1-QA\a.ps1:1 char:11
+ "asdasds" !
+           ~
Unexpected token '!' in expression or statement.

file: Group 1 "C:\tmp\C1-INT to C1-QA\a.ps1"

line: Group 2 "1"

column: Group 3 "11"

message: Group 7 Unexpected token '!' in expression or statement.

Simson
  • 3,373
  • 2
  • 24
  • 38
smichaud
  • 326
  • 2
  • 12
  • I would love to help you but I don't understand what the question is / what is the problem? (Maybe this is because I've not used VSCode) – David Abrahamsson Jul 01 '15 at 06:00
  • Problem is the error detection via the regex works in external regex testing tool, but in VSCode the error underlining/marking does not work (red underlining / error outpout) – smichaud Jul 02 '15 at 10:19

1 Answers1

4

I'm not sure that the regex for a problem matcher can handle line breaks. By default problem matchers are single line, but you can create multi-line matchers as described here: https://code.visualstudio.com/Docs/editor/tasks#_defining-a-multiline-problem-matcher

Essentially you provide multiple regex's. For your scenario you could try something like the following:

"problemMatcher": {
    "owner": "custom",
    "fileLocation": ["absolute"],
    "pattern": [{
        "regexp": "At (.*\\.ps1):(\\d*) char:(\\d*)(.*)",
        "file": 1,
        "line": 2,
        "column": 3                 
    }, {
        "regexp": "\\+.*"
    },{
        "regexp": "\\+.*"
    },{
        "regexp": "(.+)",
        "message": 1
    }]
}

The first pattern matches the file, line and column in the first line. The second and third patterns match the next two lines of output but don't capture any values. The final line matches the next output line and captures it all as the message.

Hope that helps!

jpierson
  • 16,435
  • 14
  • 105
  • 149
Stuart Leeks
  • 415
  • 3
  • 7
  • 1
    What if the number of lines in the middle (lines you don't care about) can be variable? I'm dealing with Pester output and the line number and file path info appears on the next to last line of error output. Unfortunately the number of lines between the first (error indicator) line and this line is variable. – Keith Hill Feb 13 '16 at 04:30
  • For Pester I wrote a custom execution script that reformatted the output as it got me back up and running again :-) https://github.com/stuartleeks/posh-HumpCompletion/blob/master/RunPester.ps1#L26 – Stuart Leeks Oct 27 '16 at 15:59