forked from qt-creator/qt-creator
Fix changing "#include" lines after file renaming
Didn't work if there was any folded text before the #include. Change-Id: I8f16205f06bfaa8b8541401a9ebd5995c15b2227 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com> Reviewed-by: Daniel Teske <daniel.teske@theqtcompany.com>
This commit is contained in:
committed by
Nikolai Kosjar
parent
5eb8fe0306
commit
307061032c
@@ -1113,7 +1113,7 @@ void CppModelManager::renameIncludes(const QString &oldFileName, const QString &
|
||||
|
||||
foreach (Snapshot::IncludeLocation loc, snapshot().includeLocationsOfDocument(oldFileName)) {
|
||||
TextEditor::RefactoringFilePtr file = changes.file(loc.first->fileName());
|
||||
const QTextBlock &block = file->document()->findBlockByLineNumber(loc.second - 1);
|
||||
const QTextBlock &block = file->document()->findBlockByNumber(loc.second - 1);
|
||||
const int replaceStart = block.text().indexOf(oldFileInfo.fileName());
|
||||
if (replaceStart > -1) {
|
||||
Utils::ChangeSet changeSet;
|
||||
|
@@ -36,6 +36,7 @@
|
||||
#include "editordocumenthandle.h"
|
||||
#include "modelmanagertesthelper.h"
|
||||
|
||||
#include <coreplugin/documentmanager.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/fileutils.h>
|
||||
#include <coreplugin/testdatadir.h>
|
||||
@@ -43,6 +44,7 @@
|
||||
#include <projectexplorer/session.h>
|
||||
|
||||
#include <cplusplus/LookupContext.h>
|
||||
#include <utils/executeondestruction.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
|
||||
#include <QDebug>
|
||||
@@ -1107,6 +1109,69 @@ void CppToolsPlugin::test_modelmanager_renameIncludes()
|
||||
QCOMPARE(snapshot.allIncludesForDocument(sourceFile), QSet<QString>() << newHeader);
|
||||
}
|
||||
|
||||
void CppToolsPlugin::test_modelmanager_renameIncludesInEditor()
|
||||
{
|
||||
struct ModelManagerGCHelper {
|
||||
~ModelManagerGCHelper() { CppModelManager::instance()->GC(); }
|
||||
} GCHelper;
|
||||
Q_UNUSED(GCHelper); // do not warn about being unused
|
||||
|
||||
TemporaryDir tmpDir;
|
||||
QVERIFY(tmpDir.isValid());
|
||||
|
||||
const QDir workingDir(tmpDir.path());
|
||||
const QStringList fileNames = QStringList() << _("foo.h") << _("foo.cpp") << _("main.cpp");
|
||||
const QString oldHeader(workingDir.filePath(_("foo.h")));
|
||||
const QString newHeader(workingDir.filePath(_("bar.h")));
|
||||
const QString mainFile(workingDir.filePath(_("main.cpp")));
|
||||
CppModelManager *modelManager = CppModelManager::instance();
|
||||
const MyTestDataDir testDir(_("testdata_project1"));
|
||||
|
||||
ModelManagerTestHelper helper;
|
||||
helper.resetRefreshedSourceFiles();
|
||||
|
||||
// Copy test files to a temporary directory
|
||||
QSet<QString> sourceFiles;
|
||||
foreach (const QString &fileName, fileNames) {
|
||||
const QString &file = workingDir.filePath(fileName);
|
||||
QVERIFY(QFile::copy(testDir.file(fileName), file));
|
||||
// Saving source file names for the model manager update,
|
||||
// so we can update just the relevant files.
|
||||
if (ProjectFile::classify(file) == ProjectFile::CXXSource)
|
||||
sourceFiles.insert(file);
|
||||
}
|
||||
|
||||
// Update the c++ model manager and check for the old includes
|
||||
modelManager->updateSourceFiles(sourceFiles).waitForFinished();
|
||||
QCoreApplication::processEvents();
|
||||
CPlusPlus::Snapshot snapshot = modelManager->snapshot();
|
||||
foreach (const QString &sourceFile, sourceFiles)
|
||||
QCOMPARE(snapshot.allIncludesForDocument(sourceFile), QSet<QString>() << oldHeader);
|
||||
|
||||
// Open a file in the editor
|
||||
QCOMPARE(Core::DocumentModel::openedDocuments().size(), 0);
|
||||
Core::IEditor *editor = Core::EditorManager::openEditor(mainFile);
|
||||
QVERIFY(editor);
|
||||
EditorCloser editorCloser(editor);
|
||||
Utils::ExecuteOnDestruction saveAllFiles([](){
|
||||
Core::DocumentManager::saveAllModifiedDocumentsSilently();
|
||||
});
|
||||
QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1);
|
||||
QVERIFY(modelManager->isCppEditor(editor));
|
||||
QVERIFY(modelManager->workingCopy().contains(mainFile));
|
||||
|
||||
// Renaming the header
|
||||
QVERIFY(Core::FileUtils::renameFile(oldHeader, newHeader));
|
||||
|
||||
// Update the c++ model manager again and check for the new includes
|
||||
TestCase::waitForProcessedEditorDocument(mainFile);
|
||||
modelManager->updateSourceFiles(sourceFiles).waitForFinished();
|
||||
QCoreApplication::processEvents();
|
||||
snapshot = modelManager->snapshot();
|
||||
foreach (const QString &sourceFile, sourceFiles)
|
||||
QCOMPARE(snapshot.allIncludesForDocument(sourceFile), QSet<QString>() << newHeader);
|
||||
}
|
||||
|
||||
void CppToolsPlugin::test_modelmanager_documentsAndRevisions()
|
||||
{
|
||||
TestCase helper;
|
||||
|
@@ -79,7 +79,6 @@ public:
|
||||
QSharedPointer<CppCodeModelSettings> codeModelSettings() const;
|
||||
|
||||
static StringTable &stringTable();
|
||||
|
||||
public slots:
|
||||
void switchHeaderSource();
|
||||
void switchHeaderSourceInNextSplit();
|
||||
@@ -158,6 +157,7 @@ private slots:
|
||||
void test_modelmanager_updateEditorsAfterProjectUpdate();
|
||||
void test_modelmanager_precompiled_headers();
|
||||
void test_modelmanager_renameIncludes();
|
||||
void test_modelmanager_renameIncludesInEditor();
|
||||
void test_modelmanager_documentsAndRevisions();
|
||||
|
||||
void test_cpplocatorfilters_CppLocatorFilter();
|
||||
|
@@ -1,4 +1,32 @@
|
||||
// Copyright header
|
||||
/****************************************************************************
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "foo.h"
|
||||
|
||||
|
Reference in New Issue
Block a user