From cf6456c9043684db3634952d00d042c901b9d66e Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Thu, 30 Mar 2017 22:30:50 -0700 Subject: [PATCH] add basic index cache (useful for debugging) --- src/command_line.cc | 28 ++++++++++++++++++++++++++++ src/indexer.cpp | 3 +++ 2 files changed, 31 insertions(+) diff --git a/src/command_line.cc b/src/command_line.cc index 0cff7cd2..842c7b69 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -151,6 +152,28 @@ void RegisterMessageTypes() { MessageRegistry::instance()->Register(); } +void WriteToCache(std::string filename, IndexedFile& file) { + // TODO/FIXME + const char* kCacheDirectory = "C:/Users/jacob/Desktop/superindex/indexer/CACHE/"; + + + std::replace(filename.begin(), filename.end(), '\\', '_'); + std::replace(filename.begin(), filename.end(), '/', '_'); + std::replace(filename.begin(), filename.end(), ':', '_'); + std::replace(filename.begin(), filename.end(), '.', '_'); + std::string cache_file = kCacheDirectory + filename + ".json"; + + std::string indexed_content = Serialize(file); + + + std::cerr << "Caching to " << cache_file << std::endl; + std::ofstream cache; + cache.open(cache_file); + assert(cache.good()); + cache << indexed_content; + cache.close(); +} + void IndexMain(IndexRequestQueue* requests, IndexResponseQueue* responses) { while (true) { // Try to get a request. If there isn't one, sleep for a little while. @@ -169,12 +192,17 @@ void IndexMain(IndexRequestQueue* requests, IndexResponseQueue* responses) { IndexedFile file = Parse(request->path, request->args); time.ResetAndPrint("Parsing/indexing"); + // TODO: Check cache for existing index; compute diff if there is one. IndexUpdate update(file); IndexTranslationUnitResponse response(update); time.ResetAndPrint("Creating index update/response"); responses->Enqueue(response); time.ResetAndPrint("Sending update to server"); + + // Cache file so we can diff it later. + WriteToCache(request->path, file); + time.ResetAndPrint("Cache index update to disk"); } } diff --git a/src/indexer.cpp b/src/indexer.cpp index aa53382d..869a9e59 100644 --- a/src/indexer.cpp +++ b/src/indexer.cpp @@ -1199,6 +1199,9 @@ void indexEntityReference(CXClientData client_data, IndexedFile Parse(std::string filename, std::vector args, bool dump_ast) { + // TODO: We are currently emitting too much information for things not in the main file. If we're + // not in the main file, we should only emit references. + clang_enableStackTraces(); clang_toggleCrashRecovery(1);