diff options
| author | Utkarsh Saxena <usx@google.com> | 2019-12-12 12:12:17 +0100 |
|---|---|---|
| committer | Utkarsh Saxena <usx@google.com> | 2020-01-08 08:27:50 +0100 |
| commit | 583ba07884ed9281d1f1f5311ee2e280c977d62d (patch) | |
| tree | f2f0cfe00c6af8fcacfb5d70370812ad41c9b553 /clang-tools-extra/clangd/index/SymbolCollector.cpp | |
| parent | 880734aebb396891d8e6596ae85d597ca43359b1 (diff) | |
| download | bcm5719-llvm-583ba07884ed9281d1f1f5311ee2e280c977d62d.tar.gz bcm5719-llvm-583ba07884ed9281d1f1f5311ee2e280c977d62d.zip | |
[clangd] Add xref for macros to FileIndex.
Summary:
Adds macro references to the dynamic index.
Tests added.
Also exposed a new API to convert path to URI in URI.h
Reviewers: hokein
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71406
Diffstat (limited to 'clang-tools-extra/clangd/index/SymbolCollector.cpp')
| -rw-r--r-- | clang-tools-extra/clangd/index/SymbolCollector.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp b/clang-tools-extra/clangd/index/SymbolCollector.cpp index c0b2b52a43c..48c26bae5c2 100644 --- a/clang-tools-extra/clangd/index/SymbolCollector.cpp +++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp @@ -346,6 +346,29 @@ bool SymbolCollector::handleDeclOccurrence( return true; } +void SymbolCollector::handleMacros(const MainFileMacros &MacroRefsToIndex) { + assert(PP.get()); + const auto &SM = PP->getSourceManager(); + const auto *MainFileEntry = SM.getFileEntryForID(SM.getMainFileID()); + assert(MainFileEntry); + + const auto MainFileURI = toURI(SM, MainFileEntry->getName(), Opts); + // Add macro references. + for (const auto &IDToRefs : MacroRefsToIndex.MacroRefs) { + for (const auto &Range : IDToRefs.second) { + Ref R; + R.Location.Start.setLine(Range.start.line); + R.Location.Start.setColumn(Range.start.character); + R.Location.End.setLine(Range.end.line); + R.Location.End.setColumn(Range.end.character); + R.Location.FileURI = MainFileURI.c_str(); + // FIXME: Add correct RefKind information to MainFileMacros. + R.Kind = RefKind::Reference; + Refs.insert(IDToRefs.first, R); + } + } +} + bool SymbolCollector::handleMacroOccurrence(const IdentifierInfo *Name, const MacroInfo *MI, index::SymbolRoleSet Roles, |

