notskm / vscode-clang-tidy

MIT License
48 stars 26 forks source link

Clang-Tidy can't find my header files #14

Closed mumin16 closed 4 years ago

mumin16 commented 4 years ago

Clang-Tidy can't find my header files

notskm commented 4 years ago

Does this happen if you run clang-tidy manually from the command line?

mumin16 commented 4 years ago

My main includes are in main.cpp. i want to check my submodule:

clang-tidy -checks="cppcoreguidelines-*" mysubmodule.hpp -- -Iinclude/

my command line is wrong?

notskm commented 4 years ago

I need more information.

alessandrostranieri commented 4 years ago

Hi! I thought of chiming in because I am having the same issue(I think). In a simple .h file, the extension says that cstdint is not found. When I run from the command line:

clang-tidy src/game.h -p build/compile_commands.json

I get what I think the correct output: some errors, but not the missing standard include.

In my settings.json I have:

"clang-tidy.buildPath": "build/compile_commands.json"

And in clang-tidy console in VS Code I see:

clang-tidy <path-to>/game.h --export-fixes=- -p="build/compile_commands.json"
[...]
error: 'cstdint' file not found [clang-diagnostic-error]

This last command also works from the command line. The problem with the extension disappears if I use the cmake-tools option to copy the compile_commands.json file to the project root directory. So, in a way, the clang-tidy.buildPath settings seems not to be working for me.

notskm commented 4 years ago

I don't see why the command would behave differently in the terminal vs through Node's execFile or spawn. What OS are you using?

alessandrostranieri commented 4 years ago

Hi, I use Ubuntu 18.04.

I realized that yesterday I omitted probably the most important bit of information:

The extension logging ends with this:

Error while trying to load a compilation database:
Could not auto-detect compilation database from directory ""./build/compile_commands.json""
No compilation database found in /home/astranieri/projects/cg_uttt/"./build/compile_commands.json" or any parent directory

I tried with both absolute and relative arguments. I know absolutely zero about javascript but maybe the arguments are not consumed correctly when you invoke the process? Some stripping of double quotes perhaps.

VeithBuergerhoff commented 4 years ago

I stumbled across the same problem. It appears as if the extension setting "clang-tidy.buildPath" is being ignored. Maybe I have not set the path properly. What does the setting expect, when the file is located at "/build/compile_commands.json"?

knehez commented 4 years ago

The problem is the double quotes. To fix it, please remove the double quotes in line 37 from tidy.ts ->:

args.push(-p="${buildPath}");

majcosta commented 4 years ago

I found this on line 30 of $HOME/.vscode-oss/extensions/notskm.clang-tidy-0.4.1/tidy.js file and changed it to:

args.push(`-p=${buildPath}`);

did not change anything apparently.

UPDATE: replacing ${workspaceFolder} with the full path in my "clang-tidy.buildPath": "${workspaceFolder}/build/compile_commands.json", line, along with @knehez' suggestion fixed it for me