notskm / vscode-clang-tidy

MIT License
49 stars 25 forks source link

Extension not Working #37

Closed SandroWissmann closed 4 years ago

SandroWissmann commented 4 years ago

So I installed the Extension under Ubuntu but nothing is happening.

I would appreciate instructions on how to set it up.

notskm commented 4 years ago

Make sure you have clang-tidy installed. The extension looks for clang-tidy on the PATH by default. You can use the clang-tidy.executable setting if clang-tidy is not on your PATH.

If you can't get it to work, open up the output pane in VSCode, select "Clang-Tidy" in the dropdown menu, and paste the output here.

SandroWissmann commented 4 years ago

I installed clang-tidy and could run it in my ubuntu system from command line. So that means It should work already automatically?

And if not I have to modify the settings.json file and add the executable there?

edit:

I specified the path like this:

Screenshot_20200603_060804

However nothing happens. Also in the output Window I cannot select tidy;

Screenshot_20200603_060915

notskm notifications@github.com schrieb am Di., 2. Juni 2020, 20:40:

Make sure you have clang-tidy installed. The extension looks for clang-tidy on the PATH by default. You can use the clang-tidy.executable setting if clang-tidy is not on your PATH.

If you can't get it to work, open up the output pane in VSCode, select "Clang-Tidy" in the dropdown menu, and paste the output here.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/notskm/vscode-clang-tidy/issues/37#issuecomment-637735118, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKD3YSE6MOHOZ5MWKZDH3HLRUVBRTANCNFSM4NQ2NKCA .

notskm commented 4 years ago

Do you have a .clang-tidy file in the root of your project? If not, are you setting clang-tidy.checks?

I cannot reproduce this issue.

SandroWissmann commented 4 years ago

how do i get this .clang-tidy file? Can I generate it?

Can you give an example what to write in the settings.json?

notskm commented 4 years ago

Here's clang-tidy's docs. https://clang.llvm.org/extra/clang-tidy/ This extension simply runs clang-tidy for you. You need to learn how to use clang-tidy first.

.clang-tidy is the config file for clang-tidy. It's where you specify what checks you want enabled.

SandroWissmann commented 4 years ago

I checked the docs but I could not find out how to create the tidy file.

If I have the file and specified the path the extension should work automatically?

notskm notifications@github.com schrieb am Do., 4. Juni 2020, 20:47:

Here's clang-tidy's docs. https://clang.llvm.org/extra/clang-tidy/ This extension simply runs clang-tidy for you. You need to learn how to use clang-tidy first.

.clang-tidy is the config file for clang-tidy. It's where you specify what checks you want enabled.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/notskm/vscode-clang-tidy/issues/37#issuecomment-639048495, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKD3YSHHP4WRJ3ZRYGI2DW3RU7T47ANCNFSM4NQ2NKCA .

notskm commented 4 years ago

Here's an example .clang-tidy file from one of my projects. See clang-tidy's docs if you need help with it. https://github.com/notskm/cpp-application-template/blob/master/.clang-tidy

You need to learn how to use clang-tidy from the command line if you want to use this extension.

This extension runs clang-tidy for you whenever you save. You can also run it manually from the command palette. You either need to set clang-tidy.checks to the list of checks you want enabled, or you need to have a .clang-tidy file with the list of checks you want enabled in the root of your project. See README.md.

SandroWissmann commented 4 years ago

Ok. I added the .clang-tidy file to the project.

And I added the path of clang-tidy to settings.json like this:

"clang-tidy.executable": "/usr/bin/clang-tidy",

But I still don't see anything happen when I save a file. Am I still missing something?

notskm commented 4 years ago

I have no idea why it's not working for you. It should be. The output window still doesn't have a clang-tidy section?

SandroWissmann commented 4 years ago

It looks like it is working now in the Problesm Clang Diagnostics error show up.

However one Issue I have. It looks like clang-tidy does not find additionally specified headers and marks them as errors.

In my case I get a complain that SDL.h is not found like this:

'SDL.h' file not found [clang-diagnostic-error]

So do I have to additonally include the path to SDL to clang-tidy?

I already specified it for intellisense in c_cpp_configurations.json like this:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/include/SDL2/**",
                "/mnt/Programmierung/Cpp/Udacity/Project/Bricks/thirdparty/googletest/googletest/include/**"
            ],
            "browse": {
                "limitSymbolsToIncludedHeaders": false,
                "path": [
                    "${workspaceFolder}/**",
                    "/usr/include/SDL2/**",
                    "/mnt/Programmierung/Cpp/Udacity/Project/Bricks/thirdparty/googletest/googletest/include/**"
                ]
            },
            "defines": [],
            "compilerPath": "/usr/bin/g++",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}
notskm commented 4 years ago

That sounds like you don't have a compile_commands.json file in your project. If you're using CMake, it can generate one for you by specifying -DCMAKE_EXPORT_COMPILE_COMMANDS=ON on the command line. I think the CMake Tools extension also has a setting for that. Other build tools may also provide some means to generate compile_commands.json, but I'm not sure.

Many tools rely on compile_commands.json being present. Clang-Tidy should find it automatically if it's in the root of your project. Otherwise, you can use this extension's clang-tidy.buildPath setting to tell clang-tidy where to look.

SandroWissmann commented 4 years ago

Thanks a lot now it is working well.

I generated the compile_commands.json with CMake from command line like you suggested.

Now tidy works well.

Thank you very much for your patience.

notskm commented 4 years ago

No problem. I'm glad it's working.

SjoerdNijboer commented 4 years ago

This is easy to fix but gives a bad first impression when not discovered. Could you add this to a setup page for some generic project setups like cmake based projects?