Caphyon / clang-power-tools

Bringing clang-tidy magic to Visual Studio C++ developers.
http://www.clangpowertools.com
Apache License 2.0
472 stars 57 forks source link

Detection of .clang-tidy file not working #1342

Open johanneskopf opened 3 months ago

johanneskopf commented 3 months ago

Steps to reproduce

  1. Remove any .clang-tidy files from the project
  2. In the Clang Power Options Settings - Tidy, set the option Use checks from = PredefinedChecks, enable just one or two checks, and set Detect .clang-tidy file = true
  3. Right click project, Clang Power Tools - Tidy, wait till it finishes.
  4. In the Clang Power Options Settings - Tidy, the option is automatically changed from Use checks from = PredefinedChecks to Use checks from = TidyFile. Expected behavior: As there is no ".clang-tidy" file in my project, it should stay at Use checks from = PredefinedChecks according to the tooltip of that option.
  5. When I now use right clicking on project - Clang Power Tools - Tidy, it runs tidy with many checks enabled which I never specified (some defaults maybe?)
  6. As soon as I used the Tidy file config - Export button to export the .clang-tidy file to my project root, it used these options when right clicking on project - Clang Power Tools - Tidy.

Versions of the tools used:

mariru27 commented 3 months ago

Hi @johanneskopf,

I apologize for a late reply

It is not enough to remove .clang-tidy from your project

.clang-tidy file is detected by clang-tidy.exe (not by us) based on its predefined search paths. When we run clang-tidy.exe without specifying a configuration file explicitly (Detect .clang-tidy file = true, Use checks from = TidyFile), it will search for .clang-tidy file in the following locations:

Current directory: clang-tidy.exe will first look for .clang-tidy in the directory from which it is being executed. Parent directories: If .clang-tidy is not found in the current directory, clang-tidy.exe will search in parent directories recursively until it finds a .clang-tidy file or reaches the root directory.

If you have some custom checks, you can export .clang-tidy file (from Settings -> tidy) and use it in your project

Let me know if this helps

Kind regards, Marina

johanneskopf commented 3 months ago

Hi @mariru27 ,

Thanks for the reply. And no worries for the answer time, that is still quick enough! :)

That explains it to some degree. I already did the export of my custom checks (see step 6. of my initial post above) and that runs fine now, but I still want to figure out which .clang-tidy file it uses when this manually exported .clang-tidy file is not given. I don't have any .clang-tidy file in a parent folder of my project. As a next step, I try to figure out where I find the clang-tidy executable on Windows (EDIT: found it here: "%APPDATA%\ClangPowerTools\LLVM\LLVM17.0.1\bin" (adapt path depending on downloaded LLVM version)) and then add it to path environment variable, before I can execute it in a console window, and afterwards I'll search if there's a way to display the used .clang-tidy file.

I have an idea here though: Is it possible to display the path of the found .clang-tidy file in the clang power tools? That would be super helpful. Even better would be to display it as a hyperlink that opens the file explorer at the corresponding folder and highlights the used .clang-tidy file.

Kind regards, Johannes

mariru27 commented 3 months ago

We know path to .clang-tidy file, just when you use PedefinedChecks (unchecked detect .clang-tidy file), because we create .clang-tidy file (with needed checks) in %temp% and specify .clang-tidy temp path when passing to our script.

It's the single case when we know exactly the path to .clang-tidy, but as I understand, you want to know the path in different scenarios, so unfortunately I don't think that I can help you here

If you want to display the .clang-tidy path from temp, just let me know.

Have a nice day, Marina

johanneskopf commented 2 months ago

I see, thanks for the explanation!

To summarize, my problem is that clang-tidy uses a .clang-tidy file that I could not find on disk, but clang-tidy obviously did. As a result, I created an issue at the LLVM project that hopefully leads to a solution: https://github.com/llvm/llvm-project/issues/88242

I am interested in a general solution to output all .clang-tidy files that are used. But I acknowledge that this can only be solved on the LLVM side. So let's wait if they can help us out here.

Have a great day, Johannes

johanneskopf commented 2 months ago

Got a solution in https://github.com/llvm/llvm-project/issues/88242

So by using the --explain-config flag, I was able to figure out that in the case where it can't find a .clang-tidy file, it uses the clang-tidy options specified in the binary. This was the piece of information I was missing.

As a result, is it possible that Detect .clang-tidy file also finds and uses those binary-checks? If so, the option Detect .clang-tidy file potentially always finds something (in my case at least when there are checks in the binary) and thus the question is whether there is any benefit of having this option. I would suggest to always use the Predefined Checks when Use checks from: PredefinedChecks is assigned, and always detect the .clang-tidy file when Use checks from: TidyFile is assigned. What do you think @mariru27 ? Am I missing something here?

Also, finding this flag means that it is actually possible to retrieve the paths to all the clang-tidy files involved. I believe that adding this information to the UI would definitely be beneficial.