Clang: Take over jobs if document's project changes

On registerProjectPartsForEditor() we recreated the affected
DocumentProcessors, but did not take care of the jobs that were in the
queue, which effectively could led to lost jobs. Catch up on this.

Task-number: QTCREATORBUG-18856
Change-Id: I4184e5dc6480667953f2d2081ccf39a28c092186
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
Nikolai Kosjar
2018-01-05 09:35:00 +01:00
parent dd06a4188d
commit 2d7f1d6c8c
16 changed files with 162 additions and 19 deletions

View File

@@ -28,6 +28,8 @@
#include "clangexceptions.h"
#include "projectpart.h"
#include <utils/algorithm.h>
namespace ClangBackEnd {
DocumentProcessors::DocumentProcessors(Documents &documents,
@@ -84,6 +86,25 @@ void DocumentProcessors::remove(const Document &document)
throw DocumentProcessorDoesNotExist(document.filePath(), document.projectPart().id());
}
void DocumentProcessors::reset(const Document &oldDocument, const Document &newDocument)
{
// Wait until the currently running jobs finish and remember the not yet
// processed job requests for the new processor...
JobRequests jobsToTakeOver = processor(oldDocument).stop();
// ...but do not take over irrelevant ones.
jobsToTakeOver = Utils::filtered(jobsToTakeOver, [](const JobRequest &job){
return job.isTakeOverable();
});
// Remove current processor
remove(oldDocument);
// Create new processor and take over not yet processed jobs.
DocumentProcessor newProcessor = create(newDocument);
for (const JobRequest &job : jobsToTakeOver)
newProcessor.addJob(job);
}
JobRequests DocumentProcessors::process()
{
JobRequests jobsStarted;