Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VSCode Powershell问题匹配器_Powershell_Visual Studio Code_Vscode Problem Matcher - Fatal编程技术网

VSCode Powershell问题匹配器

VSCode Powershell问题匹配器,powershell,visual-studio-code,vscode-problem-matcher,Powershell,Visual Studio Code,Vscode Problem Matcher,我在VSCode中有一个Powershell任务,但不知道如何使problemMatch工作 { "version": "0.1.0", "command": "PowerShell.exe", "isShellCommand": true, "suppressTaskName": true, "args": [ "& '${file}'" ], "tasks": [ { "taskName"

我在VSCode中有一个Powershell任务,但不知道如何使
problemMatch
工作

{
    "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
            }
        }]
    }]
}
正则表达式的目标如下:

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

行:组21

列:第3组11


消息:第7组意外标记“!”在表达式或语句中。

我不确定问题匹配器的正则表达式是否能够处理换行。默认情况下,问题匹配器是单行的,但您可以创建多行匹配器,如下所述:

实际上,您提供了多个正则表达式。对于您的场景,您可以尝试以下操作:

"problemMatcher": {
    "owner": "custom",
    "fileLocation": ["absolute"],
    "pattern": [{
        "regexp": "At (.*\\.ps1):(\\d*) char:(\\d*)(.*)",
        "file": 1,
        "line": 2,
        "column": 3                 
    }, {
        "regexp": "\\+.*"
    },{
        "regexp": "\\+.*"
    },{
        "regexp": "(.+)",
        "message": 1
    }]
}
第一个模式匹配第一行中的文件、行和列。第二个和第三个模式匹配下两行输出,但不捕获任何值。最后一行匹配下一个输出行,并将其全部捕获为消息


希望有帮助

我很想帮助你,但我不明白问题是什么?(也许这是因为我没有使用VSCode)问题是通过REGEX在外部REGEX测试工具中进行错误检测,但是在VSCode,错误下划线/标记不起作用(红色下划线/错误输出),如果中间的行数(不关心的行)可以是可变的呢?我正在处理Pester输出,行号和文件路径信息出现在错误输出的下一行。不幸的是,第一行(错误指示符)和此行之间的行数是可变的。对于Pester,我编写了一个自定义执行脚本,当它让我重新启动并再次运行时,它重新格式化了输出:-)