mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-19 12:05:50 +00:00
Fix delta update.
Previous file was being loaded after the current file is written to disk.
This commit is contained in:
parent
59851c06e0
commit
3ab4d0455d
22
src/cache.cc
22
src/cache.cc
@ -4,6 +4,8 @@
|
|||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include "language_server_api.h"
|
#include "language_server_api.h"
|
||||||
|
|
||||||
|
#include <loguru/loguru.hpp>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@ -30,7 +32,9 @@ std::unique_ptr<IndexFile> LoadCachedIndex(Config* config,
|
|||||||
if (!file_content)
|
if (!file_content)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
return Deserialize(filename, *file_content, IndexFile::kCurrentVersion);
|
auto result = Deserialize(filename, *file_content, IndexFile::kCurrentVersion);
|
||||||
|
result->is_loaded_from_cache_ = true;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
optional<std::string> LoadCachedFileContents(Config* config,
|
optional<std::string> LoadCachedFileContents(Config* config,
|
||||||
@ -42,25 +46,21 @@ optional<std::string> LoadCachedFileContents(Config* config,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WriteToCache(Config* config,
|
void WriteToCache(Config* config,
|
||||||
const std::string& filename,
|
IndexFile& file) {
|
||||||
IndexFile& file,
|
|
||||||
const optional<std::string>& indexed_file_content) {
|
|
||||||
if (!config->enableCacheWrite)
|
if (!config->enableCacheWrite)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::string cache_basename =
|
std::string cache_basename =
|
||||||
GetCachedBaseFileName(config->cacheDirectory, filename);
|
GetCachedBaseFileName(config->cacheDirectory, file.path);
|
||||||
|
|
||||||
if (indexed_file_content) {
|
LOG_IF_S(ERROR, file.file_contents_.empty()) << "Writing " << file.path << " to cache but it has no contents";
|
||||||
|
|
||||||
|
assert(!file.file_contents_.empty());
|
||||||
std::ofstream cache_content;
|
std::ofstream cache_content;
|
||||||
cache_content.open(cache_basename);
|
cache_content.open(cache_basename);
|
||||||
assert(cache_content.good());
|
assert(cache_content.good());
|
||||||
cache_content << *indexed_file_content;
|
cache_content << file.file_contents_;
|
||||||
cache_content.close();
|
cache_content.close();
|
||||||
}
|
|
||||||
else {
|
|
||||||
CopyFileTo(cache_basename, filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string indexed_content = Serialize(file);
|
std::string indexed_content = Serialize(file);
|
||||||
std::ofstream cache;
|
std::ofstream cache;
|
||||||
|
@ -17,6 +17,4 @@ optional<std::string> LoadCachedFileContents(Config* config,
|
|||||||
const std::string& filename);
|
const std::string& filename);
|
||||||
|
|
||||||
void WriteToCache(Config* config,
|
void WriteToCache(Config* config,
|
||||||
const std::string& filename,
|
IndexFile& file);
|
||||||
IndexFile& file,
|
|
||||||
const optional<std::string>& indexed_file_contents);
|
|
@ -583,6 +583,7 @@ struct Index_OnIdMapped {
|
|||||||
|
|
||||||
std::unique_ptr<File> previous;
|
std::unique_ptr<File> previous;
|
||||||
std::unique_ptr<File> current;
|
std::unique_ptr<File> current;
|
||||||
|
|
||||||
PerformanceImportFile perf;
|
PerformanceImportFile perf;
|
||||||
bool is_interactive;
|
bool is_interactive;
|
||||||
|
|
||||||
@ -638,8 +639,6 @@ struct Index_OnIndexed {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -896,11 +895,6 @@ std::vector<Index_DoIdMap> DoParseFile(
|
|||||||
// Note: we are reusing the parent perf.
|
// Note: we are reusing the parent perf.
|
||||||
perf.index_load_cached = time.ElapsedMicrosecondsAndReset();
|
perf.index_load_cached = time.ElapsedMicrosecondsAndReset();
|
||||||
|
|
||||||
// Write new cache to disk. Add file to list of paths that need to be reimported.
|
|
||||||
time.Reset();
|
|
||||||
WriteToCache(config, new_index->path, *new_index, new_index->file_contents_);
|
|
||||||
perf.index_save_to_disk = time.ElapsedMicrosecondsAndReset();
|
|
||||||
|
|
||||||
// TODO/FIXME: real is_interactive
|
// TODO/FIXME: real is_interactive
|
||||||
bool is_interactive = false;
|
bool is_interactive = false;
|
||||||
LOG_S(INFO) << "Emitting index result for " << new_index->path;
|
LOG_S(INFO) << "Emitting index result for " << new_index->path;
|
||||||
@ -952,6 +946,7 @@ bool IndexMain_DoParse(
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool IndexMain_DoCreateIndexUpdate(
|
bool IndexMain_DoCreateIndexUpdate(
|
||||||
|
Config* config,
|
||||||
QueueManager* queue) {
|
QueueManager* queue) {
|
||||||
// TODO: Index_OnIdMapped dtor is failing because it seems that its contents have already been destroyed.
|
// TODO: Index_OnIdMapped dtor is failing because it seems that its contents have already been destroyed.
|
||||||
optional<Index_OnIdMapped> response = queue->on_id_mapped.TryDequeue();
|
optional<Index_OnIdMapped> response = queue->on_id_mapped.TryDequeue();
|
||||||
@ -968,11 +963,19 @@ bool IndexMain_DoCreateIndexUpdate(
|
|||||||
previous_index = response->previous->file.get();
|
previous_index = response->previous->file.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Build delta update.
|
||||||
IndexUpdate update = IndexUpdate::CreateDelta(
|
IndexUpdate update = IndexUpdate::CreateDelta(
|
||||||
previous_id_map, response->current->ids.get(),
|
previous_id_map, response->current->ids.get(),
|
||||||
previous_index, response->current->file.get());
|
previous_index, response->current->file.get());
|
||||||
response->perf.index_make_delta = time.ElapsedMicrosecondsAndReset();
|
response->perf.index_make_delta = time.ElapsedMicrosecondsAndReset();
|
||||||
|
|
||||||
|
// Write new cache to disk if it is a fresh index.
|
||||||
|
if (!response->current->file->is_loaded_from_cache_) {
|
||||||
|
time.Reset();
|
||||||
|
WriteToCache(config, *response->current->file);
|
||||||
|
response->perf.index_save_to_disk = time.ElapsedMicrosecondsAndReset();
|
||||||
|
}
|
||||||
|
|
||||||
#if false
|
#if false
|
||||||
#define PRINT_SECTION(name) \
|
#define PRINT_SECTION(name) \
|
||||||
if (response->perf.name) {\
|
if (response->perf.name) {\
|
||||||
@ -1061,7 +1064,7 @@ void IndexMain(Config* config,
|
|||||||
bool did_parse = IndexMain_DoParse(config, queue, file_consumer_shared, &index);
|
bool did_parse = IndexMain_DoParse(config, queue, file_consumer_shared, &index);
|
||||||
|
|
||||||
bool did_create_update =
|
bool did_create_update =
|
||||||
IndexMain_DoCreateIndexUpdate(queue);
|
IndexMain_DoCreateIndexUpdate(config, queue);
|
||||||
|
|
||||||
bool did_load_previous = IndexMain_LoadPreviousIndex(config, queue);
|
bool did_load_previous = IndexMain_LoadPreviousIndex(config, queue);
|
||||||
|
|
||||||
|
@ -356,10 +356,6 @@ std::string IndexFile::ToString() {
|
|||||||
return Serialize(*this);
|
return Serialize(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IndexFile::ClearLargeState() {
|
|
||||||
file_contents_ = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
IndexType::IndexType(IndexTypeId id, const std::string& usr)
|
IndexType::IndexType(IndexTypeId id, const std::string& usr)
|
||||||
: def(usr), id(id) {
|
: def(usr), id(id) {
|
||||||
assert(usr.size() > 0);
|
assert(usr.size() > 0);
|
||||||
|
@ -480,6 +480,8 @@ struct IndexFile {
|
|||||||
std::vector<IndexFunc> funcs;
|
std::vector<IndexFunc> funcs;
|
||||||
std::vector<IndexVar> vars;
|
std::vector<IndexVar> vars;
|
||||||
|
|
||||||
|
// True if this file was loaded from cache. Not serialized.
|
||||||
|
bool is_loaded_from_cache_ = false;
|
||||||
// Diagnostics found when indexing this file. Not serialized.
|
// Diagnostics found when indexing this file. Not serialized.
|
||||||
NonElidedVector<lsDiagnostic> diagnostics_;
|
NonElidedVector<lsDiagnostic> diagnostics_;
|
||||||
// File contents at the time of index. Not serialized.
|
// File contents at the time of index. Not serialized.
|
||||||
@ -498,7 +500,6 @@ struct IndexFile {
|
|||||||
IndexVar* Resolve(IndexVarId id);
|
IndexVar* Resolve(IndexVarId id);
|
||||||
|
|
||||||
std::string ToString();
|
std::string ToString();
|
||||||
void ClearLargeState();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FileContents {
|
struct FileContents {
|
||||||
|
Loading…
Reference in New Issue
Block a user