microsoft / microsoft/vscode-cpptools

C_Cpp.codeAnalysis.clangTidy.useBuildPath should work with CMake configuration

Open
#9,565 3 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement Feature: Code Analysis Feature: Configuration Language Service
Dominant language
TypeScript
Stars
6.2k
Forks
1.7k
Avg merge
14h 46m
Merged PRs (30d)
61

Description

I use ms-vscode.cmake-tools and ms-vscode.cpptools and rely on the default behaviour as much as possible.
When running Code analysis on active file clang-tidy crashes. I can also call clang-tidy (even official clang-tidy-14) with all the arguments that the cpptools would pass and get a crash. It really looks like a clang-tidy bug. I tried to work around by passing compile_commands.json to clang-tidy.

Not sure how C_Cpp.codeAnalysis.clangTidy.useBuildPath is supposed to work.
Just having
"C_Cpp.codeAnalysis.clangTidy.useBuildPath": true
does not pass the -p option, it still passes build arguments after --. It seems I also have to set "C_Cpp.default.compileCommands".

"C_Cpp.default.compileCommands": "${command:cmake.buildDirectory}/compile_commands.json"
also does not work. It looks like C_Cpp.default.compileCommands does not support any substitutions, even ${workspaceFolder} does not work.

The only way I could make it work was something like

"cmake.copyCompileCommands": "/workspace/build/compile_commands.json",
"C_Cpp.default.compileCommands": "/workspace/build/compile_commands.json",
"C_Cpp.codeAnalysis.clangTidy.useBuildPath": true

With the first cmake.copyCompileCommands I copy the current configuration (I have multiple) to a stable location. This can be used by C_Cpp.default.compileCommands and the -p=/workspace/build/ is passed to clang-tidy.

Substitutions should be supported by C_Cpp.default.compileCommands.
Only setting C_Cpp.codeAnalysis.clangTidy.useBuildPath to true should be enough if ms-vscode.cmake-tools is the configuration provider and it has generated a compile_commands.json

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read the handling of C_Cpp.codeAnalysis.clangTidy.useBuildPath and C_Cpp.default.compileCommands, then reproduce the issue with the CMake configuration provider and its generated compile_commands.json. Check how cmake.copyCompileCommands and ${command:cmake.buildDirectory} are handled, and verify that useBuildPath works without requiring a fixed copied path.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp, vscode
Domain
build-system, developer-experience, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.