diff options
| author | Haojian Wu <hokein@google.com> | 2019-07-02 09:16:21 +0000 |
|---|---|---|
| committer | Haojian Wu <hokein@google.com> | 2019-07-02 09:16:21 +0000 |
| commit | 7c251fa069a6f87be237fcd13191d7d0a95da0e4 (patch) | |
| tree | f3af3bd9d5a5409f6d8c360a1a7939af6089d57f /clang-tools-extra/clangd/index/SymbolCollector.cpp | |
| parent | 8d568d044cdc1d4e69f151f475a11dbb4b786ced (diff) | |
| download | bcm5719-llvm-7c251fa069a6f87be237fcd13191d7d0a95da0e4.tar.gz bcm5719-llvm-7c251fa069a6f87be237fcd13191d7d0a95da0e4.zip | |
[clangd] Collect the refs when the main file is header.
Summary:
Previously, we only collect refs of the symbols which are declared in
the preamble and referenced in the main file, it works well when the
main file is .cpp file.
However, when the main file is .h file (when opening a .h file in the
editor), we don't collect refs of the symbol declared in this file, so we miss
these refs in our dynamic index.
A typical scenario:
1. Open Foo.h (which contains class Foo)
2. Open Foo.cpp, call find references for Foo
And we only get refs from Foo.cpp.
Reviewers: ilya-biryukov
Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D63818
llvm-svn: 364893
Diffstat (limited to 'clang-tools-extra/clangd/index/SymbolCollector.cpp')
| -rw-r--r-- | clang-tools-extra/clangd/index/SymbolCollector.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp b/clang-tools-extra/clangd/index/SymbolCollector.cpp index f7b027c3240..8b2d40b3d38 100644 --- a/clang-tools-extra/clangd/index/SymbolCollector.cpp +++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp @@ -314,10 +314,12 @@ bool SymbolCollector::handleDeclOccurence( if (IsOnlyRef && !CollectRef) return true; - // ND is the canonical (i.e. first) declaration. If it's in the main file, - // then no public declaration was visible, so assume it's main-file only. + // ND is the canonical (i.e. first) declaration. If it's in the main file + // (which is not a header), then no public declaration was visible, so assume + // it's main-file only. bool IsMainFileOnly = - SM.isWrittenInMainFile(SM.getExpansionLoc(ND->getBeginLoc())); + SM.isWrittenInMainFile(SM.getExpansionLoc(ND->getBeginLoc())) && + !ASTCtx->getLangOpts().IsHeaderFile; // In C, printf is a redecl of an implicit builtin! So check OrigD instead. if (ASTNode.OrigD->isImplicit() || !shouldCollectSymbol(*ND, *ASTCtx, Opts, IsMainFileOnly)) |

