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

Clang: Fix updating supportive translation unit



...with new project arguments.

Reproduce with:
 1. Open a file with some #ifdef
 2. Edit the file, e.g. type space.
 3. Change the build configuration so that the highlighting flips in the
    editor.
 4. Edit the file again, the configuration flips again [repeat].

Change-Id: Ib97c18fc46538d74c63972e682a348ae2736a4e6
Reviewed-by: David Schulz's avatarDavid Schulz <david.schulz@qt.io>
parent fda21898
......@@ -50,6 +50,7 @@
#include <updatetranslationunitsforeditormessage.h>
#include <updatevisibletranslationunitsmessage.h>
#include <utils/algorithm.h>
#include <utils/qtcassert.h>
#include <QCoreApplication>
......@@ -155,7 +156,16 @@ void ClangCodeModelServer::registerProjectPartsForEditor(const RegisterProjectPa
try {
projects.createOrUpdate(message.projectContainers());
documents.setDocumentsDirtyIfProjectPartChanged();
std::vector<Document> affectedDocuments = documents.setDocumentsDirtyIfProjectPartChanged();
for (Document &document : affectedDocuments) {
document.setResponsivenessIncreaseNeeded(document.isResponsivenessIncreased());
documentProcessors().remove(document);
document.translationUnits().removeAll();
document.translationUnits().createAndAppend();
documentProcessors().create(document);
}
processJobsForDirtyAndVisibleDocuments();
} catch (const std::exception &exception) {
......
......@@ -273,10 +273,14 @@ TimePoint Document::isDirtyTimeChangePoint() const
return d->isDirtyChangeTimePoint;
}
void Document::setDirtyIfProjectPartIsOutdated()
bool Document::setDirtyIfProjectPartIsOutdated()
{
if (isProjectPartOutdated())
if (isProjectPartOutdated()) {
setDirty();
return true;
}
return false;
}
void Document::setDirtyIfDependencyIsMet(const Utf8String &filePath)
......
......@@ -102,7 +102,7 @@ public:
bool isDirty() const;
TimePoint isDirtyTimeChangePoint() const;
void setDirtyIfProjectPartIsOutdated();
bool setDirtyIfProjectPartIsOutdated();
void setDirtyIfDependencyIsMet(const Utf8String &filePath);
TranslationUnitUpdateInput createUpdateInput() const;
......
......@@ -185,10 +185,16 @@ void Documents::updateDocumentsWithChangedDependencies(const QVector<FileContain
updateDocumentsWithChangedDependency(fileContainer.filePath());
}
void Documents::setDocumentsDirtyIfProjectPartChanged()
std::vector<Document> Documents::setDocumentsDirtyIfProjectPartChanged()
{
for (auto &document : documents_)
document.setDirtyIfProjectPartIsOutdated();
std::vector<Document> notDirtyBefore;
for (auto &document : documents_) {
if (!document.isDirty() && document.setDirtyIfProjectPartIsOutdated())
notDirtyBefore.push_back(document);
}
return notDirtyBefore;
}
QVector<FileContainer> Documents::newerFileContainers(const QVector<FileContainer> &fileContainers) const
......
......@@ -68,7 +68,7 @@ public:
void updateDocumentsWithChangedDependency(const Utf8String &filePath);
void updateDocumentsWithChangedDependencies(const QVector<FileContainer> &fileContainers);
void setDocumentsDirtyIfProjectPartChanged();
std::vector<Document> setDocumentsDirtyIfProjectPartChanged();
QVector<FileContainer> newerFileContainers(const QVector<FileContainer> &fileContainers) const;
......
......@@ -65,6 +65,11 @@ TranslationUnit TranslationUnits::createAndAppend()
return toTranslationUnit(m_units.last());
}
void TranslationUnits::removeAll()
{
m_units.clear();
}
TranslationUnit TranslationUnits::get(PreferredTranslationUnit type)
{
if (m_units.isEmpty())
......
......@@ -60,6 +60,7 @@ public:
TranslationUnits(const Utf8String &filePath);
TranslationUnit createAndAppend();
void removeAll();
TranslationUnit get(PreferredTranslationUnit type = PreferredTranslationUnit::RecentlyParsed);
void updateParseTimePoint(const Utf8String &translationUnitId, TimePoint timePoint);
......
......@@ -322,8 +322,9 @@ TEST_F(Document, SetDirtyIfProjectPartIsOutdated)
document.parse();
projects.createOrUpdate({ProjectPartContainer(projectPartId, {Utf8StringLiteral("-DNEW")})});
document.setDirtyIfProjectPartIsOutdated();
const bool wasOutdated = document.setDirtyIfProjectPartIsOutdated();
ASSERT_TRUE(wasOutdated);
ASSERT_TRUE(document.isDirty());
}
......@@ -331,8 +332,9 @@ TEST_F(DocumentSlowTest, SetNotDirtyIfProjectPartIsNotOutdated)
{
document.parse();
document.setDirtyIfProjectPartIsOutdated();
const bool wasOutdated = document.setDirtyIfProjectPartIsOutdated();
ASSERT_FALSE(wasOutdated);
ASSERT_FALSE(document.isDirty());
}
......
......@@ -402,6 +402,29 @@ TEST_F(Documents, IsNotVisibleEditorAfterBeingVisible)
ASSERT_FALSE(document.isVisibleInEditor());
}
TEST_F(Documents, SetDocumentsDirtyIfProjectPartChanged)
{
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
const auto createdDocuments = documents.create({fileContainer});
ClangBackEnd::FileContainer fileContainerWithOtherProject(filePath, otherProjectPartId, Utf8StringVector(), 74u);
documents.create({fileContainerWithOtherProject});
projects.createOrUpdate({ProjectPartContainer(projectPartId)});
const auto notDirtyBefore = documents.setDocumentsDirtyIfProjectPartChanged();
ASSERT_THAT(notDirtyBefore, createdDocuments);
}
TEST_F(Documents, SetDocumentsDirtyIfProjectPartChangedReturnsEmpty)
{
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
documents.create({fileContainer});
const auto notDirtyBefore = documents.setDocumentsDirtyIfProjectPartChanged();
ASSERT_TRUE(notDirtyBefore.empty());
}
void Documents::SetUp()
{
projects.createOrUpdate({ProjectPartContainer(projectPartId)});
......
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