From b55819a8a1077441f9aa6a9206a36febaf85d216 Mon Sep 17 00:00:00 2001 From: scturtle Date: Tue, 8 May 2018 15:35:32 +0800 Subject: [PATCH] Random changes. (#6) --- src/clang_indexer.cc | 15 +++++++++------ src/import_pipeline.cc | 19 +++++++++++++++++++ src/include_complete.cc | 4 ++-- src/messages/initialize.cc | 9 +++------ src/project.cc | 3 +++ src/query.h | 6 +----- 6 files changed, 37 insertions(+), 19 deletions(-) diff --git a/src/clang_indexer.cc b/src/clang_indexer.cc index 355cda29..cf36a4c1 100644 --- a/src/clang_indexer.cc +++ b/src/clang_indexer.cc @@ -1841,12 +1841,15 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) { if (!ns.def.spell) { ClangCursor sem_parent = referenced.get_semantic_parent(); ClangCursor lex_parent = referenced.get_lexical_parent(); - ns.def.spell = - SetUse(db, referenced.get_spell(), sem_parent, Role::Definition); - ns.def.extent = - SetUse(db, referenced.get_extent(), lex_parent, Role::None); - std::string name = referenced.get_spell_name(); - SetTypeName(ns, referenced, nullptr, name.c_str(), param); + CXFile referenced_file; + Range spell = referenced.get_spell(&referenced_file); + if (file == referenced_file) { + ns.def.spell = SetUse(db, spell, sem_parent, Role::Definition); + ns.def.extent = + SetUse(db, referenced.get_extent(), lex_parent, Role::None); + std::string name = referenced.get_spell_name(); + SetTypeName(ns, referenced, nullptr, name.c_str(), param); + } } break; } diff --git a/src/import_pipeline.cc b/src/import_pipeline.cc index 14a341d2..680f3d67 100644 --- a/src/import_pipeline.cc +++ b/src/import_pipeline.cc @@ -71,6 +71,13 @@ bool Indexer_Parse(DiagnosticsEngine* diag_engine, auto& request = *opt_request; ICacheManager cache; + // dummy one to trigger refresh semantic highlight + if (request.path.empty()) { + queue->on_indexed.PushBack( + Index_OnIndexed(IndexUpdate{}, PerformanceImportFile()), false); + return false; + } + Project::Entry entry; { std::lock_guard lock(project->mutex_); @@ -216,6 +223,18 @@ void QueryDb_OnIndexed(QueueManager* queue, SemanticHighlightSymbolCache* semantic_cache, WorkingFiles* working_files, Index_OnIndexed* response) { + + if (response->update.file_id < 0) { // dummy + 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]; + EmitSemanticHighlighting(db, semantic_cache, f.get(), file); + } + return; + } + Timer time; db->ApplyIndexUpdate(&response->update); diff --git a/src/include_complete.cc b/src/include_complete.cc index f5ea1fc3..056a5b2b 100644 --- a/src/include_complete.cc +++ b/src/include_complete.cc @@ -106,8 +106,8 @@ void IncludeComplete::Rescan() { SetThreadName("scan_includes"); Timer timer; - InsertIncludesFromDirectory(g_config->projectRoot, - false /*use_angle_brackets*/); + // 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/messages/initialize.cc b/src/messages/initialize.cc index 9cbcba60..40571b8f 100644 --- a/src/messages/initialize.cc +++ b/src/messages/initialize.cc @@ -510,12 +510,9 @@ struct Handler_Initialize : BaseMessageHandler { // Start indexer threads. Start this after loading the project, as that // may take a long time. Indexer threads will emit status/progress // reports. - if (g_config->index.threads == 0) { - // If the user has not specified how many indexers to run, try to - // guess an appropriate value. Default to 80% utilization. - g_config->index.threads = - std::max(int(std::thread::hardware_concurrency() * 0.8), 1); - } + if (g_config->index.threads == 0) + g_config->index.threads = std::thread::hardware_concurrency(); + LOG_S(INFO) << "Starting " << g_config->index.threads << " indexers"; for (int i = 0; i < g_config->index.threads; i++) { std::thread([=]() { diff --git a/src/project.cc b/src/project.cc index d30e57e1..545f8cf8 100644 --- a/src/project.cc +++ b/src/project.cc @@ -563,6 +563,9 @@ 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 + queue->index_request.PushBack(Index_Request("", {}, false, "")); } TEST_SUITE("Project") { diff --git a/src/query.h b/src/query.h index 51d96ef3..a146df9f 100644 --- a/src/query.h +++ b/src/query.h @@ -99,11 +99,7 @@ struct IndexUpdate { static IndexUpdate CreateDelta(IndexFile* previous, IndexFile* current); - // Merge |update| into this update; this can reduce overhead / index update - // work can be parallelized. - void Merge(IndexUpdate&& update); - - int file_id; + int file_id = -1; // File updates. std::optional files_removed;