Commit a85d5c72 authored by Nikolai Kosjar's avatar Nikolai Kosjar
Browse files

Clang: Return updated documents



Change-Id: Id4b1267914019ac56cdd132c6d597167a1f2b9a9
Reviewed-by: David Schulz's avatarDavid Schulz <david.schulz@qt.io>
parent 6ede503a
......@@ -68,14 +68,20 @@ std::vector<Document> Documents::create(const QVector<FileContainer> &fileContai
return createdDocuments;
}
void Documents::update(const QVector<FileContainer> &fileContainers)
std::vector<Document> Documents::update(const QVector<FileContainer> &fileContainers)
{
checkIfDocumentsForFilePathsExist(fileContainers);
std::vector<Document> createdDocuments;
for (const FileContainer &fileContainer : fileContainers) {
updateDocument(fileContainer);
const std::vector<Document> documents = updateDocument(fileContainer);
createdDocuments.insert(createdDocuments.end(), documents.begin(), documents.end());
updateDocumentsWithChangedDependency(fileContainer.filePath());
}
return createdDocuments;
}
static bool removeFromFileContainer(QVector<FileContainer> &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<Document> Documents::updateDocument(const FileContainer &fileContainer)
{
const auto documents = findAllDocumentsWithFilePath(fileContainer.filePath());
for (auto document : documents)
document.setDocumentRevision(fileContainer.documentRevision());
return documents;
}
std::vector<Document>::iterator Documents::findDocument(const FileContainer &fileContainer)
......
......@@ -45,7 +45,7 @@ public:
Documents(ProjectParts &projectParts, UnsavedFiles &unsavedFiles);
std::vector<Document> create(const QVector<FileContainer> &fileContainers);
void update(const QVector<FileContainer> &fileContainers);
std::vector<Document> update(const QVector<FileContainer> &fileContainers);
void remove(const QVector<FileContainer> &fileContainers);
void setUsedByCurrentEditor(const Utf8String &filePath);
......@@ -72,7 +72,7 @@ public:
private:
Document createDocument(const FileContainer &fileContainer);
void updateDocument(const FileContainer &fileContainer);
std::vector<Document> updateDocument(const FileContainer &fileContainer);
std::vector<Document>::iterator findDocument(const FileContainer &fileContainer);
std::vector<Document> findAllDocumentsWithFilePath(const Utf8String &filePath);
std::vector<Document>::const_iterator findDocument(const Utf8String &filePath, const Utf8String &projectPartId) const;
......
......@@ -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<Document> 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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment