forked from qt-creator/qt-creator
Clang: Fix updating dependencies
...if the registered document comes with unsaved content. This can easily happen if the document is opened and modified by a refactoring action. Task-number: QTCREATORBUG-17295 Change-Id: I3a95fb495b6122248ceaa80985e838851ba2c0e5 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -364,6 +364,11 @@ const QSet<Utf8String> Document::dependedFilePaths() const
|
|||||||
return d->dependedFilePaths;
|
return d->dependedFilePaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Document::setDependedFilePaths(const QSet<Utf8String> &filePaths)
|
||||||
|
{
|
||||||
|
d->dependedFilePaths = filePaths;
|
||||||
|
}
|
||||||
|
|
||||||
void Document::setDirty()
|
void Document::setDirty()
|
||||||
{
|
{
|
||||||
d->needsToBeReparsedChangeTimePoint = Clock::now();
|
d->needsToBeReparsedChangeTimePoint = Clock::now();
|
||||||
|
|||||||
@@ -111,6 +111,7 @@ public: // for tests
|
|||||||
void parse() const;
|
void parse() const;
|
||||||
void reparse() const;
|
void reparse() const;
|
||||||
const QSet<Utf8String> dependedFilePaths() const;
|
const QSet<Utf8String> dependedFilePaths() const;
|
||||||
|
void setDependedFilePaths(const QSet<Utf8String> &filePaths);
|
||||||
TranslationUnitUpdater createUpdater() const;
|
TranslationUnitUpdater createUpdater() const;
|
||||||
void setHasParseOrReparseFailed(bool hasFailed);
|
void setHasParseOrReparseFailed(bool hasFailed);
|
||||||
TimePoint isNeededReparseChangeTimePoint() const;
|
TimePoint isNeededReparseChangeTimePoint() const;
|
||||||
|
|||||||
@@ -64,8 +64,12 @@ std::vector<Document> Documents::create(const QVector<FileContainer> &fileContai
|
|||||||
|
|
||||||
std::vector<Document> createdDocuments;
|
std::vector<Document> createdDocuments;
|
||||||
|
|
||||||
for (const FileContainer &fileContainer : fileContainers)
|
for (const FileContainer &fileContainer : fileContainers) {
|
||||||
|
if (fileContainer.hasUnsavedFileContent())
|
||||||
|
updateDocumentsWithChangedDependency(fileContainer.filePath());
|
||||||
|
|
||||||
createdDocuments.push_back(createDocument(fileContainer));
|
createdDocuments.push_back(createDocument(fileContainer));
|
||||||
|
}
|
||||||
|
|
||||||
return createdDocuments;
|
return createdDocuments;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ protected:
|
|||||||
ClangBackEnd::UnsavedFiles unsavedFiles;
|
ClangBackEnd::UnsavedFiles unsavedFiles;
|
||||||
ClangBackEnd::Documents documents{projects, unsavedFiles};
|
ClangBackEnd::Documents documents{projects, unsavedFiles};
|
||||||
const Utf8String filePath = Utf8StringLiteral(TESTDATA_DIR"/translationunits.cpp");
|
const Utf8String filePath = Utf8StringLiteral(TESTDATA_DIR"/translationunits.cpp");
|
||||||
|
const Utf8String otherFilePath = Utf8StringLiteral(TESTDATA_DIR"/translationunits.h");
|
||||||
const Utf8String headerPath = Utf8StringLiteral(TESTDATA_DIR"/translationunits.h");
|
const Utf8String headerPath = Utf8StringLiteral(TESTDATA_DIR"/translationunits.h");
|
||||||
const Utf8String nonExistingFilePath = Utf8StringLiteral("foo.cpp");
|
const Utf8String nonExistingFilePath = Utf8StringLiteral("foo.cpp");
|
||||||
const Utf8String projectPartId = Utf8StringLiteral("projectPartId");
|
const Utf8String projectPartId = Utf8StringLiteral("projectPartId");
|
||||||
@@ -121,6 +122,18 @@ TEST_F(Documents, Add)
|
|||||||
IsDocument(filePath, projectPartId, 74u));
|
IsDocument(filePath, projectPartId, 74u));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(Documents, CreateWithUnsavedContentSetsDependenciesDirty)
|
||||||
|
{
|
||||||
|
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
|
||||||
|
ClangBackEnd::FileContainer fileContainerWithUnsavedContent(otherFilePath, projectPartId, Utf8StringVector(), Utf8String(), true, 2u);
|
||||||
|
auto dependentDocument = documents.create({fileContainer}).at(0);
|
||||||
|
dependentDocument.setDependedFilePaths(QSet<Utf8String>() << filePath << otherFilePath);
|
||||||
|
|
||||||
|
documents.create({fileContainerWithUnsavedContent});
|
||||||
|
|
||||||
|
ASSERT_TRUE(dependentDocument.isNeedingReparse());
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(Documents, AddAndTestCreatedTranslationUnit)
|
TEST_F(Documents, AddAndTestCreatedTranslationUnit)
|
||||||
{
|
{
|
||||||
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
|
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
|
||||||
|
|||||||
Reference in New Issue
Block a user