mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-19 20:12:33 +00:00
Simplify dependency management when updating index for a file.
This commit is contained in:
parent
1f6da81009
commit
7326b861ac
@ -896,7 +896,7 @@ bool IndexMain_DoIndex(IndexerConfig* config,
|
|||||||
queue_do_index->PriorityEnqueue(std::move(dep_index_request));
|
queue_do_index->PriorityEnqueue(std::move(dep_index_request));
|
||||||
}
|
}
|
||||||
|
|
||||||
project->UpdateFileState(index_request->path, old_index->import_file, old_index->dependencies, old_index->last_modification_time);
|
project->UpdateFileState(index_request->path, old_index->import_file, old_index->last_modification_time);
|
||||||
|
|
||||||
Index_DoIdMap response(nullptr, std::move(old_index));
|
Index_DoIdMap response(nullptr, std::move(old_index));
|
||||||
queue_do_id_map->Enqueue(std::move(response));
|
queue_do_id_map->Enqueue(std::move(response));
|
||||||
@ -919,7 +919,6 @@ bool IndexMain_DoIndex(IndexerConfig* config,
|
|||||||
optional<Project::Entry> entry = project->FindCompilationEntryForFile(index_request->path);
|
optional<Project::Entry> entry = project->FindCompilationEntryForFile(index_request->path);
|
||||||
if (entry && entry->last_modification_time) {
|
if (entry && entry->last_modification_time) {
|
||||||
import_file = entry->import_file;
|
import_file = entry->import_file;
|
||||||
import_dependencies = entry->import_dependencies;
|
|
||||||
|
|
||||||
int64_t modification_time = GetLastModificationTime(index_request->path);
|
int64_t modification_time = GetLastModificationTime(index_request->path);
|
||||||
if (modification_time == *entry->last_modification_time) {
|
if (modification_time == *entry->last_modification_time) {
|
||||||
@ -930,18 +929,21 @@ bool IndexMain_DoIndex(IndexerConfig* config,
|
|||||||
|
|
||||||
std::vector<std::unique_ptr<IndexedFile>> indexes = Parse(
|
std::vector<std::unique_ptr<IndexedFile>> indexes = Parse(
|
||||||
config, file_consumer_shared,
|
config, file_consumer_shared,
|
||||||
index_request->path, import_file, import_dependencies,
|
index_request->path, import_file,
|
||||||
index_request->args);
|
index_request->args);
|
||||||
time.ResetAndPrint("Parsing/indexing " + index_request->path);
|
time.ResetAndPrint("Parsing/indexing " + index_request->path);
|
||||||
|
|
||||||
for (auto& current_index : indexes) {
|
for (auto& current_index : indexes) {
|
||||||
std::cerr << "Got index for " << current_index->path << std::endl;
|
std::cerr << "Got index for " << current_index->path << std::endl;
|
||||||
|
|
||||||
project->UpdateFileState(current_index->path, current_index->import_file, current_index->dependencies, current_index->last_modification_time);
|
project->UpdateFileState(current_index->path, current_index->import_file, current_index->last_modification_time);
|
||||||
|
|
||||||
std::unique_ptr<IndexedFile> old_index = LoadCachedFile(config, current_index->path);
|
std::unique_ptr<IndexedFile> old_index = LoadCachedFile(config, current_index->path);
|
||||||
time.ResetAndPrint("Loading cached index");
|
time.ResetAndPrint("Loading cached index");
|
||||||
|
|
||||||
|
if (old_index)
|
||||||
|
AddRange(¤t_index->dependencies, old_index->dependencies);
|
||||||
|
|
||||||
// TODO: Cache to disk on a separate thread. Maybe we do the cache after we
|
// TODO: Cache to disk on a separate thread. Maybe we do the cache after we
|
||||||
// have imported the index (so the import pipeline has five stages instead
|
// have imported the index (so the import pipeline has five stages instead
|
||||||
// of the current 4).
|
// of the current 4).
|
||||||
|
@ -1337,7 +1337,7 @@ void indexEntityReference(CXClientData client_data,
|
|||||||
|
|
||||||
std::vector<std::unique_ptr<IndexedFile>> Parse(
|
std::vector<std::unique_ptr<IndexedFile>> Parse(
|
||||||
IndexerConfig* config, FileConsumer::SharedState* file_consumer_shared,
|
IndexerConfig* config, FileConsumer::SharedState* file_consumer_shared,
|
||||||
std::string desired_index_file, std::string import_file, const std::vector<std::string>& existing_dependencies,
|
std::string desired_index_file, std::string import_file,
|
||||||
std::vector<std::string> args,
|
std::vector<std::string> args,
|
||||||
bool dump_ast) {
|
bool dump_ast) {
|
||||||
|
|
||||||
@ -1392,9 +1392,6 @@ std::vector<std::unique_ptr<IndexedFile>> Parse(
|
|||||||
|
|
||||||
entry->last_modification_time = GetLastModificationTime(entry->path);
|
entry->last_modification_time = GetLastModificationTime(entry->path);
|
||||||
entry->import_file = import_file;
|
entry->import_file = import_file;
|
||||||
|
|
||||||
if (entry->path == import_file && !existing_dependencies.empty())
|
|
||||||
AddRange(&entry->dependencies, existing_dependencies);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Fix interesting checks.
|
// TODO: Fix interesting checks.
|
||||||
|
@ -505,7 +505,7 @@ struct IndexedFile {
|
|||||||
// |dependencies| are the existing dependencies of |import_file| if this is a reparse.
|
// |dependencies| are the existing dependencies of |import_file| if this is a reparse.
|
||||||
std::vector<std::unique_ptr<IndexedFile>> Parse(
|
std::vector<std::unique_ptr<IndexedFile>> Parse(
|
||||||
IndexerConfig* config, FileConsumer::SharedState* file_consumer_shared,
|
IndexerConfig* config, FileConsumer::SharedState* file_consumer_shared,
|
||||||
std::string desired_index_file, std::string import_file, const std::vector<std::string>& existing_dependencies,
|
std::string desired_index_file, std::string import_file,
|
||||||
std::vector<std::string> args,
|
std::vector<std::string> args,
|
||||||
bool dump_ast = false);
|
bool dump_ast = false);
|
||||||
void IndexInit();
|
void IndexInit();
|
||||||
|
@ -259,7 +259,7 @@ optional<Project::Entry> Project::FindCompilationEntryForFile(const std::string&
|
|||||||
return nullopt;
|
return nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::UpdateFileState(const std::string& filename, const std::string& import_file, const std::vector<std::string>& import_dependencies, uint64_t modification_time) {
|
void Project::UpdateFileState(const std::string& filename, const std::string& import_file, uint64_t modification_time) {
|
||||||
{
|
{
|
||||||
// TODO: There might be a lot of thread contention here.
|
// TODO: There might be a lot of thread contention here.
|
||||||
std::lock_guard<std::mutex> lock(entries_modification_mutex_);
|
std::lock_guard<std::mutex> lock(entries_modification_mutex_);
|
||||||
@ -267,7 +267,6 @@ void Project::UpdateFileState(const std::string& filename, const std::string& im
|
|||||||
if (it != absolute_path_to_entry_index_.end()) {
|
if (it != absolute_path_to_entry_index_.end()) {
|
||||||
auto& entry = entries[it->second];
|
auto& entry = entries[it->second];
|
||||||
entry.import_file = import_file;
|
entry.import_file = import_file;
|
||||||
entry.import_dependencies = import_dependencies;
|
|
||||||
entry.last_modification_time = modification_time;
|
entry.last_modification_time = modification_time;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -283,7 +282,6 @@ void Project::UpdateFileState(const std::string& filename, const std::string& im
|
|||||||
}
|
}
|
||||||
|
|
||||||
entry.import_file = import_file;
|
entry.import_file = import_file;
|
||||||
entry.import_dependencies = import_dependencies;
|
|
||||||
entry.last_modification_time = modification_time;
|
entry.last_modification_time = modification_time;
|
||||||
|
|
||||||
// TODO: There might be a lot of thread contention here.
|
// TODO: There might be a lot of thread contention here.
|
||||||
|
@ -16,7 +16,6 @@ struct Project {
|
|||||||
std::vector<std::string> args;
|
std::vector<std::string> args;
|
||||||
|
|
||||||
std::string import_file;
|
std::string import_file;
|
||||||
std::vector<std::string> import_dependencies;
|
|
||||||
optional<uint64_t> last_modification_time;
|
optional<uint64_t> last_modification_time;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -36,6 +35,6 @@ struct Project {
|
|||||||
optional<Entry> FindCompilationEntryForFile(const std::string& filename);
|
optional<Entry> FindCompilationEntryForFile(const std::string& filename);
|
||||||
|
|
||||||
// Update the modification time for the given filename. This is thread-safe.
|
// Update the modification time for the given filename. This is thread-safe.
|
||||||
void UpdateFileState(const std::string& filename, const std::string& import_file, const std::vector<std::string>& import_dependencies, uint64_t modification_time);
|
void UpdateFileState(const std::string& filename, const std::string& import_file, uint64_t modification_time);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ void RunTests() {
|
|||||||
std::cout << "[START] " << path << std::endl;
|
std::cout << "[START] " << path << std::endl;
|
||||||
std::vector<std::unique_ptr<IndexedFile>> dbs = Parse(
|
std::vector<std::unique_ptr<IndexedFile>> dbs = Parse(
|
||||||
&config, &file_consumer_shared,
|
&config, &file_consumer_shared,
|
||||||
path, path, {},
|
path, path,
|
||||||
{
|
{
|
||||||
"-xc++",
|
"-xc++",
|
||||||
"-std=c++11",
|
"-std=c++11",
|
||||||
|
Loading…
Reference in New Issue
Block a user