Clang: Rename reparseNeeded to isDirty

...because the flag can be set for needed parses, too.

Change-Id: I8b328afefb282cb6bd1cf88711af3d08a56808db
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Nikolai Kosjar
2017-05-03 10:10:50 +02:00
parent e811ac4bfe
commit b9c76d5218
7 changed files with 43 additions and 41 deletions

View File

@@ -283,7 +283,7 @@ void ClangCodeModelServer::processJobsForDirtyAndVisibleDocuments()
void ClangCodeModelServer::processJobsForDirtyCurrentDocument() void ClangCodeModelServer::processJobsForDirtyCurrentDocument()
{ {
const auto currentDirtyDocuments = documents.filtered([](const Document &document) { const auto currentDirtyDocuments = documents.filtered([](const Document &document) {
return document.isNeedingReparse() && document.isUsedByCurrentEditor(); return document.isDirty() && document.isUsedByCurrentEditor();
}); });
QTC_CHECK(currentDirtyDocuments.size() <= 1); QTC_CHECK(currentDirtyDocuments.size() <= 1);

View File

@@ -70,9 +70,11 @@ public:
QSet<Utf8String> dependedFilePaths; QSet<Utf8String> dependedFilePaths;
uint documentRevision = 0; uint documentRevision = 0;
TimePoint needsToBeReparsedChangeTimePoint;
TimePoint isDirtyChangeTimePoint;
bool isDirty = false;
bool hasParseOrReparseFailed = false; bool hasParseOrReparseFailed = false;
bool needsToBeReparsed = false;
bool isUsedByCurrentEditor = false; bool isUsedByCurrentEditor = false;
bool isVisibleInEditor = false; bool isVisibleInEditor = false;
}; };
@@ -87,7 +89,7 @@ DocumentData::DocumentData(const Utf8String &filePath,
projectPart(projectPart), projectPart(projectPart),
lastProjectPartChangeTimePoint(Clock::now()), lastProjectPartChangeTimePoint(Clock::now()),
translationUnits(filePath), translationUnits(filePath),
needsToBeReparsedChangeTimePoint(lastProjectPartChangeTimePoint) isDirtyChangeTimePoint(lastProjectPartChangeTimePoint)
{ {
dependedFilePaths.insert(filePath); dependedFilePaths.insert(filePath);
translationUnits.createAndAppend(); translationUnits.createAndAppend();
@@ -239,18 +241,18 @@ void Document::setIsVisibleInEditor(bool isVisibleInEditor)
d->isVisibleInEditor = isVisibleInEditor; d->isVisibleInEditor = isVisibleInEditor;
} }
TimePoint Document::isNeededReparseChangeTimePoint() const bool Document::isDirty() const
{ {
checkIfNull(); checkIfNull();
return d->needsToBeReparsedChangeTimePoint; return d->isDirty;
} }
bool Document::isNeedingReparse() const TimePoint Document::isDirtyTimeChangePoint() const
{ {
checkIfNull(); checkIfNull();
return d->needsToBeReparsed; return d->isDirtyChangeTimePoint;
} }
void Document::setDirtyIfProjectPartIsOutdated() void Document::setDirtyIfProjectPartIsOutdated()
@@ -269,8 +271,8 @@ TranslationUnitUpdateInput Document::createUpdateInput() const
{ {
TranslationUnitUpdateInput updateInput; TranslationUnitUpdateInput updateInput;
updateInput.parseNeeded = isProjectPartOutdated(); updateInput.parseNeeded = isProjectPartOutdated();
updateInput.reparseNeeded = isNeedingReparse(); updateInput.reparseNeeded = d->isDirty;
updateInput.needsToBeReparsedChangeTimePoint = d->needsToBeReparsedChangeTimePoint; updateInput.needsToBeReparsedChangeTimePoint = d->isDirtyChangeTimePoint;
updateInput.filePath = filePath(); updateInput.filePath = filePath();
updateInput.fileArguments = fileArguments(); updateInput.fileArguments = fileArguments();
updateInput.unsavedFiles = d->documents.unsavedFiles(); updateInput.unsavedFiles = d->documents.unsavedFiles();
@@ -302,7 +304,7 @@ void Document::incorporateUpdaterResult(const TranslationUnitUpdateResult &resul
{ {
d->hasParseOrReparseFailed = result.hasParseOrReparseFailed; d->hasParseOrReparseFailed = result.hasParseOrReparseFailed;
if (d->hasParseOrReparseFailed) { if (d->hasParseOrReparseFailed) {
d->needsToBeReparsed = false; d->isDirty = false;
return; return;
} }
@@ -319,8 +321,8 @@ void Document::incorporateUpdaterResult(const TranslationUnitUpdateResult &resul
d->documents.addWatchedFiles(d->dependedFilePaths); d->documents.addWatchedFiles(d->dependedFilePaths);
if (result.hasReparsed() if (result.hasReparsed()
&& result.needsToBeReparsedChangeTimePoint == d->needsToBeReparsedChangeTimePoint) { && result.needsToBeReparsedChangeTimePoint == d->isDirtyChangeTimePoint) {
d->needsToBeReparsed = false; d->isDirty = false;
} }
} }
@@ -371,8 +373,8 @@ void Document::setDependedFilePaths(const QSet<Utf8String> &filePaths)
void Document::setDirty() void Document::setDirty()
{ {
d->needsToBeReparsedChangeTimePoint = Clock::now(); d->isDirtyChangeTimePoint = Clock::now();
d->needsToBeReparsed = true; d->isDirty = true;
} }
void Document::checkIfNull() const void Document::checkIfNull() const

View File

@@ -96,7 +96,8 @@ public:
bool isVisibleInEditor() const; bool isVisibleInEditor() const;
void setIsVisibleInEditor(bool isVisibleInEditor); void setIsVisibleInEditor(bool isVisibleInEditor);
bool isNeedingReparse() const; bool isDirty() const;
TimePoint isDirtyTimeChangePoint() const;
void setDirtyIfProjectPartIsOutdated(); void setDirtyIfProjectPartIsOutdated();
void setDirtyIfDependencyIsMet(const Utf8String &filePath); void setDirtyIfDependencyIsMet(const Utf8String &filePath);
@@ -114,7 +115,6 @@ public: // for tests
void setDependedFilePaths(const QSet<Utf8String> &filePaths); void setDependedFilePaths(const QSet<Utf8String> &filePaths);
TranslationUnitUpdater createUpdater() const; TranslationUnitUpdater createUpdater() const;
void setHasParseOrReparseFailed(bool hasFailed); void setHasParseOrReparseFailed(bool hasFailed);
TimePoint isNeededReparseChangeTimePoint() const;
private: private:
void setDirty(); void setDirty();

View File

@@ -157,7 +157,7 @@ const std::vector<Document> Documents::filtered(const IsMatchingDocument &isMatc
std::vector<Document> Documents::dirtyAndVisibleButNotCurrentDocuments() const std::vector<Document> Documents::dirtyAndVisibleButNotCurrentDocuments() const
{ {
return filtered([](const Document &document) { return filtered([](const Document &document) {
return document.isNeedingReparse() return document.isDirty()
&& document.isVisibleInEditor() && document.isVisibleInEditor()
&& !document.isUsedByCurrentEditor(); && !document.isUsedByCurrentEditor();
}); });

View File

@@ -213,12 +213,12 @@ TEST_F(Document, DeletedFileShouldNotNeedReparsing)
document.setDirtyIfDependencyIsMet(document.filePath()); document.setDirtyIfDependencyIsMet(document.filePath());
ASSERT_FALSE(document.isNeedingReparse()); ASSERT_FALSE(document.isDirty());
} }
TEST_F(Document, NeedsNoReparseAfterCreation) TEST_F(Document, NeedsNoReparseAfterCreation)
{ {
ASSERT_FALSE(document.isNeedingReparse()); ASSERT_FALSE(document.isDirty());
} }
TEST_F(DocumentSlowTest, NeedsReparseAfterChangeOfMainFile) TEST_F(DocumentSlowTest, NeedsReparseAfterChangeOfMainFile)
@@ -227,7 +227,7 @@ TEST_F(DocumentSlowTest, NeedsReparseAfterChangeOfMainFile)
document.setDirtyIfDependencyIsMet(documentFilePath); document.setDirtyIfDependencyIsMet(documentFilePath);
ASSERT_TRUE(document.isNeedingReparse()); ASSERT_TRUE(document.isDirty());
} }
TEST_F(DocumentSlowTest, NoNeedForReparsingForIndependendFile) TEST_F(DocumentSlowTest, NoNeedForReparsingForIndependendFile)
@@ -236,7 +236,7 @@ TEST_F(DocumentSlowTest, NoNeedForReparsingForIndependendFile)
document.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/otherfiles.h")); document.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/otherfiles.h"));
ASSERT_FALSE(document.isNeedingReparse()); ASSERT_FALSE(document.isDirty());
} }
TEST_F(DocumentSlowTest, NeedsReparsingForDependendFile) TEST_F(DocumentSlowTest, NeedsReparsingForDependendFile)
@@ -245,7 +245,7 @@ TEST_F(DocumentSlowTest, NeedsReparsingForDependendFile)
document.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/translationunits.h")); document.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/translationunits.h"));
ASSERT_TRUE(document.isNeedingReparse()); ASSERT_TRUE(document.isDirty());
} }
TEST_F(DocumentSlowTest, NeedsNoReparsingAfterReparsing) TEST_F(DocumentSlowTest, NeedsNoReparsingAfterReparsing)
@@ -255,7 +255,7 @@ TEST_F(DocumentSlowTest, NeedsNoReparsingAfterReparsing)
document.reparse(); document.reparse();
ASSERT_FALSE(document.isNeedingReparse()); ASSERT_FALSE(document.isDirty());
} }
TEST_F(DocumentSlowTest, IsIntactAfterParsing) TEST_F(DocumentSlowTest, IsIntactAfterParsing)
@@ -276,7 +276,7 @@ TEST_F(DocumentSlowTest, DoesNotNeedReparseAfterParse)
{ {
document.parse(); document.parse();
ASSERT_FALSE(document.isNeedingReparse()); ASSERT_FALSE(document.isDirty());
} }
TEST_F(DocumentSlowTest, NeedsReparseAfterMainFileChanged) TEST_F(DocumentSlowTest, NeedsReparseAfterMainFileChanged)
@@ -285,7 +285,7 @@ TEST_F(DocumentSlowTest, NeedsReparseAfterMainFileChanged)
document.setDirtyIfDependencyIsMet(documentFilePath); document.setDirtyIfDependencyIsMet(documentFilePath);
ASSERT_TRUE(document.isNeedingReparse()); ASSERT_TRUE(document.isDirty());
} }
TEST_F(DocumentSlowTest, NeedsReparseAfterIncludedFileChanged) TEST_F(DocumentSlowTest, NeedsReparseAfterIncludedFileChanged)
@@ -294,7 +294,7 @@ TEST_F(DocumentSlowTest, NeedsReparseAfterIncludedFileChanged)
document.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/translationunits.h")); document.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/translationunits.h"));
ASSERT_TRUE(document.isNeedingReparse()); ASSERT_TRUE(document.isDirty());
} }
TEST_F(DocumentSlowTest, DoesNotNeedReparseAfterNotIncludedFileChanged) TEST_F(DocumentSlowTest, DoesNotNeedReparseAfterNotIncludedFileChanged)
@@ -303,7 +303,7 @@ TEST_F(DocumentSlowTest, DoesNotNeedReparseAfterNotIncludedFileChanged)
document.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/otherfiles.h")); document.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/otherfiles.h"));
ASSERT_FALSE(document.isNeedingReparse()); ASSERT_FALSE(document.isDirty());
} }
TEST_F(DocumentSlowTest, DoesNotNeedReparseAfterReparse) TEST_F(DocumentSlowTest, DoesNotNeedReparseAfterReparse)
@@ -313,7 +313,7 @@ TEST_F(DocumentSlowTest, DoesNotNeedReparseAfterReparse)
document.reparse(); document.reparse();
ASSERT_FALSE(document.isNeedingReparse()); ASSERT_FALSE(document.isDirty());
} }
TEST_F(Document, SetDirtyIfProjectPartIsOutdated) TEST_F(Document, SetDirtyIfProjectPartIsOutdated)
@@ -324,7 +324,7 @@ TEST_F(Document, SetDirtyIfProjectPartIsOutdated)
document.setDirtyIfProjectPartIsOutdated(); document.setDirtyIfProjectPartIsOutdated();
ASSERT_TRUE(document.isNeedingReparse()); ASSERT_TRUE(document.isDirty());
} }
TEST_F(DocumentSlowTest, SetNotDirtyIfProjectPartIsNotOutdated) TEST_F(DocumentSlowTest, SetNotDirtyIfProjectPartIsNotOutdated)
@@ -333,7 +333,7 @@ TEST_F(DocumentSlowTest, SetNotDirtyIfProjectPartIsNotOutdated)
document.setDirtyIfProjectPartIsOutdated(); document.setDirtyIfProjectPartIsOutdated();
ASSERT_FALSE(document.isNeedingReparse()); ASSERT_FALSE(document.isDirty());
} }
TEST_F(Document, IncorporateUpdaterResultResetsDirtyness) TEST_F(Document, IncorporateUpdaterResultResetsDirtyness)
@@ -341,12 +341,12 @@ TEST_F(Document, IncorporateUpdaterResultResetsDirtyness)
document.setDirtyIfDependencyIsMet(document.filePath()); document.setDirtyIfDependencyIsMet(document.filePath());
TranslationUnitUpdateResult result; TranslationUnitUpdateResult result;
result.reparseTimePoint = Clock::now(); result.reparseTimePoint = Clock::now();
result.needsToBeReparsedChangeTimePoint = document.isNeededReparseChangeTimePoint(); result.needsToBeReparsedChangeTimePoint = document.isDirtyTimeChangePoint();
result.translationUnitId = document.translationUnit().id(); result.translationUnitId = document.translationUnit().id();
document.incorporateUpdaterResult(result); document.incorporateUpdaterResult(result);
ASSERT_FALSE(document.isNeedingReparse()); ASSERT_FALSE(document.isDirty());
} }
TEST_F(Document, IncorporateUpdaterResultDoesNotResetDirtynessIfItWasChanged) TEST_F(Document, IncorporateUpdaterResultDoesNotResetDirtynessIfItWasChanged)
@@ -359,7 +359,7 @@ TEST_F(Document, IncorporateUpdaterResultDoesNotResetDirtynessIfItWasChanged)
document.incorporateUpdaterResult(result); document.incorporateUpdaterResult(result);
ASSERT_TRUE(document.isNeedingReparse()); ASSERT_TRUE(document.isDirty());
} }
TEST_F(Document, IncorporateUpdaterResultUpdatesTranslationUnitsReparseTimePoint) TEST_F(Document, IncorporateUpdaterResultUpdatesTranslationUnitsReparseTimePoint)

View File

@@ -133,7 +133,7 @@ TEST_F(Documents, CreateWithUnsavedContentSetsDependenciesDirty)
documents.create({fileContainerWithUnsavedContent}); documents.create({fileContainerWithUnsavedContent});
ASSERT_TRUE(dependentDocument.isNeedingReparse()); ASSERT_TRUE(dependentDocument.isDirty());
} }
TEST_F(Documents, AddAndTestCreatedTranslationUnit) TEST_F(Documents, AddAndTestCreatedTranslationUnit)
@@ -212,7 +212,7 @@ TEST_F(DocumentsSlowTest, UpdateUnsavedFileAndCheckForReparse)
documents.update({headerContainerWithUnsavedContent}); documents.update({headerContainerWithUnsavedContent});
ASSERT_TRUE(documents.document(filePath, projectPartId).isNeedingReparse()); ASSERT_TRUE(documents.document(filePath, projectPartId).isDirty());
} }
TEST_F(DocumentsSlowTest, RemoveFileAndCheckForReparse) TEST_F(DocumentsSlowTest, RemoveFileAndCheckForReparse)
@@ -226,7 +226,7 @@ TEST_F(DocumentsSlowTest, RemoveFileAndCheckForReparse)
documents.remove({headerContainerWithUnsavedContent}); documents.remove({headerContainerWithUnsavedContent});
ASSERT_TRUE(documents.document(filePath, projectPartId).isNeedingReparse()); ASSERT_TRUE(documents.document(filePath, projectPartId).isDirty());
} }
TEST_F(Documents, DontGetNewerFileContainerIfRevisionIsTheSame) TEST_F(Documents, DontGetNewerFileContainerIfRevisionIsTheSame)

View File

@@ -60,13 +60,13 @@ MATCHER_P5(HasDirtyDocument,
filePath, filePath,
projectPartId, projectPartId,
documentRevision, documentRevision,
isNeedingReparse, isDirty,
hasNewDiagnostics, hasNewDiagnostics,
std::string(negation ? "isn't" : "is") std::string(negation ? "isn't" : "is")
+ " document with file path "+ PrintToString(filePath) + " document with file path "+ PrintToString(filePath)
+ " and project " + PrintToString(projectPartId) + " and project " + PrintToString(projectPartId)
+ " and document revision " + PrintToString(documentRevision) + " and document revision " + PrintToString(documentRevision)
+ " and isNeedingReparse = " + PrintToString(isNeedingReparse) + " and isDirty = " + PrintToString(isDirty)
+ " and hasNewDiagnostics = " + PrintToString(hasNewDiagnostics) + " and hasNewDiagnostics = " + PrintToString(hasNewDiagnostics)
) )
{ {
@@ -75,10 +75,10 @@ MATCHER_P5(HasDirtyDocument,
auto document = documents.document(filePath, projectPartId); auto document = documents.document(filePath, projectPartId);
if (document.documentRevision() == documentRevision) { if (document.documentRevision() == documentRevision) {
if (document.isNeedingReparse() && !isNeedingReparse) { if (document.isDirty() && !isDirty) {
*result_listener << "isNeedingReparse is true"; *result_listener << "isNeedingReparse is true";
return false; return false;
} else if (!document.isNeedingReparse() && isNeedingReparse) { } else if (!document.isDirty() && isDirty) {
*result_listener << "isNeedingReparse is false"; *result_listener << "isNeedingReparse is false";
return false; return false;
} }