如何使vscode问题匹配器匹配IAR ARM编译器错误?

时间:2019-07-05 02:43:33

标签: visual-studio-code vscode-tasks

我正在尝试匹配IAR ARM编译器为VSCode ProblemMatcher生成的这种格式的错误...

"d:\test\helloWorld.c",646  Warning[Pe223]:
function "printf" declared implicitly

使用regex101.com,我可以将第一行消息与此regex匹配...

^"(.*)",(\d+)\s+((Warning|Error)\[Pe\d+\]):$

A,当以正确的转义斜杠放入我的task.json文件时。 vscode在task.json中提示该错误。 error in task.json

"problemMatcher": {
   "owner": "cpp",
   "fileLocation": "absolute",
   "pattern": [
      // The regular expression for IAR ARM compiler. Example to match: 
      //   "d:\test\helloWorld.c",646  Warning[Pe223]:
      //   function "printf" declared implicitly
      {
         "regexp": "^"(.*)",(\\d+)\\s+((Warning|Error)\\[Pe\\d+\\]):$",
         // The first match group matches the file name which is relative.
         "file"    : 1,
         // The second match group matches the line on which the problem occurred.
         "location": 2,
         // The third match group matches the message
         "message" : 3,
         // The fourth match group matches the problem's severity. Can
         // be ignored. Then all problems are captured as errors.
         "severity": 4
      },
      {
         // The next line matches the message.
         "regexp": "^([^\\s].*)$",
         "message": 1               
      }
   ]
}

然后,我删除了“”,它变成了

^(.*),(\\d+)\\s+((Warning|Error)\\[Pe\\d+\\]):$

最后,在运行将在VSCode终端中生成这些错误的任务后,我在“问题”选项卡中收到输出。警告消息和行号正确。但是文件不匹配,无法跳转到文件。

1 个答案:

答案 0 :(得分:0)

好的,我从https://docs.microsoft.com/en-us/visualstudio/ide/using-regular-expressions-in-visual-studio找到了答案

\"匹配双引号

所以正确的正则表达式是

"regexp": "^\"(.+?)\",(\\d+)\\s+((Warning|Error)\\[Pe\\d+\\]):$",