diff --git a/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp b/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp index e95bcb71d9a..32b5b31585e 100644 --- a/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp +++ b/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp @@ -37,6 +37,7 @@ #include "clanggloballocatorfilters.h" #include "clangoverviewmodel.h" +#include #include #include #include @@ -290,8 +291,27 @@ void ClangModelManagerSupport::updateLanguageClient(ProjectExplorer::Project *pr if (cppModelManager()->projectInfo(project) != projectInfo) return; - // TODO: We'd like to add all open editor documents for the project to the client here, - // but there doesn't seem to be such an interface. + // Acquaint the client with all open C++ documents for this project. + bool hasDocuments = false; + for (const Core::DocumentModel::Entry * const entry : Core::DocumentModel::entries()) { + const auto textDocument = qobject_cast(entry->document); + if (!textDocument) + continue; + const bool isCppDocument = Utils::contains( + Core::DocumentModel::editorsForDocument(textDocument), + [](Core::IEditor *editor) { + return CppTools::CppModelManager::isCppEditor(editor); + }); + if (!isCppDocument) + continue; + if (!project->isKnownFile(entry->fileName())) + continue; + client->openDocument(textDocument); + hasDocuments = true; + } + + if (hasDocuments) + return; // clangd oddity: Background indexing only starts after opening a random file. // TODO: changes to the compilation db do not seem to trigger re-indexing. diff --git a/src/plugins/clangcodemodel/clangrefactoringengine.cpp b/src/plugins/clangcodemodel/clangrefactoringengine.cpp index dc0e06899f7..ba418e7e032 100644 --- a/src/plugins/clangcodemodel/clangrefactoringengine.cpp +++ b/src/plugins/clangcodemodel/clangrefactoringengine.cpp @@ -97,8 +97,8 @@ void RefactoringEngine::findUsages(const CppTools::CursorInEditor &cursor, ->findUsages(cursor, std::move(callback)); return; } - if (!client->documentOpen(cursor.textDocument())) - client->openDocument(cursor.textDocument()); // TODO: Just a workaround + QTC_ASSERT(client->documentOpen(cursor.textDocument()), + client->openDocument(cursor.textDocument())); client->findUsages(cursor.textDocument(), cursor.cursor()); }