vscode-clangd: Providing a Problem Matcher for Clang

Hi Folks,

how about providing a pre-defined problem matcher for clang’s diagnostic output to the clangd VS Code extension?

I DO NOT use the Microsoft C/C++ extension, but vscode-clangd and CodeLLDB instead. The only thing I’m missing is the predefined gcc problemMatcher since I’m using one for several build tasks. Yes, I can define it in-place, but for each task a new one. And, like every developer, it drives me crazy to have redundant code somewhere.

The solution is to append something like that:

“problemMatchers”: [
{
“name”: “clang”,
“owner”: “cpp”,
“fileLocation”: [
“relative”,
“${workspaceRoot}”
],
“pattern”: {
“regexp”: “^(.):(\d+):(\d+):\s+(warning|error):\s+(.)$”,
“file”: 1,
“line”: 2,
“column”: 3,
“severity”: 4,
“message”: 5
}
}
]

to the contributes block of the vscode-clangd package.json file. Since it’s named “clang” it shouldn’t interfere with some oyher installed extension like the Microsoft’s one.

I’ve patched that into my copy of vscode-clangd’s package.json file and it works like expected.

May be that could be of some good use for someone else out there.

Regards,

Andreas

Having such a matcher somewhere shared makes sense but it’s not obvious it belongs in the clangd extension - neither clangd nor its extension actually run clang.

What do others think?

You’re right, Sam, although - from a certain point of view - clangd IS clang.

Yes, clangd doesn’t run clang. But its users most probably do (either clang or gcc; the problemMatcher in question fits both). And, to my knowledge, their is no obvious extension to provide it.