diff options
Diffstat (limited to 'clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp')
-rw-r--r-- | clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp | 40 |
1 files changed, 8 insertions, 32 deletions
diff --git a/clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp b/clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp index 8b2c411a166..80246b9ceea 100644 --- a/clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp +++ b/clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp @@ -6,21 +6,13 @@ // //===----------------------------------------------------------------------===// -#include "GlobalCompilationDatabase.h" #include "Logger.h" -#include "Path.h" #include "index/Background.h" -#include "llvm/ADT/Optional.h" -#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/ScopeExit.h" -#include "llvm/ADT/SmallString.h" -#include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/StringRef.h" #include "llvm/Support/Error.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" -#include <functional> namespace clang { namespace clangd { @@ -126,21 +118,12 @@ public: // Creates and owns IndexStorages for multiple CDBs. class DiskBackedIndexStorageManager { public: - DiskBackedIndexStorageManager( - std::function<llvm::Optional<ProjectInfo>(PathRef)> GetProjectInfo) - : IndexStorageMapMu(llvm::make_unique<std::mutex>()), - GetProjectInfo(std::move(GetProjectInfo)) { - llvm::SmallString<128> HomeDir; - llvm::sys::path::home_directory(HomeDir); - this->HomeDir = HomeDir.str().str(); - } + DiskBackedIndexStorageManager() + : IndexStorageMapMu(llvm::make_unique<std::mutex>()) {} - // Creates or fetches to storage from cache for the specified project. - BackgroundIndexStorage *operator()(PathRef File) { + // Creates or fetches to storage from cache for the specified CDB. + BackgroundIndexStorage *operator()(llvm::StringRef CDBDirectory) { std::lock_guard<std::mutex> Lock(*IndexStorageMapMu); - Path CDBDirectory = HomeDir; - if (auto PI = GetProjectInfo(File)) - CDBDirectory = PI->SourceRoot; auto &IndexStorage = IndexStorageMap[CDBDirectory]; if (!IndexStorage) IndexStorage = create(CDBDirectory); @@ -148,28 +131,21 @@ public: } private: - std::unique_ptr<BackgroundIndexStorage> create(PathRef CDBDirectory) { - if (CDBDirectory.empty()) { - elog("Tried to create storage for empty directory!"); + std::unique_ptr<BackgroundIndexStorage> create(llvm::StringRef CDBDirectory) { + if (CDBDirectory.empty()) return llvm::make_unique<NullStorage>(); - } return llvm::make_unique<DiskBackedIndexStorage>(CDBDirectory); } - Path HomeDir; - llvm::StringMap<std::unique_ptr<BackgroundIndexStorage>> IndexStorageMap; std::unique_ptr<std::mutex> IndexStorageMapMu; - - std::function<llvm::Optional<ProjectInfo>(PathRef)> GetProjectInfo; }; } // namespace BackgroundIndexStorage::Factory -BackgroundIndexStorage::createDiskBackedStorageFactory( - std::function<llvm::Optional<ProjectInfo>(PathRef)> GetProjectInfo) { - return DiskBackedIndexStorageManager(std::move(GetProjectInfo)); +BackgroundIndexStorage::createDiskBackedStorageFactory() { + return DiskBackedIndexStorageManager(); } } // namespace clangd |