diff --git a/src/cache_manager.cc b/src/cache_manager.cc index 2c23f26c..0fc06613 100644 --- a/src/cache_manager.cc +++ b/src/cache_manager.cc @@ -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::Make(Config* config) { - return std::make_shared(config); +std::shared_ptr ICacheManager::Make() { + return std::make_shared(); } // static diff --git a/src/cache_manager.h b/src/cache_manager.h index f175544b..0904f098 100644 --- a/src/cache_manager.h +++ b/src/cache_manager.h @@ -18,7 +18,7 @@ struct ICacheManager { std::string json; }; - static std::shared_ptr Make(Config* config); + static std::shared_ptr Make(); static std::shared_ptr MakeFake( const std::vector& entries); diff --git a/src/messages/ccls_freshen_index.cc b/src/messages/ccls_freshen_index.cc index 8e25a7b2..b56701db 100644 --- a/src/messages/ccls_freshen_index.cc +++ b/src/messages/ccls_freshen_index.cc @@ -40,7 +40,7 @@ struct Handler_CclsFreshenIndex : BaseMessageHandler { GroupMatch matcher(request->params.whitelist, request->params.blacklist); // Unmark all files whose timestamp has changed. - std::shared_ptr cache_manager = ICacheManager::Make(config); + std::shared_ptr cache_manager = ICacheManager::Make(); std::queue q; // |need_index| stores every filename ever enqueued. diff --git a/src/messages/ccls_index_file.cc b/src/messages/ccls_index_file.cc index 4dfac696..0e4ecd86 100644 --- a/src/messages/ccls_index_file.cc +++ b/src/messages/ccls_index_file.cc @@ -33,7 +33,7 @@ struct Handler_CclsIndexFile : BaseMessageHandler { 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); diff --git a/src/messages/text_document_did_change.cc b/src/messages/text_document_did_change.cc index 95be3ab5..4f978bc3 100644 --- a/src/messages/text_document_did_change.cc +++ b/src/messages/text_document_did_change.cc @@ -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); } } diff --git a/src/messages/text_document_did_open.cc b/src/messages/text_document_did_open.cc index e1261c95..06c83fa2 100644 --- a/src/messages/text_document_did_open.cc +++ b/src/messages/text_document_did_open.cc @@ -41,7 +41,7 @@ struct Handler_TextDocumentDidOpen Timer time; std::string path = params.textDocument.uri.GetPath(); - std::shared_ptr cache_manager = ICacheManager::Make(config); + std::shared_ptr cache_manager = ICacheManager::Make(); WorkingFile* working_file = working_files->OnOpen(params.textDocument); std::optional cached_file_contents = cache_manager->LoadCachedFileContents(path); diff --git a/src/messages/text_document_did_save.cc b/src/messages/text_document_did_save.cc index 57a3310b..9596ddb4 100644 --- a/src/messages/text_document_did_save.cc +++ b/src/messages/text_document_did_save.cc @@ -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); } } diff --git a/src/messages/workspace_did_change_watched_files.cc b/src/messages/workspace_did_change_watched_files.cc index ac2a1bd1..19b4ad13 100644 --- a/src/messages/workspace_did_change_watched_files.cc +++ b/src/messages/workspace_did_change_watched_files.cc @@ -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; } } diff --git a/src/project.cc b/src/project.cc index fe1f88f3..7357557d 100644 --- a/src/project.cc +++ b/src/project.cc @@ -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)); }); }