diff --git a/src/messages/textDocument_did.cc b/src/messages/textDocument_did.cc index d8631b442..1f2a47de3 100644 --- a/src/messages/textDocument_did.cc +++ b/src/messages/textDocument_did.cc @@ -41,10 +41,12 @@ void MessageHandler::textDocument_didOpen(DidOpenTextDocumentParam ¶m) { // Submit new index request if it is not a header file or there is no // pending index request. - std::pair lang = lookupExtension(path); - if ((lang.first != LanguageId::Unknown && !lang.second) || + auto [lang, header] = lookupExtension(path); + if ((lang != LanguageId::Unknown && !header) || !pipeline::pending_index_requests) pipeline::Index(path, {}, IndexMode::Normal, false); + if (header) + project->IndexRelated(path); manager->OnView(path); } diff --git a/src/project.cc b/src/project.cc index c96eac1ea..e81d73032 100644 --- a/src/project.cc +++ b/src/project.cc @@ -535,4 +535,22 @@ void Project::Index(WorkingFiles *wfiles, RequestId id) { // trigger refreshing semantic highlight for all working files. pipeline::Index("", {}, IndexMode::NonInteractive, false); } + +void Project::IndexRelated(const std::string &path) { + auto &gi = g_config->index; + GroupMatch match(gi.whitelist, gi.blacklist); + std::string stem = sys::path::stem(path); + std::lock_guard lock(mtx); + for (auto &[root, folder] : root2folder) + if (StringRef(path).startswith(root)) { + for (const Project::Entry &entry : folder.entries) { + std::string reason; + if (sys::path::stem(entry.filename) == stem && entry.filename != path && + match.Matches(entry.filename, &reason)) + pipeline::Index(entry.filename, entry.args, IndexMode::NonInteractive, + true); + } + break; + } +} } // namespace ccls diff --git a/src/project.hh b/src/project.hh index 472cb32ae..f9fcad201 100644 --- a/src/project.hh +++ b/src/project.hh @@ -65,5 +65,6 @@ struct Project { const std::string &path); void Index(WorkingFiles *wfiles, RequestId id); + void IndexRelated(const std::string &path); }; } // namespace ccls