mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-30 03:17:08 +00:00
5d4e0a5020
- Add FakeCacheManager - Add IIndexer so we don't call out to clang
51 lines
1.4 KiB
C++
51 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include <optional.h>
|
|
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
struct Config;
|
|
struct IndexFile;
|
|
|
|
struct ICacheManager {
|
|
struct FakeCacheEntry {
|
|
std::string path;
|
|
std::string content;
|
|
std::string json;
|
|
};
|
|
|
|
static std::unique_ptr<ICacheManager> Make(Config* config);
|
|
static std::unique_ptr<ICacheManager> MakeFake(
|
|
const std::vector<FakeCacheEntry>& entries);
|
|
|
|
virtual ~ICacheManager();
|
|
|
|
// Tries to load a cache for |path|, returning null if there is none. The
|
|
// cache loader still owns the cache.
|
|
IndexFile* TryLoad(const std::string& path);
|
|
|
|
// Takes the existing cache or loads the cache at |path|. May return null if
|
|
// the cache does not exist.
|
|
std::unique_ptr<IndexFile> TryTakeOrLoad(const std::string& path);
|
|
|
|
// Takes the existing cache or loads the cache at |path|. Asserts the cache
|
|
// exists.
|
|
std::unique_ptr<IndexFile> TakeOrLoad(const std::string& path);
|
|
|
|
virtual void WriteToCache(IndexFile& file) = 0;
|
|
|
|
virtual optional<std::string> LoadCachedFileContents(
|
|
const std::string& path) = 0;
|
|
|
|
// Iterate over all loaded caches.
|
|
void IterateLoadedCaches(std::function<void(IndexFile*)> fn);
|
|
|
|
protected:
|
|
virtual std::unique_ptr<IndexFile> RawCacheLoad(const std::string& path) = 0;
|
|
std::unordered_map<std::string, std::unique_ptr<IndexFile>> caches_;
|
|
};
|