forked from OSchip/llvm-project
[clangd] Allow using experimental Dex index
This patch adds hidden Clangd flag ("use-dex-index") which replaces (currently) default `MemIndex` with `DexIndex` for the static index. Reviewed by: ioeric Differential Revision: https://reviews.llvm.org/D50897 llvm-svn: 340262
This commit is contained in:
parent
597811e7a7
commit
7a94c918a0
|
@ -28,6 +28,12 @@ void MemIndex::build(std::shared_ptr<std::vector<const Symbol *>> Syms) {
|
|||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<SymbolIndex> MemIndex::build(SymbolSlab Slab) {
|
||||
auto Idx = llvm::make_unique<MemIndex>();
|
||||
Idx->build(getSymbolsFromSlab(std::move(Slab)));
|
||||
return std::move(Idx);
|
||||
}
|
||||
|
||||
bool MemIndex::fuzzyFind(
|
||||
const FuzzyFindRequest &Req,
|
||||
llvm::function_ref<void(const Symbol &)> Callback) const {
|
||||
|
@ -72,7 +78,14 @@ void MemIndex::lookup(const LookupRequest &Req,
|
|||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<SymbolIndex> MemIndex::build(SymbolSlab Slab) {
|
||||
void MemIndex::findOccurrences(
|
||||
const OccurrencesRequest &Req,
|
||||
llvm::function_ref<void(const SymbolOccurrence &)> Callback) const {
|
||||
log("findOccurrences is not implemented.");
|
||||
}
|
||||
|
||||
std::shared_ptr<std::vector<const Symbol *>>
|
||||
getSymbolsFromSlab(SymbolSlab Slab) {
|
||||
struct Snapshot {
|
||||
SymbolSlab Slab;
|
||||
std::vector<const Symbol *> Pointers;
|
||||
|
@ -81,17 +94,8 @@ std::unique_ptr<SymbolIndex> MemIndex::build(SymbolSlab Slab) {
|
|||
Snap->Slab = std::move(Slab);
|
||||
for (auto &Sym : Snap->Slab)
|
||||
Snap->Pointers.push_back(&Sym);
|
||||
auto S = std::shared_ptr<std::vector<const Symbol *>>(std::move(Snap),
|
||||
&Snap->Pointers);
|
||||
auto MemIdx = llvm::make_unique<MemIndex>();
|
||||
MemIdx->build(std::move(S));
|
||||
return std::move(MemIdx);
|
||||
}
|
||||
|
||||
void MemIndex::findOccurrences(
|
||||
const OccurrencesRequest &Req,
|
||||
llvm::function_ref<void(const SymbolOccurrence &)> Callback) const {
|
||||
log("findOccurrences is not implemented.");
|
||||
return std::shared_ptr<std::vector<const Symbol *>>(std::move(Snap),
|
||||
&Snap->Pointers);
|
||||
}
|
||||
|
||||
} // namespace clangd
|
||||
|
|
|
@ -47,6 +47,11 @@ private:
|
|||
mutable std::mutex Mutex;
|
||||
};
|
||||
|
||||
// Returns pointers to the symbols in given slab and bundles slab lifetime with
|
||||
// returned symbol pointers so that the pointers are never invalid.
|
||||
std::shared_ptr<std::vector<const Symbol *>>
|
||||
getSymbolsFromSlab(SymbolSlab Slab);
|
||||
|
||||
} // namespace clangd
|
||||
} // namespace clang
|
||||
|
||||
|
|
|
@ -69,6 +69,12 @@ void DexIndex::build(std::shared_ptr<std::vector<const Symbol *>> Syms) {
|
|||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<SymbolIndex> DexIndex::build(SymbolSlab Slab) {
|
||||
auto Idx = llvm::make_unique<MemIndex>();
|
||||
Idx->build(getSymbolsFromSlab(std::move(Slab)));
|
||||
return std::move(Idx);
|
||||
}
|
||||
|
||||
/// Constructs iterators over tokens extracted from the query and exhausts it
|
||||
/// while applying Callback to each symbol in the order of decreasing quality
|
||||
/// of the matched symbols.
|
||||
|
|
|
@ -43,6 +43,9 @@ public:
|
|||
/// accessible as long as `Symbols` is kept alive.
|
||||
void build(std::shared_ptr<std::vector<const Symbol *>> Symbols);
|
||||
|
||||
/// \brief Build index from a symbol slab.
|
||||
static std::unique_ptr<SymbolIndex> build(SymbolSlab Slab);
|
||||
|
||||
bool
|
||||
fuzzyFind(const FuzzyFindRequest &Req,
|
||||
llvm::function_ref<void(const Symbol &)> Callback) const override;
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "Path.h"
|
||||
#include "Trace.h"
|
||||
#include "index/SymbolYAML.h"
|
||||
#include "index/dex/DexIndex.h"
|
||||
#include "clang/Basic/Version.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
|
@ -29,6 +30,7 @@ using namespace clang;
|
|||
using namespace clang::clangd;
|
||||
|
||||
namespace {
|
||||
|
||||
enum class PCHStorageFlag { Disk, Memory };
|
||||
|
||||
// Build an in-memory static index for global symbols from a YAML-format file.
|
||||
|
@ -45,8 +47,10 @@ std::unique_ptr<SymbolIndex> buildStaticIndex(llvm::StringRef YamlSymbolFile) {
|
|||
for (auto Sym : Slab)
|
||||
SymsBuilder.insert(Sym);
|
||||
|
||||
return MemIndex::build(std::move(SymsBuilder).build());
|
||||
return UseDex ? DexIndex::build(std::move(SymsBuilder).build())
|
||||
: MemIndex::build(std::move(SymsBuilder).build());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
static llvm::cl::opt<Path> CompileCommandsDir(
|
||||
|
@ -185,6 +189,11 @@ static llvm::cl::opt<CompileArgsFrom> CompileArgsFrom(
|
|||
"'compile_commands.json' files")),
|
||||
llvm::cl::init(FilesystemCompileArgs), llvm::cl::Hidden);
|
||||
|
||||
static llvm::cl::opt<bool>
|
||||
UseDex("use-dex-index",
|
||||
llvm::cl::desc("Use experimental Dex static index."),
|
||||
llvm::cl::init(false), llvm::cl::Hidden);
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
|
||||
llvm::cl::SetVersionPrinter([](llvm::raw_ostream &OS) {
|
||||
|
|
Loading…
Reference in New Issue