clang-tools  7.0.0
MemIndex.h
Go to the documentation of this file.
1 //===--- MemIndex.h - Dynamic in-memory symbol index. -------------- C++-*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_MEMINDEX_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_MEMINDEX_H
12 
13 #include "Index.h"
14 #include <mutex>
15 
16 namespace clang {
17 namespace clangd {
18 
19 /// \brief This implements an index for a (relatively small) set of symbols that
20 /// can be easily managed in memory.
21 class MemIndex : public SymbolIndex {
22 public:
23  /// \brief (Re-)Build index for `Symbols`. All symbol pointers must remain
24  /// accessible as long as `Symbols` is kept alive.
25  void build(std::shared_ptr<std::vector<const Symbol *>> Symbols);
26 
27  /// \brief Build index from a symbol slab.
28  static std::unique_ptr<SymbolIndex> build(SymbolSlab Slab);
29 
30  bool
31  fuzzyFind(const FuzzyFindRequest &Req,
32  llvm::function_ref<void(const Symbol &)> Callback) const override;
33 
34  virtual void
35  lookup(const LookupRequest &Req,
36  llvm::function_ref<void(const Symbol &)> Callback) const override;
37 
38 private:
39  std::shared_ptr<std::vector<const Symbol *>> Symbols;
40  // Index is a set of symbols that are deduplicated by symbol IDs.
41  // FIXME: build smarter index structure.
42  llvm::DenseMap<SymbolID, const Symbol *> Index;
43  mutable std::mutex Mutex;
44 };
45 
46 } // namespace clangd
47 } // namespace clang
48 
49 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_MEMINDEX_H
void build(std::shared_ptr< std::vector< const Symbol *>> Symbols)
(Re-)Build index for Symbols.
Definition: MemIndex.cpp:18
Interface for symbol indexes that can be used for searching or matching symbols among a set of symbol...
Definition: Index.h:317
llvm::unique_function< void(llvm::Expected< T >)> Callback
A Callback<T> is a void function that accepts Expected<T>.
Definition: Function.h:28
This implements an index for a (relatively small) set of symbols that can be easily managed in memory...
Definition: MemIndex.h:21
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
virtual void lookup(const LookupRequest &Req, llvm::function_ref< void(const Symbol &)> Callback) const override
Looks up symbols with any of the given symbol IDs and applies Callback on each matched symbol...
Definition: MemIndex.cpp:65
bool fuzzyFind(const FuzzyFindRequest &Req, llvm::function_ref< void(const Symbol &)> Callback) const override
Matches symbols in the index fuzzily and applies Callback on each matched symbol before returning...
Definition: MemIndex.cpp:31