From a85d5c7222dc131b885c7eaeb0a14f8d25299f2f Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Thu, 15 Sep 2016 14:38:42 +0200 Subject: [PATCH] Clang: Return updated documents Change-Id: Id4b1267914019ac56cdd132c6d597167a1f2b9a9 Reviewed-by: David Schulz --- .../clangbackend/ipcsource/clangdocuments.cpp | 14 +++++++++++--- src/tools/clangbackend/ipcsource/clangdocuments.h | 4 ++-- tests/unit/unittest/clangdocuments-test.cpp | 13 +++++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/tools/clangbackend/ipcsource/clangdocuments.cpp b/src/tools/clangbackend/ipcsource/clangdocuments.cpp index d85a0de49fd..6077505b573 100644 --- a/src/tools/clangbackend/ipcsource/clangdocuments.cpp +++ b/src/tools/clangbackend/ipcsource/clangdocuments.cpp @@ -68,14 +68,20 @@ std::vector Documents::create(const QVector &fileContai return createdDocuments; } -void Documents::update(const QVector &fileContainers) +std::vector Documents::update(const QVector &fileContainers) { checkIfDocumentsForFilePathsExist(fileContainers); + std::vector createdDocuments; + for (const FileContainer &fileContainer : fileContainers) { - updateDocument(fileContainer); + const std::vector documents = updateDocument(fileContainer); + createdDocuments.insert(createdDocuments.end(), documents.begin(), documents.end()); + updateDocumentsWithChangedDependency(fileContainer.filePath()); } + + return createdDocuments; } static bool removeFromFileContainer(QVector &fileContainers, const Document &document) @@ -205,12 +211,14 @@ Document Documents::createDocument(const FileContainer &fileContainer) return documents_.back(); } -void Documents::updateDocument(const FileContainer &fileContainer) +std::vector Documents::updateDocument(const FileContainer &fileContainer) { const auto documents = findAllDocumentsWithFilePath(fileContainer.filePath()); for (auto document : documents) document.setDocumentRevision(fileContainer.documentRevision()); + + return documents; } std::vector::iterator Documents::findDocument(const FileContainer &fileContainer) diff --git a/src/tools/clangbackend/ipcsource/clangdocuments.h b/src/tools/clangbackend/ipcsource/clangdocuments.h index 3af689145bd..90c905f16c4 100644 --- a/src/tools/clangbackend/ipcsource/clangdocuments.h +++ b/src/tools/clangbackend/ipcsource/clangdocuments.h @@ -45,7 +45,7 @@ public: Documents(ProjectParts &projectParts, UnsavedFiles &unsavedFiles); std::vector create(const QVector &fileContainers); - void update(const QVector &fileContainers); + std::vector update(const QVector &fileContainers); void remove(const QVector &fileContainers); void setUsedByCurrentEditor(const Utf8String &filePath); @@ -72,7 +72,7 @@ public: private: Document createDocument(const FileContainer &fileContainer); - void updateDocument(const FileContainer &fileContainer); + std::vector updateDocument(const FileContainer &fileContainer); std::vector::iterator findDocument(const FileContainer &fileContainer); std::vector findAllDocumentsWithFilePath(const Utf8String &filePath); std::vector::const_iterator findDocument(const Utf8String &filePath, const Utf8String &projectPartId) const; diff --git a/tests/unit/unittest/clangdocuments-test.cpp b/tests/unit/unittest/clangdocuments-test.cpp index 0be8c6281a2..58159924413 100644 --- a/tests/unit/unittest/clangdocuments-test.cpp +++ b/tests/unit/unittest/clangdocuments-test.cpp @@ -43,6 +43,7 @@ using ClangBackEnd::ProjectPartContainer; using testing::IsNull; using testing::NotNull; using testing::Gt; +using testing::Eq; using testing::Not; using testing::Contains; @@ -158,6 +159,18 @@ TEST_F(Documents, UpdateSingle) IsDocument(filePath, projectPartId, 75u)); } +TEST_F(Documents, UpdateReturnsUpdatedDocument) +{ + ClangBackEnd::FileContainer createFileContainer(filePath, projectPartId, Utf8StringVector(), 74u); + ClangBackEnd::FileContainer updateFileContainer(filePath, Utf8String(), Utf8StringVector(), 75u); + documents.create({createFileContainer}); + + const std::vector updatedDocuments = documents.update({updateFileContainer}); + + ASSERT_THAT(updatedDocuments.size(), Eq(1u)); + ASSERT_THAT(updatedDocuments.front().documentRevision(), Eq(75u)); +} + TEST_F(Documents, UpdateMultiple) { ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u);