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

Clang: Simplify triggering initialization of supportive translation unit



Use a flag to indicate whether a supportive translation unit should be
set up. It will be needed in a follow-up change, too.

Change-Id: I6858caa303fcd9dca9486607380240dd5895a14a
Reviewed-by: David Schulz's avatarDavid Schulz <david.schulz@qt.io>
parent 2a46b152
......@@ -115,14 +115,18 @@ void ClangCodeModelServer::updateTranslationUnitsForEditor(const UpdateTranslati
try {
const auto newerFileContainers = documents.newerFileContainers(message.fileContainers());
if (newerFileContainers.size() > 0) {
const std::vector<Document> updateDocuments = documents.update(newerFileContainers);
std::vector<Document> updateDocuments = documents.update(newerFileContainers);
unsavedFiles.createOrUpdate(newerFileContainers);
for (Document &document : updateDocuments) {
if (!document.isResponsivenessIncreased())
document.setResponsivenessIncreaseNeeded(true);
}
// Start the jobs on the next event loop iteration since otherwise
// we might block the translation unit for a completion request
// that comes right after this message.
updateDocumentAnnotationsTimer.start(0);
delayStartInitializingSupportiveTranslationUnits(updateDocuments);
}
} catch (const std::exception &exception) {
qWarning() << "Error in ClangCodeModelServer::updateTranslationUnitsForEditor:" << exception.what();
......@@ -279,7 +283,7 @@ void ClangCodeModelServer::processJobsForDirtyAndVisibleDocuments()
void ClangCodeModelServer::processJobsForDirtyCurrentDocument()
{
const auto currentDirtyDocuments = documents.filtered([](const Document &document) {
auto currentDirtyDocuments = documents.filtered([](const Document &document) {
return document.isDirty() && document.isUsedByCurrentEditor();
});
QTC_CHECK(currentDirtyDocuments.size() <= 1);
......@@ -287,13 +291,23 @@ void ClangCodeModelServer::processJobsForDirtyCurrentDocument()
addAndRunUpdateJobs(currentDirtyDocuments);
}
void ClangCodeModelServer::addAndRunUpdateJobs(const std::vector<Document> &documents)
void ClangCodeModelServer::addAndRunUpdateJobs(std::vector<Document> documents)
{
for (const auto &document : documents) {
for (auto &document : documents) {
DocumentProcessor processor = documentProcessors().processor(document);
// Run the regular edit-reparse-job
processor.addJob(JobRequest::Type::UpdateDocumentAnnotations,
PreferredTranslationUnit::PreviouslyParsed);
processor.process();
// If requested, run jobs to increase the responsiveness of the document
if (useSupportiveTranslationUnit() && document.isResponsivenessIncreaseNeeded()) {
QTC_CHECK(!document.isResponsivenessIncreased());
QTC_CHECK(!processor.hasSupportiveTranslationUnit());
document.setResponsivenessIncreaseNeeded(false);
processor.startInitializingSupportiveTranslationUnit();
}
}
}
......@@ -322,30 +336,6 @@ void ClangCodeModelServer::processInitialJobsForDocuments(const std::vector<Docu
}
}
void ClangCodeModelServer::delayStartInitializingSupportiveTranslationUnits(
const std::vector<Document> &documents)
{
if (useSupportiveTranslationUnit()) {
QTimer::singleShot(0, [this, documents](){
startInitializingSupportiveTranslationUnits(documents);
});
}
}
void ClangCodeModelServer::startInitializingSupportiveTranslationUnits(
const std::vector<Document> &documents)
{
for (const Document &document : documents) {
try {
DocumentProcessor processor = documentProcessors().processor(document);
if (!processor.hasSupportiveTranslationUnit())
processor.startInitializingSupportiveTranslationUnit();
} catch (const DocumentProcessorDoesNotExist &) {
// OK, document was already closed.
}
}
}
void ClangCodeModelServer::setUpdateDocumentAnnotationsTimeOutInMsForTestsOnly(int value)
{
updateDocumentAnnotationsTimeOutInMs = value;
......
......@@ -72,15 +72,12 @@ private:
void startDocumentAnnotationsTimerIfFileIsNotOpenAsDocument(const Utf8String &filePath);
void processInitialJobsForDocuments(const std::vector<Document> &documents);
void delayStartInitializingSupportiveTranslationUnits(const std::vector<Document> &documents);
void startInitializingSupportiveTranslationUnits(const std::vector<Document> &documents);
void processJobsForDirtyAndVisibleDocuments();
void processJobsForDirtyCurrentDocument();
void processTimerForVisibleButNotCurrentDocuments();
void processJobsForDirtyAndVisibleButNotCurrentDocuments();
void addAndRunUpdateJobs(const std::vector<Document> &documents);
void addAndRunUpdateJobs(std::vector<Document> documents);
private:
ProjectParts projects;
......
......@@ -77,6 +77,7 @@ public:
bool hasParseOrReparseFailed = false;
bool isUsedByCurrentEditor = false;
bool isVisibleInEditor = false;
bool increaseResponsiveness = false;
};
DocumentData::DocumentData(const Utf8String &filePath,
......@@ -213,6 +214,23 @@ void Document::setDocumentRevision(uint revision)
d->documentRevision = revision;
}
bool Document::isResponsivenessIncreased() const
{
return d->translationUnits.size() > 1;
}
bool Document::isResponsivenessIncreaseNeeded() const
{
checkIfNull();
return d->increaseResponsiveness;
}
void Document::setResponsivenessIncreaseNeeded(bool responsivenessIncreaseNeeded)
{
d->increaseResponsiveness = responsivenessIncreaseNeeded;
}
bool Document::isUsedByCurrentEditor() const
{
checkIfNull();
......
......@@ -90,6 +90,10 @@ public:
uint documentRevision() const;
void setDocumentRevision(uint revision);
bool isResponsivenessIncreased() const;
bool isResponsivenessIncreaseNeeded() const;
void setResponsivenessIncreaseNeeded(bool responsivenessIncreaseNeeded);
bool isUsedByCurrentEditor() const;
void setIsUsedByCurrentEditor(bool isUsedByCurrentEditor);
......
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