diff --git a/src/import_pipeline.cc b/src/import_pipeline.cc index 680f3d67..f4cd7d5f 100644 --- a/src/import_pipeline.cc +++ b/src/import_pipeline.cc @@ -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 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; diff --git a/src/include_complete.cc b/src/include_complete.cc index 056a5b2b..ea33fa33 100644 --- a/src/include_complete.cc +++ b/src/include_complete.cc @@ -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) diff --git a/src/project.cc b/src/project.cc index 545f8cf8..df568423 100644 --- a/src/project.cc +++ b/src/project.cc @@ -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, "")); } diff --git a/src/query.h b/src/query.h index a146df9f..571f1a4e 100644 --- a/src/query.h +++ b/src/query.h @@ -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 files_removed;