summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/index/MemIndex.h
diff options
context:
space:
mode:
authorEric Liu <ioeric@google.com>2017-12-14 11:25:49 +0000
committerEric Liu <ioeric@google.com>2017-12-14 11:25:49 +0000
commit3732cadc73a86cdde5521c53dc00d69318a3133e (patch)
tree2a7e9c2e3ac7ec2f756d625eee623a906e3bd26d /clang-tools-extra/clangd/index/MemIndex.h
parent83bcc68afa1907f1e86321f25a72342f0c9a714f (diff)
downloadbcm5719-llvm-3732cadc73a86cdde5521c53dc00d69318a3133e.tar.gz
bcm5719-llvm-3732cadc73a86cdde5521c53dc00d69318a3133e.zip
[clangd] Symbol index interfaces and an in-memory index implementation.
Summary: o Index interfaces to support using different index sources (e.g. AST index, global index) for code completion, cross-reference finding etc. This patch focuses on code completion. The following changes in the original patch has been split out. o Implement an AST-based index. o Add an option to replace sema code completion for qualified-id with index-based completion. o Implement an initial naive code completion index which matches symbols that have the query string as substring. Reviewers: malaperle, sammccall Reviewed By: sammccall Subscribers: hokein, klimek, malaperle, mgorny, ilya-biryukov, cfe-commits Differential Revision: https://reviews.llvm.org/D40548 llvm-svn: 320688
Diffstat (limited to 'clang-tools-extra/clangd/index/MemIndex.h')
-rw-r--r--clang-tools-extra/clangd/index/MemIndex.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/clang-tools-extra/clangd/index/MemIndex.h b/clang-tools-extra/clangd/index/MemIndex.h
new file mode 100644
index 00000000000..24601294da7
--- /dev/null
+++ b/clang-tools-extra/clangd/index/MemIndex.h
@@ -0,0 +1,41 @@
+//===--- MemIndex.h - Dynamic in-memory symbol index. -------------- C++-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_MEMINDEX_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_MEMINDEX_H
+
+#include "Index.h"
+#include <mutex>
+
+namespace clang {
+namespace clangd {
+
+/// \brief This implements an index for a (relatively small) set of symbols that
+/// can be easily managed in memory.
+class MemIndex : public SymbolIndex {
+public:
+ /// \brief (Re-)Build index for `Symbols`. All symbol pointers must remain
+ /// accessible as long as `Symbols` is kept alive.
+ void build(std::shared_ptr<std::vector<const Symbol *>> Symbols);
+
+ bool fuzzyFind(Context &Ctx, const FuzzyFindRequest &Req,
+ std::function<void(const Symbol &)> Callback) const override;
+
+private:
+ std::shared_ptr<std::vector<const Symbol *>> Symbols;
+ // Index is a set of symbols that are deduplicated by symbol IDs.
+ // FIXME: build smarter index structure.
+ llvm::DenseMap<SymbolID, const Symbol *> Index;
+ mutable std::mutex Mutex;
+};
+
+} // namespace clangd
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_MEMINDEX_H
OpenPOWER on IntegriCloud