Try putting the following in your workspace settings.json file:
"C_Cpp.codeAnalysis.clangTidy.useBuildPath": true
The setting's description:
If true
and compileCommands
is set, the -p=<build-path>
argument is passed to clang-tidy instead of build arguments being passed after --
. This may not work if environment variables aren't set so that system includes can be found.
From the help message for clang-tidy's -p
flag:
-p <build-path> is used to read a compile command database.
For example, it can be a CMake build directory in which a file named
compile_commands.json exists (use -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
CMake option to get this output). When no build path is specified,
a search for compile_commands.json will be attempted through all
parent paths of the first input file . See:
https://clang.llvm.org/docs/HowToSetupToolingForLLVM.html for an
example of setting up Clang Tooling on a source tree.
Somewhat related GitHub issue ticket in the vscode-cpptools repo: C_Cpp.codeAnalysis.clangTidy.useBuildPath should not add "compile_commands.json" to the -p argument #9273
I'm not sure if that will just work for you. If it doesn't try specifying the -p
flag and build path manually (the path to the directory containing the compile commands JSON file) using the "C_Cpp.codeAnalysis.clangTidy.args"
VS Code setting.