CppTools: Do not garbage collect files in the working copy

...except the configuration file if no projects are open. For this case
there is no need to keep the configuration file around.

Task-number: QTCREATORBUG-9829

Change-Id: I51b01b30c17cbc1ced491ef2c47c338dae6ed983
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
Nikolai Kosjar
2013-07-17 13:50:38 +02:00
parent 7583039b87
commit 2665a1249b
4 changed files with 59 additions and 4 deletions

View File

@@ -714,9 +714,28 @@ void CppModelManager::GC()
if (!m_enableGC) if (!m_enableGC)
return; return;
const Snapshot currentSnapshot = snapshot(); // Collect files of CppEditorSupport and AbstractEditorSupport.
QStringList filesInEditorSupports;
QList<CppEditorSupport *> cppEditorSupports;
{
QMutexLocker locker(&m_cppEditorSupportsMutex);
cppEditorSupports = m_cppEditorSupports.values();
}
foreach (const CppEditorSupport *cppEditorSupport, cppEditorSupports)
filesInEditorSupports << cppEditorSupport->fileName();
QSetIterator<AbstractEditorSupport *> jt(m_extraEditorSupports);
while (jt.hasNext()) {
AbstractEditorSupport *abstractEditorSupport = jt.next();
filesInEditorSupports << abstractEditorSupport->fileName();
}
Snapshot currentSnapshot = snapshot();
QSet<QString> reachableFiles; QSet<QString> reachableFiles;
QStringList todo = projectFiles(); // The configuration file is part of the project files, which is just fine.
// If single files are open, without any project, then there is no need to
// keep the configuration file around.
QStringList todo = filesInEditorSupports + projectFiles();
// Collect all files that are reachable from the project files // Collect all files that are reachable from the project files
while (!todo.isEmpty()) { while (!todo.isEmpty()) {

View File

@@ -151,11 +151,11 @@ public slots:
private slots: private slots:
// This should be executed in the GUI thread. // This should be executed in the GUI thread.
void onAboutToRemoveProject(ProjectExplorer::Project *project);
void onAboutToLoadSession(); void onAboutToLoadSession();
void onAboutToUnloadSession(); void onAboutToUnloadSession();
void onCoreAboutToClose();
void onProjectAdded(ProjectExplorer::Project *project); void onProjectAdded(ProjectExplorer::Project *project);
void onAboutToRemoveProject(ProjectExplorer::Project *project);
void onCoreAboutToClose();
private: private:
void delayedGC(); void delayedGC();

View File

@@ -551,3 +551,38 @@ void CppToolsPlugin::test_modelmanager_gc_if_last_cppeditor_closed()
QVERIFY(!mm->workingCopy().contains(file)); QVERIFY(!mm->workingCopy().contains(file));
QVERIFY(!mm->snapshot().contains(file)); QVERIFY(!mm->snapshot().contains(file));
} }
/// Check: Files that are open in the editor are not garbage collected.
void CppToolsPlugin::test_modelmanager_dont_gc_opened_files()
{
ModelManagerTestHelper helper;
TestDataDirectory testDataDirectory(QLatin1String("testdata_guiproject1"));
const QString file = testDataDirectory.file(QLatin1String("main.cpp"));
Core::EditorManager *em = Core::EditorManager::instance();
CppModelManager *mm = CppModelManager::instance();
// Open a file in the editor
QCOMPARE(Core::EditorManager::documentModel()->openedDocuments().size(), 0);
Core::IEditor *editor = em->openEditor(file);
QVERIFY(editor);
QCOMPARE(Core::EditorManager::documentModel()->openedDocuments().size(), 1);
QVERIFY(mm->isCppEditor(editor));
// Check: File is in the working copy and snapshot
QVERIFY(mm->workingCopy().contains(file));
QVERIFY(mm->snapshot().contains(file));
// Run the garbage collector
mm->GC();
// Check: File is still there
QVERIFY(mm->workingCopy().contains(file));
QVERIFY(mm->snapshot().contains(file));
// Close editor
em->closeEditors(QList<Core::IEditor*>() << editor);
helper.waitForFinishedGc();
QVERIFY(mm->snapshot().isEmpty());
}

View File

@@ -195,6 +195,7 @@ private slots:
void test_modelmanager_snapshot_after_two_projects(); void test_modelmanager_snapshot_after_two_projects();
void test_modelmanager_extraeditorsupport_uiFiles(); void test_modelmanager_extraeditorsupport_uiFiles();
void test_modelmanager_gc_if_last_cppeditor_closed(); void test_modelmanager_gc_if_last_cppeditor_closed();
void test_modelmanager_dont_gc_opened_files();
private: private:
void test_completion(); void test_completion();