Clang: Avoid access to a not yet created document processor

That could happen when registerTranslationUnitsForEditor is called with
visible documents that are not those that we are registering. In that
case, processSuspendResumeJobs() would request the not existing document
processor and throw an exception, thus preventing parse jobs.

Change-Id: I9e9aeefcb1fbb70ec0cfe21e1b2fc849286a8f0d
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
Nikolai Kosjar
2017-08-22 15:09:12 +02:00
parent 9a25e31ae8
commit 95b5477cc4

View File

@@ -87,6 +87,8 @@ void ClangCodeModelServer::registerTranslationUnitsForEditor(const ClangBackEnd:
try {
auto createdDocuments = documents.create(message.fileContainers());
for (const auto &document : createdDocuments)
documentProcessors().create(document);
unsavedFiles.createOrUpdate(message.fileContainers());
documents.setUsedByCurrentEditor(message.currentEditorFilePath());
documents.setVisibleInEditors(message.visibleEditorFilePaths());
@@ -364,7 +366,7 @@ void ClangCodeModelServer::processSuspendResumeJobs(const std::vector<Document>
void ClangCodeModelServer::processInitialJobsForDocuments(const std::vector<Document> &documents)
{
for (const auto &document : documents) {
DocumentProcessor processor = documentProcessors().create(document);
DocumentProcessor processor = documentProcessors().processor(document);
processor.addJob(JobRequest::Type::UpdateDocumentAnnotations);
processor.addJob(JobRequest::Type::CreateInitialDocumentPreamble);
processor.process();