Fix file_id. (#8)

This commit is contained in:
scturtle 2018-05-08 23:56:20 +08:00 committed by Fangrui Song
parent b55819a8a1
commit 72433643bf
4 changed files with 15 additions and 10 deletions

View File

@ -71,10 +71,12 @@ bool Indexer_Parse(DiagnosticsEngine* diag_engine,
auto& request = *opt_request;
ICacheManager cache;
// dummy one to trigger refresh semantic highlight
// Dummy one to trigger refresh semantic highlight.
if (request.path.empty()) {
IndexUpdate dummy;
dummy.refresh = true;
queue->on_indexed.PushBack(
Index_OnIndexed(IndexUpdate{}, PerformanceImportFile()), false);
Index_OnIndexed(std::move(dummy), PerformanceImportFile()), false);
return false;
}
@ -224,12 +226,14 @@ void QueryDb_OnIndexed(QueueManager* queue,
WorkingFiles* working_files,
Index_OnIndexed* response) {
if (response->update.file_id < 0) { // dummy
if (response->update.refresh) {
LOG_S(INFO) << "Loaded project. Refresh semantic highlight for all working file.";
std::lock_guard<std::mutex> lock(working_files->files_mutex);
for (auto& f : working_files->files) {
int file_id = db->name2file_id[LowerPathIfInsensitive(f->filename)];
QueryFile* file = &db->files[file_id];
std::string filename = LowerPathIfInsensitive(f->filename);
if (db->name2file_id.find(filename) == db->name2file_id.end())
continue;
QueryFile* file = &db->files[db->name2file_id[filename]];
EmitSemanticHighlighting(db, semantic_cache, f.get(), file);
}
return;

View File

@ -106,8 +106,6 @@ void IncludeComplete::Rescan() {
SetThreadName("scan_includes");
Timer timer;
// InsertIncludesFromDirectory(g_config->projectRoot,
// false /*use_angle_brackets*/);
for (const std::string& dir : project_->quote_include_directories)
InsertIncludesFromDirectory(dir, false /*use_angle_brackets*/);
for (const std::string& dir : project_->angle_include_directories)

View File

@ -563,8 +563,8 @@ void Project::Index(QueueManager* queue,
queue->index_request.PushBack(Index_Request(entry.filename, entry.args,
is_interactive, *content, id));
});
// dummy request to indicate that project is loaded and
// trigger refreshing semantic highlight for all working files
// Dummy request to indicate that project is loaded and
// trigger refreshing semantic highlight for all working files.
queue->index_request.PushBack(Index_Request("", {}, false, ""));
}

View File

@ -99,7 +99,10 @@ struct IndexUpdate {
static IndexUpdate CreateDelta(IndexFile* previous,
IndexFile* current);
int file_id = -1;
int file_id;
// Dummy one to refresh all semantic highlight.
bool refresh = false;
// File updates.
std::optional<std::string> files_removed;