Clang: Send in-memory generated ui header to backend

Change-Id: I59e9b1f10d1a7fe9a75cbe84117aa5cc04460dab
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
This commit is contained in:
Nikolai Kosjar
2015-06-04 11:38:59 +02:00
parent 3a2c9f6d4b
commit 521d7cf7a3
2 changed files with 56 additions and 1 deletions

View File

@@ -69,6 +69,10 @@ ModelManagerSupportClang::ModelManagerSupportClang()
this, &ModelManagerSupportClang::onEditorOpened);
CppTools::CppModelManager *modelManager = cppModelManager();
connect(modelManager, &CppTools::CppModelManager::abstractEditorSupportContentsUpdated,
this, &ModelManagerSupportClang::onAbstractEditorSupportContentsUpdated);
connect(modelManager, &CppTools::CppModelManager::abstractEditorSupportRemoved,
this, &ModelManagerSupportClang::onAbstractEditorSupportRemoved);
connect(modelManager, &CppTools::CppModelManager::projectPartsUpdated,
this, &ModelManagerSupportClang::onProjectPartsUpdated);
connect(modelManager, &CppTools::CppModelManager::projectPartsRemoved,

View File

@@ -615,6 +615,49 @@ bool hasSnippet(ProposalModel model, const QByteArray &text)
return false;
}
class MonitorGeneratedUiFile : public QObject
{
Q_OBJECT
public:
MonitorGeneratedUiFile();
bool waitUntilGenerated(int timeout = 10000) const;
private:
void onUiFileGenerated() { m_isGenerated = true; }
bool m_isGenerated = false;
};
MonitorGeneratedUiFile::MonitorGeneratedUiFile()
{
connect(CppTools::CppModelManager::instance(),
&CppTools::CppModelManager::abstractEditorSupportContentsUpdated,
this, &MonitorGeneratedUiFile::onUiFileGenerated);
}
bool MonitorGeneratedUiFile::waitUntilGenerated(int timeout) const
{
if (m_isGenerated)
return true;
QTime time;
time.start();
forever {
if (m_isGenerated)
return true;
if (time.elapsed() > timeout)
return false;
QCoreApplication::processEvents();
QThread::msleep(20);
}
return false;
}
} // anonymous namespace
namespace ClangCodeModel {
@@ -883,6 +926,8 @@ void ClangCodeCompletionTest::testUnsavedFilesTrackingByCompletingUiObject()
CppTools::Tests::TemporaryCopiedDir testDir(qrcPath("qt-widgets-app"));
QVERIFY(testDir.isValid());
MonitorGeneratedUiFile monitorGeneratedUiFile;
// Open project
const QString projectFilePath = testDir.absolutePath("qt-widgets-app.pro");
CppTools::Tests::ProjectOpenerAndCloser projectManager;
@@ -897,11 +942,11 @@ void ClangCodeCompletionTest::testUnsavedFilesTrackingByCompletingUiObject()
QVERIFY(openSource.succeeded());
// ...and check comletions
QVERIFY(monitorGeneratedUiFile.waitUntilGenerated());
ProposalModel proposal = completionResults(openSource.editor());
QVERIFY(hasItem(proposal, "menuBar"));
QVERIFY(hasItem(proposal, "statusBar"));
QVERIFY(hasItem(proposal, "centralWidget"));
QEXPECT_FAIL("", "Signals are not yet done", Abort);
QVERIFY(hasItem(proposal, "setupUi"));
}
@@ -921,6 +966,7 @@ void ClangCodeCompletionTest::testUpdateBackendAfterRestart()
// ... and modify it, so we have an unsaved file.
insertTextAtTopOfEditor(openHeader.editor(), "int someGlobal;\n");
// Open project ...
MonitorGeneratedUiFile monitorGeneratedUiFile;
const QString projectFilePath = testDir.absolutePath("qt-widgets-app.pro");
CppTools::Tests::ProjectOpenerAndCloser projectManager;
const CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true);
@@ -931,6 +977,7 @@ void ClangCodeCompletionTest::testUpdateBackendAfterRestart()
QVERIFY(testDocument.isCreatedAndHasValidCursorPosition());
OpenEditorAtCursorPosition openSource(testDocument);
QVERIFY(openSource.succeeded());
QVERIFY(monitorGeneratedUiFile.waitUntilGenerated());
// Check commands that would have been sent
QVERIFY(compare(LogOutput(spy.senderLog),
@@ -939,6 +986,8 @@ void ClangCodeCompletionTest::testUpdateBackendAfterRestart()
" ProjectPartContainer id: qt-widgets-app.pro\n"
"RegisterTranslationUnitForCodeCompletionCommand\n"
" Path: myheader.h ProjectPart: \n"
"RegisterTranslationUnitForCodeCompletionCommand\n"
" Path: ui_mainwindow.h ProjectPart: \n"
)));
spy.senderLog.clear();
@@ -966,3 +1015,5 @@ void ClangCodeCompletionTest::testUpdateBackendAfterRestart()
} // namespace Tests
} // namespace Internal
} // namespace ClangCodeModel
#include "clangcodecompletion_test.moc"