forked from qt-creator/qt-creator
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 <david.schulz@qt.io>
This commit is contained in:
@@ -115,14 +115,18 @@ void ClangCodeModelServer::updateTranslationUnitsForEditor(const UpdateTranslati
|
|||||||
try {
|
try {
|
||||||
const auto newerFileContainers = documents.newerFileContainers(message.fileContainers());
|
const auto newerFileContainers = documents.newerFileContainers(message.fileContainers());
|
||||||
if (newerFileContainers.size() > 0) {
|
if (newerFileContainers.size() > 0) {
|
||||||
const std::vector<Document> updateDocuments = documents.update(newerFileContainers);
|
std::vector<Document> updateDocuments = documents.update(newerFileContainers);
|
||||||
unsavedFiles.createOrUpdate(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
|
// Start the jobs on the next event loop iteration since otherwise
|
||||||
// we might block the translation unit for a completion request
|
// we might block the translation unit for a completion request
|
||||||
// that comes right after this message.
|
// that comes right after this message.
|
||||||
updateDocumentAnnotationsTimer.start(0);
|
updateDocumentAnnotationsTimer.start(0);
|
||||||
delayStartInitializingSupportiveTranslationUnits(updateDocuments);
|
|
||||||
}
|
}
|
||||||
} catch (const std::exception &exception) {
|
} catch (const std::exception &exception) {
|
||||||
qWarning() << "Error in ClangCodeModelServer::updateTranslationUnitsForEditor:" << exception.what();
|
qWarning() << "Error in ClangCodeModelServer::updateTranslationUnitsForEditor:" << exception.what();
|
||||||
@@ -279,7 +283,7 @@ void ClangCodeModelServer::processJobsForDirtyAndVisibleDocuments()
|
|||||||
|
|
||||||
void ClangCodeModelServer::processJobsForDirtyCurrentDocument()
|
void ClangCodeModelServer::processJobsForDirtyCurrentDocument()
|
||||||
{
|
{
|
||||||
const auto currentDirtyDocuments = documents.filtered([](const Document &document) {
|
auto currentDirtyDocuments = documents.filtered([](const Document &document) {
|
||||||
return document.isDirty() && document.isUsedByCurrentEditor();
|
return document.isDirty() && document.isUsedByCurrentEditor();
|
||||||
});
|
});
|
||||||
QTC_CHECK(currentDirtyDocuments.size() <= 1);
|
QTC_CHECK(currentDirtyDocuments.size() <= 1);
|
||||||
@@ -287,13 +291,23 @@ void ClangCodeModelServer::processJobsForDirtyCurrentDocument()
|
|||||||
addAndRunUpdateJobs(currentDirtyDocuments);
|
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);
|
DocumentProcessor processor = documentProcessors().processor(document);
|
||||||
|
|
||||||
|
// Run the regular edit-reparse-job
|
||||||
processor.addJob(JobRequest::Type::UpdateDocumentAnnotations,
|
processor.addJob(JobRequest::Type::UpdateDocumentAnnotations,
|
||||||
PreferredTranslationUnit::PreviouslyParsed);
|
PreferredTranslationUnit::PreviouslyParsed);
|
||||||
processor.process();
|
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)
|
void ClangCodeModelServer::setUpdateDocumentAnnotationsTimeOutInMsForTestsOnly(int value)
|
||||||
{
|
{
|
||||||
updateDocumentAnnotationsTimeOutInMs = value;
|
updateDocumentAnnotationsTimeOutInMs = value;
|
||||||
|
|||||||
@@ -72,15 +72,12 @@ private:
|
|||||||
void startDocumentAnnotationsTimerIfFileIsNotOpenAsDocument(const Utf8String &filePath);
|
void startDocumentAnnotationsTimerIfFileIsNotOpenAsDocument(const Utf8String &filePath);
|
||||||
|
|
||||||
void processInitialJobsForDocuments(const std::vector<Document> &documents);
|
void processInitialJobsForDocuments(const std::vector<Document> &documents);
|
||||||
void delayStartInitializingSupportiveTranslationUnits(const std::vector<Document> &documents);
|
|
||||||
void startInitializingSupportiveTranslationUnits(const std::vector<Document> &documents);
|
|
||||||
|
|
||||||
void processJobsForDirtyAndVisibleDocuments();
|
void processJobsForDirtyAndVisibleDocuments();
|
||||||
void processJobsForDirtyCurrentDocument();
|
void processJobsForDirtyCurrentDocument();
|
||||||
void processTimerForVisibleButNotCurrentDocuments();
|
void processTimerForVisibleButNotCurrentDocuments();
|
||||||
void processJobsForDirtyAndVisibleButNotCurrentDocuments();
|
void processJobsForDirtyAndVisibleButNotCurrentDocuments();
|
||||||
|
|
||||||
void addAndRunUpdateJobs(const std::vector<Document> &documents);
|
void addAndRunUpdateJobs(std::vector<Document> documents);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ProjectParts projects;
|
ProjectParts projects;
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ public:
|
|||||||
bool hasParseOrReparseFailed = false;
|
bool hasParseOrReparseFailed = false;
|
||||||
bool isUsedByCurrentEditor = false;
|
bool isUsedByCurrentEditor = false;
|
||||||
bool isVisibleInEditor = false;
|
bool isVisibleInEditor = false;
|
||||||
|
bool increaseResponsiveness = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
DocumentData::DocumentData(const Utf8String &filePath,
|
DocumentData::DocumentData(const Utf8String &filePath,
|
||||||
@@ -213,6 +214,23 @@ void Document::setDocumentRevision(uint revision)
|
|||||||
d->documentRevision = 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
|
bool Document::isUsedByCurrentEditor() const
|
||||||
{
|
{
|
||||||
checkIfNull();
|
checkIfNull();
|
||||||
|
|||||||
@@ -90,6 +90,10 @@ public:
|
|||||||
uint documentRevision() const;
|
uint documentRevision() const;
|
||||||
void setDocumentRevision(uint revision);
|
void setDocumentRevision(uint revision);
|
||||||
|
|
||||||
|
bool isResponsivenessIncreased() const;
|
||||||
|
bool isResponsivenessIncreaseNeeded() const;
|
||||||
|
void setResponsivenessIncreaseNeeded(bool responsivenessIncreaseNeeded);
|
||||||
|
|
||||||
bool isUsedByCurrentEditor() const;
|
bool isUsedByCurrentEditor() const;
|
||||||
void setIsUsedByCurrentEditor(bool isUsedByCurrentEditor);
|
void setIsUsedByCurrentEditor(bool isUsedByCurrentEditor);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user