clang-tidy in the editor

I have integrated clang-tidy into a text-editor project, re-running clang-tidy as the user types. It works, but it can be slow to reparse the entire file and #includes after every edit.

I've also experimented using libclang's precompiled preambles and clang_reparseTranslationUnit(). This works great for reparse performance, but I'm having trouble figuring out how to incorporate the clang-tidy checkers.

I would appreciate any advice on speeding up clang-tidy so that repeatedly reparsing a file doesn't need to reparse all the #included headers.

Thanks!

Have you tried using the -header-filter option?

Exposing clang-tidy via libclang (or similar) to be able to integrate it into editors is on our list of things to do in the first months of 2016.

Exposing clang-tidy via libclang (or similar) to be able to integrate it
into editors is on our list of things to do in the first months of 2016.

Glad to hear that there's some emphasis on making clang-tidy more useful in
the broader scope.

Looking forward to integrating it in KDevelop (via libclang)!

Cheers,
Kevin

Glad to hear it.

I have managed to integrate clang-tidy as a plugin in libclang. I haven't exposed the entire command-line options, but it is working for my purposes.

How are you planning on integrating the two?

Thanks,
Mark

Manuel Klimek wrote:

Glad to hear it.

I have managed to integrate clang-tidy as a plugin in libclang. I
haven’t exposed the entire command-line options, but it is working for
my purposes.

How are you planning on integrating the two?

  1. expose clang-tidy via libclang (or similar); plugin sounds like a good idea, but we also will want a stable (for the future) interface for editors to rely on
  2. profit :slight_smile:

Glad to hear it.

I have managed to integrate clang-tidy as a plugin in libclang. I
haven't exposed the entire command-line options, but it is working for
my purposes.

That's awesome!

Can you share the extra plumbing needed in order to load clang-tidy as a
plugin?

For loading the Clang plugin in libclang I presume you also needed a similar
patch like ⚙ D15729 Load compiler plugins in ASTUnit, too, right? Care to help out reviewing +
assuring this makes it into Clang proper?

Thanks,
Kevin

Kevin Funk wrote:

Can you share the extra plumbing needed in order to load clang-tidy as a
plugin?

For loading the Clang plugin in libclang I presume you also needed a similar
patch like ⚙ D15729 Load compiler plugins in ASTUnit, too, right? Care to help out reviewing +
assuring this makes it into Clang proper?

Since the plugin mechanism doesn't work with windows .dlls, I had to statically link the plugin, so that patch wasn't necessary for me.

I'm not ready to share a patch, as I'm still working out the kinks of the plugin itself. There were lifetime issues regarding the ClangTidyContext, so I had to change the ClangTidyASTConsumer to own the Context since the PluginASTAction is deleted right after creating the consumer. These changes break the clang-tidy tool unfortunately.