forked from qt-creator/qt-creator
CppTools: Auto-include pre-compiled headers
So far the pre-compiled headers were processed (thus defines from those headers were visible), but the actual includes for the documents were not added, which is necessary for lookup/completion. Note that this will be only done if pre-compiled headers are not ignored (Options > C++ > Code Model > [] Ignore pre-compiled headers). Change-Id: I54a8e6b00597af164d958e3e9f2a1075ea187788 Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
@@ -37,6 +37,8 @@
|
||||
#include <coreplugin/testdatadir.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/session.h>
|
||||
|
||||
#include <cplusplus/LookupContext.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
|
||||
#include <QDebug>
|
||||
@@ -873,7 +875,7 @@ void CppToolsPlugin::test_modelmanager_defines_per_project()
|
||||
}
|
||||
}
|
||||
|
||||
void CppToolsPlugin::test_modelmanager_defines_per_project_pch()
|
||||
void CppToolsPlugin::test_modelmanager_precompiled_headers()
|
||||
{
|
||||
ModelManagerTestHelper helper;
|
||||
|
||||
@@ -922,14 +924,16 @@ void CppToolsPlugin::test_modelmanager_defines_per_project_pch()
|
||||
|
||||
struct Data {
|
||||
QString firstDeclarationName;
|
||||
QString firstClassInPchFile;
|
||||
QString fileName;
|
||||
} d[] = {
|
||||
{ _("one"), main1File },
|
||||
{ _("two"), main2File }
|
||||
{ _("one"), _("ClassInPch1"), main1File },
|
||||
{ _("two"), _("ClassInPch2"), main2File }
|
||||
};
|
||||
const int size = sizeof(d) / sizeof(d[0]);
|
||||
for (int i = 0; i < size; ++i) {
|
||||
const QString firstDeclarationName = d[i].firstDeclarationName;
|
||||
const QByteArray firstClassInPchFile = d[i].firstClassInPchFile.toUtf8();
|
||||
const QString fileName = d[i].fileName;
|
||||
|
||||
Core::IEditor *editor = Core::EditorManager::openEditor(fileName);
|
||||
@@ -943,11 +947,22 @@ void CppToolsPlugin::test_modelmanager_defines_per_project_pch()
|
||||
while (sup->lastSemanticInfoDocument().isNull())
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
sup->snapshotUpdater()->setUsePrecompiledHeaders(true);
|
||||
sup->snapshotUpdater()->update(mm->workingCopy());
|
||||
const QSharedPointer<SnapshotUpdater> updater = sup->snapshotUpdater();
|
||||
updater->setUsePrecompiledHeaders(true);
|
||||
updater->update(mm->workingCopy());
|
||||
|
||||
Document::Ptr doc = mm->document(fileName);
|
||||
QCOMPARE(nameOfFirstDeclaration(doc), firstDeclarationName);
|
||||
// Check if defines from pch are considered
|
||||
Document::Ptr document = mm->document(fileName);
|
||||
QCOMPARE(nameOfFirstDeclaration(document), firstDeclarationName);
|
||||
|
||||
// Check if declarations from pch are considered
|
||||
CPlusPlus::LookupContext context(document, updater->snapshot());
|
||||
const CPlusPlus::Identifier *identifier
|
||||
= document->control()->identifier(firstClassInPchFile.data());
|
||||
const QList<CPlusPlus::LookupItem> results = context.lookup(identifier,
|
||||
document->globalNamespace());
|
||||
QVERIFY(!results.isEmpty());
|
||||
QVERIFY(results.first().declaration()->type()->asClassType());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user