[clangd] Recognize "don't include me directly" pattern, and suppress include insertion.
authorSam McCall <sam.mccall@gmail.com>
Wed, 17 Apr 2019 18:33:07 +0000 (18:33 +0000)
committerSam McCall <sam.mccall@gmail.com>
Wed, 17 Apr 2019 18:33:07 +0000 (18:33 +0000)
commita96efb654e91065697861bdb4541a793b25ecc6b
tree7a02cbb0e4aacf3004211a07084a0bc5a7ba1490
parent8ecb7bbe2babff32157b37ff6f4dda4115148fc5
[clangd] Recognize "don't include me directly" pattern, and suppress include insertion.

Summary:
Typically used with umbrella headers, e.g. GTK:

 #if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
 #error "Only <gtk/gtk.h> can be included directly."
 #endif

Heuristic is fairly conservative, a quick code search over github showed
a fair number of hits and few/no false positives. (Not all were umbrella
headers, but I'd be happy avoiding include insertion for all of them).

We may want to relax the heuristic later to catch more cases.

Reviewers: ioeric

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D60815

llvm-svn: 358605
clang-tools-extra/clangd/index/SymbolCollector.cpp
clang-tools-extra/clangd/index/SymbolCollector.h
clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp