I have a Visual Studio Code C project based on CMake, compiled using gcc. I've created a custom task for building the project, and have specified $gcc
for its problemMatcher
property.
However, when I build and there are compile errors, it never displays all the errors and warning messages. Very often it only displays the first one. Sometimes it displays two or three. If there is a warning message that comes up in the list before errors, it will consistently only display that one warning and not show any of the subsequent errors.
How do I fix this? I've already tried updating VS Code and the CMake tools and C/C++ extensions to the latest version, which as of writing this question are: VSCode 1.92.1, C++: v1.21.6, CMake Tools: 1.18.44
Here is my tasks.json
:
{
"version": "2.0.0",
"tasks": [
{
"type": "cmake",
"label": "CMake: build application",
"command": "build",
"presentation": {
"echo": false,
"reveal": "always",
"focus": false,
"close": false,
"panel": "dedicated",
"revealProblems": "onProblem",
"showReuseMessage": false,
"clear": true
},
"targets": [
"all"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "CMake build task",
"problemMatcher": ["$gcc"]
}
]
}
Edit: This problem appears to be intermittent. If it occurs, I can restart VS Code and it goes away, at least for a time.
Edit 2: There's been an update to CMake Tools since I wrote this. I've updated and we'll see it makes any difference.
Edit 3: I've found a way to consistently trigger the bug. Here's what I did:
I stopped there, but presumably it would get to the point that it would only show one error at a time.
The issue about which you are talking is likely related to how the $gcc problemsMatcher processes the output. As the problem is dis-continuous, this may also depend on how VS Code buffers the output or a temporary glitch.
To get rid of this, you can modify the problemMatcher pattern because the default $gcc may not capture all messages, so it is better to try specifying a custom problem matcher to otherwise ensure that it is correctly parsing all lines.
In your tasks.json, update the problemMatcher as follows:
"problemMatcher": [
{
"owner": "cpp",
"fileLocation": "absolute",
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+): (error|warning): (.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
]
Your complete code should look something like:
{
"version": "2.0.0",
"tasks": [
{
"type": "cmake",
"label": "CMake: build application",
"command": "build",
"presentation": {
"echo": false,
"reveal": "always",
"focus": false,
"close": false,
"panel": "shared",
"revealProblems": "onProblem",
"showReuseMessage": false,
"clear": true
},
"targets": [
"all"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "CMake build task",
"problemMatcher": [
{
"owner": "cpp",
"fileLocation": "absolute",
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+): (error|warning): (.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
]
}
]
}
In order to avoid clearing or resetting the terminal, also to improve the visibility of all messages, set "panel" : "shared" instead of "panel" : "dedicated".
Check all these and then I hope your issues will be resolved and in case of further any clarification let me know.