forked from qt-creator/qt-creator
Clang: Fix updating revision number for all translation units
Change-Id: I1ad305ed081aecadde968e041f7b99a24a1c4784 Reviewed-by: Marco Bubke <marco.bubke@qt.io> Reviewed-by: David Schulz <david.schulz@theqtcompany.com> Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -282,9 +282,10 @@ TranslationUnit TranslationUnits::createTranslationUnit(const FileContainer &fil
|
||||
|
||||
void TranslationUnits::updateTranslationUnit(const FileContainer &fileContainer)
|
||||
{
|
||||
auto findIterator = findAllTranslationUnitWithFilePath(fileContainer.filePath());
|
||||
if (findIterator != translationUnits_.end())
|
||||
findIterator->setDocumentRevision(fileContainer.documentRevision());
|
||||
const auto translationUnits = findAllTranslationUnitWithFilePath(fileContainer.filePath());
|
||||
|
||||
for (auto translationUnit : translationUnits)
|
||||
translationUnit.setDocumentRevision(fileContainer.documentRevision());
|
||||
}
|
||||
|
||||
std::vector<TranslationUnit>::iterator TranslationUnits::findTranslationUnit(const FileContainer &fileContainer)
|
||||
@@ -292,13 +293,19 @@ std::vector<TranslationUnit>::iterator TranslationUnits::findTranslationUnit(con
|
||||
return std::find(translationUnits_.begin(), translationUnits_.end(), fileContainer);
|
||||
}
|
||||
|
||||
std::vector<TranslationUnit>::iterator TranslationUnits::findAllTranslationUnitWithFilePath(const Utf8String &filePath)
|
||||
std::vector<TranslationUnit> TranslationUnits::findAllTranslationUnitWithFilePath(const Utf8String &filePath)
|
||||
{
|
||||
auto filePathCompare = [&filePath] (const TranslationUnit &translationUnit) {
|
||||
const auto filePathCompare = [&filePath] (const TranslationUnit &translationUnit) {
|
||||
return translationUnit.filePath() == filePath;
|
||||
};
|
||||
|
||||
return std::find_if(translationUnits_.begin(), translationUnits_.end(), filePathCompare);
|
||||
std::vector<TranslationUnit> translationUnits;
|
||||
std::copy_if(translationUnits_.begin(),
|
||||
translationUnits_.end(),
|
||||
std::back_inserter(translationUnits),
|
||||
filePathCompare);
|
||||
|
||||
return translationUnits;
|
||||
}
|
||||
|
||||
std::vector<TranslationUnit>::const_iterator TranslationUnits::findTranslationUnit(const Utf8String &filePath, const Utf8String &projectPartId) const
|
||||
|
@@ -94,7 +94,7 @@ private:
|
||||
TranslationUnit createTranslationUnit(const FileContainer &fileContainer);
|
||||
void updateTranslationUnit(const FileContainer &fileContainer);
|
||||
std::vector<TranslationUnit>::iterator findTranslationUnit(const FileContainer &fileContainer);
|
||||
std::vector<TranslationUnit>::iterator findAllTranslationUnitWithFilePath(const Utf8String &filePath);
|
||||
std::vector<TranslationUnit> findAllTranslationUnitWithFilePath(const Utf8String &filePath);
|
||||
std::vector<TranslationUnit>::const_iterator findTranslationUnit(const Utf8String &filePath, const Utf8String &projectPartId) const;
|
||||
bool hasTranslationUnit(const FileContainer &fileContainer) const;
|
||||
bool hasTranslationUnitWithFilePath(const Utf8String &filePath) const;
|
||||
|
@@ -99,6 +99,7 @@ protected:
|
||||
const Utf8String headerPath = Utf8StringLiteral(TESTDATA_DIR"/translationunits.h");
|
||||
const Utf8String nonExistingFilePath = Utf8StringLiteral("foo.cpp");
|
||||
const Utf8String projectPartId = Utf8StringLiteral("projectPartId");
|
||||
const Utf8String otherProjectPartId = Utf8StringLiteral("otherProjectPartId");
|
||||
const Utf8String nonExistingProjectPartId = Utf8StringLiteral("nonExistingProjectPartId");
|
||||
const ClangBackEnd::FileContainer fileContainer{filePath, projectPartId};
|
||||
const ClangBackEnd::FileContainer headerContainer{headerPath, projectPartId};
|
||||
@@ -178,7 +179,7 @@ TEST_F(TranslationUnits, ThrowForUpdatingANonExistingTranslationUnit)
|
||||
ClangBackEnd::TranslationUnitDoesNotExistException);
|
||||
}
|
||||
|
||||
TEST_F(TranslationUnits, Update)
|
||||
TEST_F(TranslationUnits, UpdateSingle)
|
||||
{
|
||||
ClangBackEnd::FileContainer createFileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
|
||||
ClangBackEnd::FileContainer updateFileContainer(filePath, Utf8String(), Utf8StringVector(), 75u);
|
||||
@@ -190,6 +191,21 @@ TEST_F(TranslationUnits, Update)
|
||||
IsTranslationUnit(filePath, projectPartId, 75u));
|
||||
}
|
||||
|
||||
TEST_F(TranslationUnits, UpdateMultiple)
|
||||
{
|
||||
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
|
||||
ClangBackEnd::FileContainer fileContainerWithOtherProject(filePath, otherProjectPartId, Utf8StringVector(), 74u);
|
||||
ClangBackEnd::FileContainer updatedFileContainer(filePath, Utf8String(), Utf8StringVector(), 75u);
|
||||
translationUnits.create({fileContainer, fileContainerWithOtherProject});
|
||||
|
||||
translationUnits.update({updatedFileContainer});
|
||||
|
||||
ASSERT_THAT(translationUnits.translationUnit(filePath, projectPartId),
|
||||
IsTranslationUnit(filePath, projectPartId, 75u));
|
||||
ASSERT_THAT(translationUnits.translationUnit(filePath, otherProjectPartId),
|
||||
IsTranslationUnit(filePath, otherProjectPartId, 75u));
|
||||
}
|
||||
|
||||
TEST_F(TranslationUnits, UpdateUnsavedFileAndCheckForReparse)
|
||||
{
|
||||
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
|
||||
@@ -509,6 +525,7 @@ TEST_F(TranslationUnits, SendDocumentAnnotationsAfterProjectPartChange)
|
||||
void TranslationUnits::SetUp()
|
||||
{
|
||||
projects.createOrUpdate({ProjectPartContainer(projectPartId)});
|
||||
projects.createOrUpdate({ProjectPartContainer(otherProjectPartId)});
|
||||
|
||||
auto callback = [&] (const DiagnosticsChangedMessage &, const HighlightingChangedMessage &) {
|
||||
mockSendDocumentAnnotationsCallback.sendDocumentAnnotations();
|
||||
|
Reference in New Issue
Block a user