mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-21 23:25:07 +00:00
.
This commit is contained in:
parent
c96631d1ee
commit
daf7a41278
@ -14,14 +14,14 @@ namespace {
|
||||
|
||||
// Manages loading caches from file paths for the indexer process.
|
||||
struct RealCacheManager : ICacheManager {
|
||||
explicit RealCacheManager(Config* config) : config_(config) {}
|
||||
explicit RealCacheManager() {}
|
||||
~RealCacheManager() override = default;
|
||||
|
||||
void WriteToCache(IndexFile& file) override {
|
||||
std::string cache_path = GetCachePath(file.path);
|
||||
WriteToFile(cache_path, file.file_contents);
|
||||
|
||||
std::string indexed_content = Serialize(config_->cacheFormat, file);
|
||||
std::string indexed_content = Serialize(g_config.cacheFormat, file);
|
||||
WriteToFile(AppendSerializationFormat(cache_path), indexed_content);
|
||||
}
|
||||
|
||||
@ -38,27 +38,27 @@ struct RealCacheManager : ICacheManager {
|
||||
if (!file_content || !serialized_indexed_content)
|
||||
return nullptr;
|
||||
|
||||
return Deserialize(config_->cacheFormat, path, *serialized_indexed_content,
|
||||
return Deserialize(g_config.cacheFormat, path, *serialized_indexed_content,
|
||||
*file_content, IndexFile::kMajorVersion);
|
||||
}
|
||||
|
||||
std::string GetCachePath(const std::string& source_file) {
|
||||
assert(!config_->cacheDirectory.empty());
|
||||
assert(!g_config.cacheDirectory.empty());
|
||||
std::string cache_file;
|
||||
size_t len = config_->projectRoot.size();
|
||||
if (StartsWith(source_file, config_->projectRoot)) {
|
||||
cache_file = EscapeFileName(config_->projectRoot) +
|
||||
size_t len = g_config.projectRoot.size();
|
||||
if (StartsWith(source_file, g_config.projectRoot)) {
|
||||
cache_file = EscapeFileName(g_config.projectRoot) +
|
||||
EscapeFileName(source_file.substr(len));
|
||||
} else {
|
||||
cache_file = '@' + EscapeFileName(config_->projectRoot) +
|
||||
cache_file = '@' + EscapeFileName(g_config.projectRoot) +
|
||||
EscapeFileName(source_file);
|
||||
}
|
||||
|
||||
return config_->cacheDirectory + cache_file;
|
||||
return g_config.cacheDirectory + cache_file;
|
||||
}
|
||||
|
||||
std::string AppendSerializationFormat(const std::string& base) {
|
||||
switch (config_->cacheFormat) {
|
||||
switch (g_config.cacheFormat) {
|
||||
case SerializeFormat::Json:
|
||||
return base + ".json";
|
||||
case SerializeFormat::MessagePack:
|
||||
@ -67,8 +67,6 @@ struct RealCacheManager : ICacheManager {
|
||||
assert(false);
|
||||
return ".json";
|
||||
}
|
||||
|
||||
Config* config_;
|
||||
};
|
||||
|
||||
struct FakeCacheManager : ICacheManager {
|
||||
@ -105,8 +103,8 @@ struct FakeCacheManager : ICacheManager {
|
||||
} // namespace
|
||||
|
||||
// static
|
||||
std::shared_ptr<ICacheManager> ICacheManager::Make(Config* config) {
|
||||
return std::make_shared<RealCacheManager>(config);
|
||||
std::shared_ptr<ICacheManager> ICacheManager::Make() {
|
||||
return std::make_shared<RealCacheManager>();
|
||||
}
|
||||
|
||||
// static
|
||||
|
@ -18,7 +18,7 @@ struct ICacheManager {
|
||||
std::string json;
|
||||
};
|
||||
|
||||
static std::shared_ptr<ICacheManager> Make(Config* config);
|
||||
static std::shared_ptr<ICacheManager> Make();
|
||||
static std::shared_ptr<ICacheManager> MakeFake(
|
||||
const std::vector<FakeCacheEntry>& entries);
|
||||
|
||||
|
@ -40,7 +40,7 @@ struct Handler_CclsFreshenIndex : BaseMessageHandler<In_CclsFreshenIndex> {
|
||||
GroupMatch matcher(request->params.whitelist, request->params.blacklist);
|
||||
|
||||
// Unmark all files whose timestamp has changed.
|
||||
std::shared_ptr<ICacheManager> cache_manager = ICacheManager::Make(config);
|
||||
std::shared_ptr<ICacheManager> cache_manager = ICacheManager::Make();
|
||||
|
||||
std::queue<const QueryFile*> q;
|
||||
// |need_index| stores every filename ever enqueued.
|
||||
|
@ -33,7 +33,7 @@ struct Handler_CclsIndexFile : BaseMessageHandler<In_CclsIndexFile> {
|
||||
QueueManager::instance()->index_request.PushBack(
|
||||
Index_Request(NormalizePath(request->params.path), request->params.args,
|
||||
request->params.is_interactive, request->params.contents,
|
||||
ICacheManager::Make(config)));
|
||||
ICacheManager::Make()));
|
||||
}
|
||||
};
|
||||
REGISTER_MESSAGE_HANDLER(Handler_CclsIndexFile);
|
||||
|
@ -33,7 +33,7 @@ struct Handler_TextDocumentDidChange
|
||||
Project::Entry entry = project->FindCompilationEntryForFile(path);
|
||||
QueueManager::instance()->index_request.PushBack(
|
||||
Index_Request(entry.filename, entry.args, true /*is_interactive*/,
|
||||
*content, ICacheManager::Make(config)),
|
||||
*content, ICacheManager::Make()),
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ struct Handler_TextDocumentDidOpen
|
||||
Timer time;
|
||||
std::string path = params.textDocument.uri.GetPath();
|
||||
|
||||
std::shared_ptr<ICacheManager> cache_manager = ICacheManager::Make(config);
|
||||
std::shared_ptr<ICacheManager> cache_manager = ICacheManager::Make();
|
||||
WorkingFile* working_file = working_files->OnOpen(params.textDocument);
|
||||
std::optional<std::string> cached_file_contents =
|
||||
cache_manager->LoadCachedFileContents(path);
|
||||
|
@ -55,7 +55,7 @@ struct Handler_TextDocumentDidSave
|
||||
Project::Entry entry = project->FindCompilationEntryForFile(path);
|
||||
QueueManager::instance()->index_request.PushBack(
|
||||
Index_Request(entry.filename, entry.args, true /*is_interactive*/,
|
||||
*content, ICacheManager::Make(config)),
|
||||
*content, ICacheManager::Make()),
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ struct Handler_WorkspaceDidChangeWatchedFiles
|
||||
else {
|
||||
QueueManager::instance()->index_request.PushBack(
|
||||
Index_Request(path, entry.args, is_interactive, *content,
|
||||
ICacheManager::Make(config)));
|
||||
ICacheManager::Make()));
|
||||
if (is_interactive)
|
||||
clang_complete->NotifySave(path);
|
||||
}
|
||||
@ -65,7 +65,7 @@ struct Handler_WorkspaceDidChangeWatchedFiles
|
||||
case lsFileChangeType::Deleted:
|
||||
QueueManager::instance()->index_request.PushBack(
|
||||
Index_Request(path, entry.args, is_interactive, std::string(),
|
||||
ICacheManager::Make(config)));
|
||||
ICacheManager::Make()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -568,9 +568,9 @@ void Project::Index(Config* config,
|
||||
return;
|
||||
}
|
||||
bool is_interactive = wfiles->GetFileByFilename(entry.filename) != nullptr;
|
||||
queue->index_request.PushBack(
|
||||
Index_Request(entry.filename, entry.args, is_interactive, *content,
|
||||
ICacheManager::Make(config), id));
|
||||
queue->index_request.PushBack(Index_Request(entry.filename, entry.args,
|
||||
is_interactive, *content,
|
||||
ICacheManager::Make(), id));
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user