microsoft / microsoft/vscode-cmake-tools

Support for additional problem severities/translations

Open
#2,333 2 comments 1 reaction 0 assignees View on GitHub
enhancement Feature: build
Dominant language
TypeScript
Stars
1.7k
Forks
546
Avg merge
2d 16h
Merged PRs (30d)
32

Description

## Brief Issue Summary

When invoking cppcheck via CMake (https://cmake.org/cmake/help/latest/prop_tgt/LANG_CPPCHECK.html) while building the output is unfortunately not parsed into the Problems Tab; albeit the output is formated in the same style as compiler warnings or clang-tidy output (which both generate entries in the problem tab).

I assume the parsing and problem generation is part of CMake-Tools - if not, please give me a pointer, where this happens and whom to address this problem to.

If this is already a known problem: Is there a workaround?

## Minimal example

### System

Tested with Ubuntu 20.04, gcc 9.3.0, CMake 3.16.3 + Ninja, VS Code 1.63.2, CMakeTools 1.9.2

### main.cpp

```cpp
#include
#include

int main(int argc, char **argv) // Will trigger compiler warning (unused parameter)
{
// Triggers clang-tidy bugprone-infinite-loop
std::string s{"Foo"};
std::cout << "Size of " << s << " is " << sizeof(s);

// Trigger cppcheck style [knownConditionTrueFalse]
bool const known = true;
if (known)
{
std::cout << "Bar" << std ::endl;
}

return EXIT_SUCCESS;
}
```

### CMakeLists.txt

```cmake
cmake_minimum_required(VERSION 3.16)

project(vscode-problem-parser-test
LANGUAGES CXX)

add_executable(vscode-ppt main.cpp)

target_compile_features(vscode-ppt
PRIVATE
cxx_std_17
)

target_compile_options(vscode-ppt
PRIVATE
-Wall -Wextra -Wpedantic -Wshadow
)

find_program( CLANG_TIDY_EXE
NAMES "clang-tidy"
DOC "Path to clang-tidy executable"
)
if( NOT CLANG_TIDY_EXE OR ( CLANG_TIDY_EXE STREQUAL "CLANG_TIDY_EXE-NOTFOUND" ))
message( WARNING "clang-tidy not found")
else()
set( CLANG_TIDY_COMMANDLINE "${CLANG_TIDY_EXE}" "--checks=-*,bugprone-*")
set_target_properties(vscode-ppt
PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMANDLINE}"
)
endif()

find_program( CPPCHECK_EXE
NAMES "cppcheck"
DOC "Path to cppcheck executable"
)
if( NOT CPPCHECK_EXE OR ( CPPCHECK_EXE STREQUAL "CPPCHECK_EXE-NOTFOUND" ))
message( WARNING "cppcheck not found")
else()
get_target_property(TGT_CXX_STANDARD vscode-ppt CXX_STANDARD)
set( CPPCHECK_COMMAND "${CPPCHECK_EXE}" "--inline-suppr" "--enable=warning,style" "--std=c++${TGT_CXX_STANDARD}")
set_target_properties( vscode-ppt
PROPERTIES CXX_CPPCHECK "${CPPCHECK_COMMAND}"
)
endif()
```
### CMake/Build output

```
[build] Starting build
[proc] Executing command: /usr/bin/cmake --build /home/rombach/src/sandbox/build --config Debug --target all -j 26 --
[build] [1/2 50% :: 0.713] Building CXX object problem-parser-test/CMakeFiles/vscode-ppt.dir/main.cpp.o
[build] /home/rombach/src/sandbox/build/../problem-parser-test/main.cpp:8:47: warning: sizeof() doesn't return the size of the container; did you mean .size()? [bugprone-sizeof-container]
[build] std::cout << "Size of " << s << " is " << sizeof(s);
[build] ^
[build] Checking ../problem-parser-test/main.cpp ...
[build] ../problem-parser-test/main.cpp:12:9: style: Condition 'known' is always true [knownConditionTrueFalse]
[build] if (known)
[build] ^
[build] ../problem-parser-test/main.cpp: In function ‘int main(int, char**)’:
[build] ../problem-parser-test/main.cpp:4:14: warning: unused parameter ‘argc’ [-Wunused-parameter]
[build] 4 | int main(int argc, char **argv) // Will trigger compiler warning (unused parameter)
[build] | ~~~~^~~~
[build] ../problem-parser-test/main.cpp:4:27: warning: unused parameter ‘argv’ [-Wunused-parameter]
[build] 4 | int main(int argc, char **argv) // Will trigger compiler warning (unused parameter)
[build] | ~~~~~~~^~~~
[build] [2/2 100% :: 0.786] Linking CXX executable problem-parser-test/vscode-ppt
[build] Build finished with exit code 0
```

### Problems tab

![grafik](https://user-images.githubusercontent.com/74900023/150314015-9179a10e-e7f1-46cb-ab5f-77c57b6ecf62.png)

Obviously the [knownConditionTrueFalse] does not show up, which is very unfortunate.

Contributor guide

Open the contributing guide

Research direction

The issue names no repository files or tests. Start by tracing how CMake Tools parses compiler and clang-tidy build output into the VS Code Problems tab, then compare that path with the shown cppcheck lines, including the style severity and bracketed message ID. Done means the knownConditionTrueFalse diagnostic and comparable cppcheck severities appear in Problems with the expected location and message.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp, typescript, vscode
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.