clang-tools  14.0.0git
Merge.h
Go to the documentation of this file.
1 //===--- Merge.h -------------------------------------------------*- C++-*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_MERGE_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_MERGE_H
11 
12 #include "Index.h"
13 
14 namespace clang {
15 namespace clangd {
16 
17 // Merge symbols L and R, preferring data from L in case of conflict.
18 // The two symbols must have the same ID.
19 // Returned symbol may contain data owned by either source.
20 Symbol mergeSymbol(const Symbol &L, const Symbol &R);
21 
22 // MergedIndex is a composite index based on two provided Indexes:
23 // - the Dynamic index covers few files, but is relatively up-to-date.
24 // - the Static index covers a bigger set of files, but is relatively stale.
25 // The returned index attempts to combine results, and avoid duplicates.
26 class MergedIndex : public SymbolIndex {
27  const SymbolIndex *Dynamic, *Static;
28 
29 public:
30  // The constructor does not access the symbols.
31  // It's safe to inherit from this class and pass pointers to derived members.
32  MergedIndex(const SymbolIndex *Dynamic, const SymbolIndex *Static)
34 
35  bool fuzzyFind(const FuzzyFindRequest &,
36  llvm::function_ref<void(const Symbol &)>) const override;
37  void lookup(const LookupRequest &,
38  llvm::function_ref<void(const Symbol &)>) const override;
39  bool refs(const RefsRequest &,
40  llvm::function_ref<void(const Ref &)>) const override;
41  void relations(const RelationsRequest &,
42  llvm::function_ref<void(const SymbolID &, const Symbol &)>)
43  const override;
44  llvm::unique_function<IndexContents(llvm::StringRef) const>
45  indexedFiles() const override;
46  size_t estimateMemoryUsage() const override {
47  return Dynamic->estimateMemoryUsage() + Static->estimateMemoryUsage();
48  }
49 };
50 
51 } // namespace clangd
52 } // namespace clang
53 
54 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_MERGE_H
clang::clangd::MergedIndex::estimateMemoryUsage
size_t estimateMemoryUsage() const override
Returns estimated size of index (in bytes).
Definition: Merge.h:46
Index.h
clang::clangd::FuzzyFindRequest
Definition: Index.h:27
clang::clangd::SymbolOrigin::Dynamic
@ Dynamic
clang::clangd::MergedIndex::relations
void relations(const RelationsRequest &, llvm::function_ref< void(const SymbolID &, const Symbol &)>) const override
Definition: Merge.cpp:171
clang::clangd::MergedIndex
Definition: Merge.h:26
clang::clangd::MergedIndex::fuzzyFind
bool fuzzyFind(const FuzzyFindRequest &, llvm::function_ref< void(const Symbol &)>) const override
Matches symbols in the index fuzzily and applies Callback on each matched symbol before returning.
Definition: Merge.cpp:38
clang::clangd::SymbolOrigin::Static
@ Static
clang::clangd::MergedIndex::refs
bool refs(const RefsRequest &, llvm::function_ref< void(const Ref &)>) const override
Finds all occurrences (e.g.
Definition: Merge.cpp:129
clang::clangd::Symbol
The class presents a C++ symbol, e.g.
Definition: Symbol.h:36
clang::clangd::IndexContents
IndexContents
Describes what data is covered by an index.
Definition: Index.h:91
clang::clangd::mergeSymbol
Symbol mergeSymbol(const Symbol &L, const Symbol &R)
Definition: Merge.cpp:213
clang::clangd::SymbolIndex
Interface for symbol indexes that can be used for searching or matching symbols among a set of symbol...
Definition: Index.h:111
clang::clangd::LookupRequest
Definition: Index.h:65
clang::clangd::Ref
Represents a symbol occurrence in the source file.
Definition: Ref.h:87
clang::clangd::MergedIndex::indexedFiles
llvm::unique_function< IndexContents(llvm::StringRef) const > indexedFiles() const override
Definition: Merge.cpp:164
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::clangd::RelationsRequest
Definition: Index.h:78
clang::clangd::SymbolID
Definition: SymbolID.h:32
clang::clangd::RefsRequest
Definition: Index.h:69
clang::clangd::MergedIndex::lookup
void lookup(const LookupRequest &, llvm::function_ref< void(const Symbol &)>) const override
Looks up symbols with any of the given symbol IDs and applies Callback on each matched symbol.
Definition: Merge.cpp:95
clang::clangd::MergedIndex::MergedIndex
MergedIndex(const SymbolIndex *Dynamic, const SymbolIndex *Static)
Definition: Merge.h:32