diff --git a/src/tools/clangbackend/ipcsource/clangdocument.cpp b/src/tools/clangbackend/ipcsource/clangdocument.cpp index 49c1a3cef0a..344787bbac1 100644 --- a/src/tools/clangbackend/ipcsource/clangdocument.cpp +++ b/src/tools/clangbackend/ipcsource/clangdocument.cpp @@ -364,6 +364,11 @@ const QSet Document::dependedFilePaths() const return d->dependedFilePaths; } +void Document::setDependedFilePaths(const QSet &filePaths) +{ + d->dependedFilePaths = filePaths; +} + void Document::setDirty() { d->needsToBeReparsedChangeTimePoint = Clock::now(); diff --git a/src/tools/clangbackend/ipcsource/clangdocument.h b/src/tools/clangbackend/ipcsource/clangdocument.h index 91112e9cddc..ab6322eff1c 100644 --- a/src/tools/clangbackend/ipcsource/clangdocument.h +++ b/src/tools/clangbackend/ipcsource/clangdocument.h @@ -111,6 +111,7 @@ public: // for tests void parse() const; void reparse() const; const QSet dependedFilePaths() const; + void setDependedFilePaths(const QSet &filePaths); TranslationUnitUpdater createUpdater() const; void setHasParseOrReparseFailed(bool hasFailed); TimePoint isNeededReparseChangeTimePoint() const; diff --git a/src/tools/clangbackend/ipcsource/clangdocuments.cpp b/src/tools/clangbackend/ipcsource/clangdocuments.cpp index 3c77089447a..6888597a826 100644 --- a/src/tools/clangbackend/ipcsource/clangdocuments.cpp +++ b/src/tools/clangbackend/ipcsource/clangdocuments.cpp @@ -64,8 +64,12 @@ std::vector Documents::create(const QVector &fileContai std::vector createdDocuments; - for (const FileContainer &fileContainer : fileContainers) + for (const FileContainer &fileContainer : fileContainers) { + if (fileContainer.hasUnsavedFileContent()) + updateDocumentsWithChangedDependency(fileContainer.filePath()); + createdDocuments.push_back(createDocument(fileContainer)); + } return createdDocuments; } diff --git a/tests/unit/unittest/clangdocuments-test.cpp b/tests/unit/unittest/clangdocuments-test.cpp index d4a6a0b1e55..688d5ed32c7 100644 --- a/tests/unit/unittest/clangdocuments-test.cpp +++ b/tests/unit/unittest/clangdocuments-test.cpp @@ -73,6 +73,7 @@ protected: ClangBackEnd::UnsavedFiles unsavedFiles; ClangBackEnd::Documents documents{projects, unsavedFiles}; 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 nonExistingFilePath = Utf8StringLiteral("foo.cpp"); const Utf8String projectPartId = Utf8StringLiteral("projectPartId"); @@ -121,6 +122,18 @@ TEST_F(Documents, Add) 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() << filePath << otherFilePath); + + documents.create({fileContainerWithUnsavedContent}); + + ASSERT_TRUE(dependentDocument.isNeedingReparse()); +} + TEST_F(Documents, AddAndTestCreatedTranslationUnit) { ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u);