aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@qt.io>2018-06-05 13:05:47 +0200
committerNikolai Kosjar <nikolai.kosjar@qt.io>2018-06-08 06:32:40 +0000
commitcbd4d05423da34891abba5e0c7b51b646f3aa101 (patch)
treecc701c570740451dde8423151b8518b3bd86aa86
parentb30926cea4d6698b7ce4793799ab155f6434b8d2 (diff)
Clang: Fix processing documents if multiple are opened at once
Reproducable with 1. $ ./qtcreator a.cpp b.cpp 2. Switch to a.cpp => no highlighting Because ClangEditorDocumentProcessor does asynchronous processing, the backend might receive a DocumentsOpenedMessage where the document is not the current editor (happens for a.cpp in the example). When switching to that document, the initial jobs were not processed as the document was not dirty. Address this case by also checking for documents that have a revision of 1 and are not dirty. Unify adding the annotations jobs to ensure that not more than needed are run. Change-Id: I14030260842f97d58280235e763c8d7490705f8d Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
-rw-r--r--src/tools/clangbackend/source/clangcodemodelserver.cpp38
-rw-r--r--src/tools/clangbackend/source/clangcodemodelserver.h4
-rw-r--r--tests/unit/unittest/clangcodemodelserver-test.cpp15
3 files changed, 38 insertions, 19 deletions
diff --git a/src/tools/clangbackend/source/clangcodemodelserver.cpp b/src/tools/clangbackend/source/clangcodemodelserver.cpp
index a9932ddb9a3..49a8008aed9 100644
--- a/src/tools/clangbackend/source/clangcodemodelserver.cpp
+++ b/src/tools/clangbackend/source/clangcodemodelserver.cpp
@@ -61,7 +61,7 @@ ClangCodeModelServer::ClangCodeModelServer()
QObject::connect(&updateAnnotationsTimer,
&QTimer::timeout,
[this]() {
- processJobsForDirtyAndVisibleDocuments();
+ processJobsForVisibleDocuments();
});
updateVisibleButNotCurrentDocumentsTimer.setSingleShot(true);
@@ -180,7 +180,7 @@ void ClangCodeModelServer::projectPartsUpdated(const ProjectPartsUpdatedMessage
resetDocuments(toDocumentResetInfos(affectedDocuments));
- processJobsForDirtyAndVisibleDocuments();
+ processJobsForVisibleDocuments();
} catch (const std::exception &exception) {
qWarning() << "Error in ClangCodeModelServer::projectPartsUpdated:" << exception.what();
}
@@ -373,20 +373,30 @@ bool ClangCodeModelServer::isTimerRunningForTestOnly() const
return updateAnnotationsTimer.isActive();
}
-void ClangCodeModelServer::processJobsForDirtyAndVisibleDocuments()
+void ClangCodeModelServer::processJobsForVisibleDocuments()
{
- processJobsForDirtyCurrentDocument();
+ processJobsForCurrentDocument();
processTimerForVisibleButNotCurrentDocuments();
}
-void ClangCodeModelServer::processJobsForDirtyCurrentDocument()
+void ClangCodeModelServer::processJobsForCurrentDocument()
{
- auto currentDirtyDocuments = documents.filtered([](const Document &document) {
- return document.isDirty() && document.isUsedByCurrentEditor();
+ auto currentDocuments = documents.filtered([](const Document &document) {
+ return document.isUsedByCurrentEditor()
+ && (document.isDirty() || document.documentRevision() == 1);
});
- QTC_CHECK(currentDirtyDocuments.size() <= 1);
+ QTC_CHECK(currentDocuments.size() <= 1);
- addAndRunUpdateJobs(currentDirtyDocuments);
+ addAndRunUpdateJobs(currentDocuments);
+}
+
+static void addUpdateAnnotationsJobsAndProcess(DocumentProcessor &processor)
+{
+ processor.addJob(JobRequest::Type::UpdateAnnotations,
+ PreferredTranslationUnit::PreviouslyParsed);
+ processor.addJob(JobRequest::Type::UpdateExtraAnnotations,
+ PreferredTranslationUnit::RecentlyParsed);
+ processor.process();
}
void ClangCodeModelServer::addAndRunUpdateJobs(std::vector<Document> documents)
@@ -395,11 +405,7 @@ void ClangCodeModelServer::addAndRunUpdateJobs(std::vector<Document> documents)
DocumentProcessor processor = documentProcessors().processor(document);
// Run the regular edit-reparse-job
- processor.addJob(JobRequest::Type::UpdateAnnotations,
- PreferredTranslationUnit::PreviouslyParsed);
- processor.addJob(JobRequest::Type::UpdateExtraAnnotations,
- PreferredTranslationUnit::RecentlyParsed);
- processor.process();
+ addUpdateAnnotationsJobsAndProcess(processor);
// If requested, run jobs to increase the responsiveness of the document
if (useSupportiveTranslationUnit() && document.isResponsivenessIncreaseNeeded()) {
@@ -478,9 +484,7 @@ void ClangCodeModelServer::processInitialJobsForDocuments(const std::vector<Docu
{
for (const auto &document : documents) {
DocumentProcessor processor = documentProcessors().processor(document);
- processor.addJob(JobRequest::Type::UpdateAnnotations);
- processor.addJob(JobRequest::Type::UpdateExtraAnnotations);
- processor.process();
+ addUpdateAnnotationsJobsAndProcess(processor);
}
}
diff --git a/src/tools/clangbackend/source/clangcodemodelserver.h b/src/tools/clangbackend/source/clangcodemodelserver.h
index 706eadd6a69..be18093073e 100644
--- a/src/tools/clangbackend/source/clangcodemodelserver.h
+++ b/src/tools/clangbackend/source/clangcodemodelserver.h
@@ -84,8 +84,8 @@ public: // for tests
private:
void processInitialJobsForDocuments(const std::vector<Document> &documents);
- void processJobsForDirtyAndVisibleDocuments();
- void processJobsForDirtyCurrentDocument();
+ void processJobsForVisibleDocuments();
+ void processJobsForCurrentDocument();
void processTimerForVisibleButNotCurrentDocuments();
void processSuspendResumeJobs(const std::vector<Document> &documents);
diff --git a/tests/unit/unittest/clangcodemodelserver-test.cpp b/tests/unit/unittest/clangcodemodelserver-test.cpp
index ea4238975e3..bde56e21608 100644
--- a/tests/unit/unittest/clangcodemodelserver-test.cpp
+++ b/tests/unit/unittest/clangcodemodelserver-test.cpp
@@ -258,6 +258,21 @@ TEST_F(ClangCodeModelServerSlowTest, NoInitialAnnotationsForClosedDocument)
closeDocument(filePathA);
}
+TEST_F(ClangCodeModelServerSlowTest, AnnotationsForInitiallyNotVisibleDocument)
+{
+ const int expectedAnnotationsCount = 2;
+ updateProjectPart();
+ updateVisibilty(filePathA, filePathA);
+ expectAnnotations(expectedAnnotationsCount);
+ clangServer.documentsOpened( // Open document while another is still visible
+ DocumentsOpenedMessage({FileContainer(filePathB, projectPartId, Utf8String(), false, 1)},
+ filePathA, {filePathA}));
+ clangServer.unsavedFilesUpdated( // Invalidate added jobs
+ UnsavedFilesUpdatedMessage({FileContainer(Utf8StringLiteral("aFile"), Utf8String())}));
+
+ updateVisibilty(filePathB, filePathB);
+}
+
TEST_F(ClangCodeModelServerSlowTest, NoAnnotationsForClosedDocument)
{
const int expectedAnnotationsCount = AnnotationJobsMultiplier; // Only for registration.