forked from qt-creator/qt-creator
		
	Merge remote-tracking branch 'origin/3.3'
Conflicts: qtcreator.pri qtcreator.qbs src/plugins/projectexplorer/projectexplorer.cpp src/shared/qbs Change-Id: I6d91042bb48314d00be721099aed19feca74e0ce
This commit is contained in:
		@@ -1927,7 +1927,9 @@ bool CppCompletionAssistProcessor::completeConstructorOrFunction(const QList<CPl
 | 
			
		||||
                    const FullySpecifiedType localTy = rewriteType(f->type(), &env, control);
 | 
			
		||||
 | 
			
		||||
                    // gets: "parameter list) cv-spec",
 | 
			
		||||
                    QString completion = overview.prettyType(localTy).mid(1);
 | 
			
		||||
                    const QString completion = overview.prettyType(localTy).mid(1);
 | 
			
		||||
                    if (completion == QLatin1String(")"))
 | 
			
		||||
                        continue;
 | 
			
		||||
 | 
			
		||||
                    addCompletionItem(completion, QIcon(), 0,
 | 
			
		||||
                                      QVariant::fromValue(CompleteFunctionDeclaration(f)));
 | 
			
		||||
 
 | 
			
		||||
@@ -300,6 +300,10 @@ CppModelManager::CppModelManager(QObject *parent)
 | 
			
		||||
            this, SLOT(onAboutToLoadSession()));
 | 
			
		||||
    connect(sessionManager, SIGNAL(aboutToUnloadSession(QString)),
 | 
			
		||||
            this, SLOT(onAboutToUnloadSession()));
 | 
			
		||||
 | 
			
		||||
    connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged,
 | 
			
		||||
            this, &CppModelManager::onCurrentEditorChanged);
 | 
			
		||||
 | 
			
		||||
    connect(Core::DocumentManager::instance(), &Core::DocumentManager::allDocumentsRenamed,
 | 
			
		||||
            this, &CppModelManager::renameIncludes);
 | 
			
		||||
 | 
			
		||||
@@ -460,7 +464,8 @@ void CppModelManager::removeExtraEditorSupport(AbstractEditorSupport *editorSupp
 | 
			
		||||
 | 
			
		||||
EditorDocumentHandle *CppModelManager::editorDocument(const QString &filePath) const
 | 
			
		||||
{
 | 
			
		||||
    QTC_ASSERT(!filePath.isEmpty(), return 0);
 | 
			
		||||
    if (filePath.isEmpty())
 | 
			
		||||
        return 0;
 | 
			
		||||
 | 
			
		||||
    QMutexLocker locker(&d->m_cppEditorsMutex);
 | 
			
		||||
    return d->m_cppEditors.value(filePath, 0);
 | 
			
		||||
@@ -687,21 +692,26 @@ void CppModelManager::recalculateFileToProjectParts()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CppModelManager::updateVisibleEditorDocuments() const
 | 
			
		||||
void CppModelManager::updateCppEditorDocuments() const
 | 
			
		||||
{
 | 
			
		||||
    QSet<QString> visibleDocumentsInEditMode;
 | 
			
		||||
    // Refresh visible documents
 | 
			
		||||
    QSet<Core::IDocument *> visibleCppEditorDocuments;
 | 
			
		||||
    foreach (Core::IEditor *editor, Core::EditorManager::visibleEditors()) {
 | 
			
		||||
        if (const Core::IDocument *document = editor->document()) {
 | 
			
		||||
            const QString filePath = document->filePath();
 | 
			
		||||
            if (!filePath.isEmpty())
 | 
			
		||||
                visibleDocumentsInEditMode.insert(filePath);
 | 
			
		||||
        if (Core::IDocument *document = editor->document()) {
 | 
			
		||||
            if (EditorDocumentHandle *cppEditorDocument = editorDocument(document->filePath())) {
 | 
			
		||||
                visibleCppEditorDocuments.insert(document);
 | 
			
		||||
                cppEditorDocument->processor()->run();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Re-process these documents
 | 
			
		||||
    foreach (const QString &filePath, visibleDocumentsInEditMode) {
 | 
			
		||||
        if (EditorDocumentHandle *editor = editorDocument(filePath))
 | 
			
		||||
            editor->processor()->run();
 | 
			
		||||
    // Mark invisible documents dirty
 | 
			
		||||
    QSet<Core::IDocument *> invisibleCppEditorDocuments
 | 
			
		||||
        = Core::DocumentModel::openedDocuments().toSet();
 | 
			
		||||
    invisibleCppEditorDocuments.subtract(visibleCppEditorDocuments);
 | 
			
		||||
    foreach (Core::IDocument *document, invisibleCppEditorDocuments) {
 | 
			
		||||
        if (EditorDocumentHandle *cppEditorDocument = editorDocument(document->filePath()))
 | 
			
		||||
            cppEditorDocument->setNeedsRefresh(true);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -784,7 +794,7 @@ QFuture<void> CppModelManager::updateProjectInfo(const ProjectInfo &newProjectIn
 | 
			
		||||
    // However, on e.g. a session restore first the editor documents are created and then the
 | 
			
		||||
    // project updates come in. That is, there are no reasonable dependency tables based on
 | 
			
		||||
    // resolved includes that we could rely on.
 | 
			
		||||
    updateVisibleEditorDocuments();
 | 
			
		||||
    updateCppEditorDocuments();
 | 
			
		||||
 | 
			
		||||
    // Trigger reindexing
 | 
			
		||||
    return updateSourceFiles(filesToReindex, ForcedProgressNotification);
 | 
			
		||||
@@ -871,6 +881,19 @@ void CppModelManager::onSourceFilesRefreshed() const
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CppModelManager::onCurrentEditorChanged(Core::IEditor *editor)
 | 
			
		||||
{
 | 
			
		||||
    if (!editor || !editor->document())
 | 
			
		||||
        return;
 | 
			
		||||
 | 
			
		||||
    if (EditorDocumentHandle *cppEditorDocument = editorDocument(editor->document()->filePath())) {
 | 
			
		||||
        if (cppEditorDocument->needsRefresh()) {
 | 
			
		||||
            cppEditorDocument->setNeedsRefresh(false);
 | 
			
		||||
            cppEditorDocument->processor()->run();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CppModelManager::onAboutToLoadSession()
 | 
			
		||||
{
 | 
			
		||||
    if (d->m_delayedGcTimer.isActive())
 | 
			
		||||
 
 | 
			
		||||
@@ -184,12 +184,13 @@ private slots:
 | 
			
		||||
    void onProjectAdded(ProjectExplorer::Project *project);
 | 
			
		||||
    void onAboutToRemoveProject(ProjectExplorer::Project *project);
 | 
			
		||||
    void onSourceFilesRefreshed() const;
 | 
			
		||||
    void onCurrentEditorChanged(Core::IEditor *editor);
 | 
			
		||||
    void onCoreAboutToClose();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    void delayedGC();
 | 
			
		||||
    void recalculateFileToProjectParts();
 | 
			
		||||
    void updateVisibleEditorDocuments() const;
 | 
			
		||||
    void updateCppEditorDocuments() const;
 | 
			
		||||
 | 
			
		||||
    void replaceSnapshot(const CPlusPlus::Snapshot &newSnapshot);
 | 
			
		||||
    void removeFilesFromSnapshot(const QSet<QString> &removedFiles);
 | 
			
		||||
 
 | 
			
		||||
@@ -1037,6 +1037,69 @@ void CppToolsPlugin::test_modelmanager_defines_per_editor()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CppToolsPlugin::test_modelmanager_updateEditorsAfterProjectUpdate()
 | 
			
		||||
{
 | 
			
		||||
    ModelManagerTestHelper helper;
 | 
			
		||||
    CppModelManager *mm = CppModelManager::instance();
 | 
			
		||||
 | 
			
		||||
    MyTestDataDir testDataDirectory(_("testdata_defines"));
 | 
			
		||||
    const QString fileA = testDataDirectory.file(_("main1.cpp")); // content not relevant
 | 
			
		||||
    const QString fileB = testDataDirectory.file(_("main2.cpp")); // content not relevant
 | 
			
		||||
 | 
			
		||||
    // Open file A in editor
 | 
			
		||||
    Core::IEditor *editorA = Core::EditorManager::openEditor(fileA);
 | 
			
		||||
    QVERIFY(editorA);
 | 
			
		||||
    EditorCloser closerA(editorA);
 | 
			
		||||
    QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1);
 | 
			
		||||
 | 
			
		||||
    EditorDocumentHandle *editorDocumentA = mm->editorDocument(fileA);
 | 
			
		||||
    QVERIFY(editorDocumentA);
 | 
			
		||||
    ProjectPart::Ptr documentAProjectPart = editorDocumentA->processor()->parser()->projectPart();
 | 
			
		||||
    QVERIFY(!documentAProjectPart->project);
 | 
			
		||||
 | 
			
		||||
    // Open file B in editor
 | 
			
		||||
    Core::IEditor *editorB = Core::EditorManager::openEditor(fileB);
 | 
			
		||||
    QVERIFY(editorB);
 | 
			
		||||
    EditorCloser closerB(editorB);
 | 
			
		||||
    QCOMPARE(Core::DocumentModel::openedDocuments().size(), 2);
 | 
			
		||||
 | 
			
		||||
    EditorDocumentHandle *editorDocumentB = mm->editorDocument(fileB);
 | 
			
		||||
    QVERIFY(editorDocumentB);
 | 
			
		||||
    ProjectPart::Ptr documentBProjectPart = editorDocumentB->processor()->parser()->projectPart();
 | 
			
		||||
    QVERIFY(!documentBProjectPart->project);
 | 
			
		||||
 | 
			
		||||
    // Switch back to document A
 | 
			
		||||
    Core::EditorManager::activateEditor(editorA);
 | 
			
		||||
 | 
			
		||||
    // Open/update related project
 | 
			
		||||
    Project *project = helper.createProject(_("test_modelmanager_updateEditorsAfterProjectUpdate"));
 | 
			
		||||
 | 
			
		||||
    ProjectPart::Ptr part(new ProjectPart);
 | 
			
		||||
    part->project = project;
 | 
			
		||||
    part->files.append(ProjectFile(fileA, ProjectFile::CXXSource));
 | 
			
		||||
    part->files.append(ProjectFile(fileB, ProjectFile::CXXSource));
 | 
			
		||||
    part->languageVersion = ProjectPart::CXX11;
 | 
			
		||||
    part->qtVersion = ProjectPart::NoQt;
 | 
			
		||||
 | 
			
		||||
    ProjectInfo pi = mm->projectInfo(project);
 | 
			
		||||
    pi.appendProjectPart(part);
 | 
			
		||||
    pi.finish();
 | 
			
		||||
    updateProjectInfo(mm, &helper, pi);
 | 
			
		||||
 | 
			
		||||
    // ... and check for updated editor document A
 | 
			
		||||
    while (editorDocumentA->processor()->isParserRunning())
 | 
			
		||||
        QCoreApplication::processEvents();
 | 
			
		||||
    documentAProjectPart = editorDocumentA->processor()->parser()->projectPart();
 | 
			
		||||
    QCOMPARE(documentAProjectPart->project, project);
 | 
			
		||||
 | 
			
		||||
    // Switch back to document B and check if that's updated, too
 | 
			
		||||
    Core::EditorManager::activateEditor(editorB);
 | 
			
		||||
    while (editorDocumentB->processor()->isParserRunning())
 | 
			
		||||
        QCoreApplication::processEvents();
 | 
			
		||||
    documentBProjectPart = editorDocumentB->processor()->parser()->projectPart();
 | 
			
		||||
    QCOMPARE(documentBProjectPart->project, project);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CppToolsPlugin::test_modelmanager_renameIncludes()
 | 
			
		||||
{
 | 
			
		||||
    struct ModelManagerGCHelper {
 | 
			
		||||
 
 | 
			
		||||
@@ -151,6 +151,7 @@ private slots:
 | 
			
		||||
    void test_modelmanager_dont_gc_opened_files();
 | 
			
		||||
    void test_modelmanager_defines_per_project();
 | 
			
		||||
    void test_modelmanager_defines_per_editor();
 | 
			
		||||
    void test_modelmanager_updateEditorsAfterProjectUpdate();
 | 
			
		||||
    void test_modelmanager_precompiled_headers();
 | 
			
		||||
    void test_modelmanager_renameIncludes();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -40,6 +40,7 @@ namespace CppTools {
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
EditorDocumentHandle::EditorDocumentHandle()
 | 
			
		||||
    : m_needsRefresh(false)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -47,4 +48,14 @@ EditorDocumentHandle::~EditorDocumentHandle()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool EditorDocumentHandle::needsRefresh() const
 | 
			
		||||
{
 | 
			
		||||
    return m_needsRefresh;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void EditorDocumentHandle::setNeedsRefresh(bool needsRefresh)
 | 
			
		||||
{
 | 
			
		||||
    m_needsRefresh = needsRefresh;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
} // namespace CppTools
 | 
			
		||||
 
 | 
			
		||||
@@ -42,6 +42,9 @@ public:
 | 
			
		||||
    EditorDocumentHandle();
 | 
			
		||||
    virtual ~EditorDocumentHandle();
 | 
			
		||||
 | 
			
		||||
    bool needsRefresh() const;
 | 
			
		||||
    void setNeedsRefresh(bool needsRefresh);
 | 
			
		||||
 | 
			
		||||
    // For the Working Copy
 | 
			
		||||
    virtual QString filePath() const = 0;
 | 
			
		||||
    virtual QByteArray contents() const = 0;
 | 
			
		||||
@@ -49,6 +52,9 @@ public:
 | 
			
		||||
 | 
			
		||||
    // For updating if new project info is set
 | 
			
		||||
    virtual BaseEditorDocumentProcessor *processor() = 0;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    bool m_needsRefresh;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} // namespace CppTools
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user