mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-25 17:11:59 +00:00
add basic index cache (useful for debugging)
This commit is contained in:
parent
5e7008875d
commit
cf6456c904
@ -15,6 +15,7 @@
|
||||
#include <rapidjson/istreamwrapper.h>
|
||||
#include <rapidjson/ostreamwrapper.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
@ -151,6 +152,28 @@ void RegisterMessageTypes() {
|
||||
MessageRegistry::instance()->Register<Ipc_WorkspaceSymbol>();
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1199,6 +1199,9 @@ void indexEntityReference(CXClientData client_data,
|
||||
IndexedFile Parse(std::string filename,
|
||||
std::vector<std::string> 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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user