【问题标题】:vscode problemMatcher doesn't not recognize Tasking compiler warningsvscode problemMatcher 无法识别任务编译器警告
【发布时间】:2020-04-19 18:10:23
【问题描述】:

以下Tasks.json 问题匹配器正则表达式应匹配以下典型警告。但事实并非如此。 ctc W505:[“somedirectory/somefile.c”350/18] 隐式声明等等等等

有什么问题?我验证了内置解析器匹配 gcc 输出错误和警告。

谢谢,

Satish K

"tasks": [
        {
            "label": "build.bat",
            "type": "shell",
            "command": "build.bat",
            "problemMatcher": {
                "owner": "cpptools",
                "fileLocation": [
                    "relative",
                    "${env:PWD}"
                ],
                "pattern": {
                    "regexp": "^ctc W(\\d+): \\[\\\"(.*)\\\" (\\d+)\\\/(\\d+)\\] (.*)$",
                    "file": 2,
                    "line": 3,
                    "column": 4,
                    "message": 5
                }
            },
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]

【问题讨论】:

    标签: visual-studio-code vscode-problem-matcher


    【解决方案1】:

    你在表达式中多加一个\,你只需要转义",不需要转义/

    "tasks": [
            {
                "label": "build.bat",
                "type": "shell",
                "command": "build.bat",
                "problemMatcher": {
                    "owner": "cpptools",
                    "fileLocation": [
                        "relative",
                        "${env:PWD}"
                    ],
                    "pattern": {
                        "regexp": "^ctc W(\\d+): \\[\"(.*)\" (\\d+)/(\\d+)\\] (.*)$",
                        "file": 2,
                        "line": 3,
                        "column": 4,
                        "message": 5
                    }
                },
                "group": {
                    "kind": "build",
                    "isDefault": true
                }
            }
        ]
    


    编辑

    这适用于 regex101(风格 Javascript)

    ^ctc W(\d+): \["(.*)" (\d+)\/(\d+)\] (.*)$
    

    要将其转换为 JSON 字符串,请转义 \" 并且正则表达式也希望您转义 / 但仅当您在文字 Javascript 中使用正则表达式(如 /\d+/g)时才需要这样做,但我们不需要在 VSC 中不会这样做,但不会有任何影响。

    导致:

    "^ctc W(\\d+): \\[\"(.*)\" (\\d+)\\/(\\d+)\\] (.*)$"
    

    【讨论】:

    • 那也没用。也在 regex101.com 中验证了它
    • @satish 我在 regex101 中尝试过,它抱怨非转义 /
    • 为了在没有 ctc 的情况下进行测试,我只是在 build.bat @echo ctc W505 中回显了以下内容: ["somedirectory/somefile.c" 350/18] 隐式声明等等等等 Vscode 默认识别文件路径。但它无法获取行号和列号。
    • @satish 我用更新的正则表达式对其进行了测试,它可以正常工作,获取行和列
    • 它适用于正则表达式。但是 vscode 无法识别行号和列号。要重现该问题,您可以执行 build.bat,其中包含 echo 语句。
    【解决方案2】:

    我无法让它工作。但是我通过 json escpare 运行了工作 regex101。它做了更多的斜线转义,结果是:

    "regexp": "^ctc W(\\d+): \\[\\\"(.*)\\\" (\\d+)\\/(\\d+)\\] (.*)$",
    

    【讨论】:

      猜你喜欢
      • 2020-11-25
      • 2014-05-11
      • 2010-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-12
      • 1970-01-01
      • 2019-03-11
      相关资源
      最近更新 更多