Clang: Introduce DocumentParsed as job requirement

This is in prepration for a follow-up change, which introduces a state
where the Document is not yet parsed (it was reset) but the queue has
jobs.

All jobs get this requirement except those that generate an AST.

Change-Id: Ifcbb704e54108b40797180514c5ad3f3768ef10b
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
Nikolai Kosjar
2018-01-05 12:28:15 +01:00
parent 063b327097
commit e3b1259004
6 changed files with 30 additions and 2 deletions

View File

@@ -247,6 +247,12 @@ bool JobQueue::areRunConditionsMet(const JobRequest &request, const Document &do
}
}
if (conditions.testFlag(Condition::DocumentParsed)
&& !document.translationUnits().hasParsedTranslationUnit()) {
qCDebugJobs() << "Not choosing due to not yet parsed translation unit:" << request;
return false;
}
return true;
}

View File

@@ -156,6 +156,9 @@ static JobRequest::RunConditions conditionsForType(JobRequest::Type type)
if (type == Type::RequestReferences)
conditions |= Condition::CurrentDocumentRevision;
if (type != Type::UpdateDocumentAnnotations && type != Type::ParseSupportiveTranslationUnit)
conditions |= Condition::DocumentParsed;
return conditions;
}

View File

@@ -70,7 +70,8 @@ public:
DocumentNotVisible = 1 << 2,
DocumentSuspended = 1 << 3,
DocumentUnsuspended = 1 << 4,
CurrentDocumentRevision = 1 << 5,
DocumentParsed = 1 << 5,
CurrentDocumentRevision = 1 << 6,
};
Q_DECLARE_FLAGS(RunConditions, RunCondition)

View File

@@ -111,6 +111,13 @@ bool TranslationUnits::areAllTranslationUnitsParsed() const
});
}
bool TranslationUnits::hasParsedTranslationUnit() const
{
return Utils::anyOf(m_units, [](const TranslationUnitDataPtr &unit) {
return unit->parseTimePoint != TimePoint();
});
}
int TranslationUnits::size() const
{
return m_units.size();

View File

@@ -65,6 +65,7 @@ public:
void updateParseTimePoint(const Utf8String &translationUnitId, TimePoint timePoint);
bool areAllTranslationUnitsParsed() const;
bool hasParsedTranslationUnit() const;
public: // for tests
int size() const;

View File

@@ -66,6 +66,8 @@ protected:
PreferredTranslationUnit preferredTranslationUnit
= PreferredTranslationUnit::RecentlyParsed) const;
void pretendParsedTranslationUnit();
void updateDocumentRevision();
void updateUnsavedFiles();
void updateProject();
@@ -173,7 +175,7 @@ TEST_F(JobQueue, ProcessSingleJob)
TEST_F(JobQueue, ProcessUntilEmpty)
{
jobQueue.add(createJobRequest(filePath1, JobRequest::Type::UpdateDocumentAnnotations));
jobQueue.add(createJobRequest(filePath1, JobRequest::Type::CreateInitialDocumentPreamble));
jobQueue.add(createJobRequest(filePath1, JobRequest::Type::ParseSupportiveTranslationUnit));
JobRequests jobsToRun;
ASSERT_THAT(jobQueue.size(), Eq(2));
@@ -421,6 +423,7 @@ TEST_F(JobQueue, RequestCompleteCodeOutdatableByDocumentClose)
TEST_F(JobQueue, RequestCompleteCodeNotOutdatableByUnsavedFilesChange)
{
pretendParsedTranslationUnit();
jobQueue.add(createJobRequest(filePath1, JobRequest::Type::CompleteCode));
updateUnsavedFiles();
@@ -431,6 +434,7 @@ TEST_F(JobQueue, RequestCompleteCodeNotOutdatableByUnsavedFilesChange)
TEST_F(JobQueue, RequestCompleteCodeNotOutdatableByDocumentRevisionChange)
{
pretendParsedTranslationUnit();
jobQueue.add(createJobRequest(filePath1, JobRequest::Type::CompleteCode));
updateDocumentRevision();
@@ -461,6 +465,7 @@ TEST_F(JobQueue, RequestCompleteCodeOutdatableByDocumentRevisionChange)
TEST_F(JobQueue, RequestReferencesRunsForCurrentDocumentRevision)
{
pretendParsedTranslationUnit();
jobQueue.add(createJobRequest(filePath1, JobRequest::Type::RequestReferences));
const JobRequests jobsToStart = jobQueue.processQueue();
@@ -549,6 +554,11 @@ JobRequest JobQueue::createJobRequest(
return jobRequest;
}
void JobQueue::pretendParsedTranslationUnit()
{
document.translationUnits().updateParseTimePoint(document.translationUnit().id(), Clock::now());
}
void JobQueue::updateDocumentRevision()
{
documents.update({FileContainer(filePath1, projectPartId, Utf8String(), true, 1)});