diff options
Diffstat (limited to 'clang-tools-extra/clangd/index/Merge.cpp')
-rw-r--r-- | clang-tools-extra/clangd/index/Merge.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/clang-tools-extra/clangd/index/Merge.cpp b/clang-tools-extra/clangd/index/Merge.cpp index aecca38..625b1c6 100644 --- a/clang-tools-extra/clangd/index/Merge.cpp +++ b/clang-tools-extra/clangd/index/Merge.cpp @@ -221,6 +221,32 @@ void MergedIndex::relations( }); } +void MergedIndex::reverseRelations( + const RelationsRequest &Req, + llvm::function_ref<void(const SymbolID &, const Symbol &)> Callback) const { + uint32_t Remaining = Req.Limit.value_or(std::numeric_limits<uint32_t>::max()); + // Return results from both indexes but avoid duplicates. + // We might return stale relations from the static index; + // we don't currently have a good way of identifying them. + llvm::DenseSet<std::pair<SymbolID, SymbolID>> SeenRelations; + Dynamic->reverseRelations( + Req, [&](const SymbolID &Subject, const Symbol &Object) { + Callback(Subject, Object); + SeenRelations.insert(std::make_pair(Subject, Object.ID)); + --Remaining; + }); + if (Remaining == 0) + return; + Static->reverseRelations( + Req, [&](const SymbolID &Subject, const Symbol &Object) { + if (Remaining > 0 && + !SeenRelations.count(std::make_pair(Subject, Object.ID))) { + --Remaining; + Callback(Subject, Object); + } + }); +} + // Returns true if \p L is (strictly) preferred to \p R (e.g. by file paths). If // neither is preferred, this returns false. static bool prefer(const SymbolLocation &L, const SymbolLocation &R) { |