Clang: Unregister file with project immediately on project close

Ensure that first the editors unregister with the removed project part,
then unregister the project part.

This makes testing and following the message logs easier.

It also fixes the following race condition:
 * Unload project of opened file
 * Immediately close the editor before a new project part is calculated
 ==> The editor is closed, but the translation unit is not properly
     unregistered.

Change-Id: I618930d221323435ba60ac6c051380bccc9fdaf1
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
This commit is contained in:
Nikolai Kosjar
2015-09-18 12:19:46 +02:00
parent 27991f2c8f
commit a5674be613
5 changed files with 51 additions and 11 deletions

View File

@@ -271,8 +271,49 @@ void ModelManagerSupportClang::onProjectPartsUpdated(ProjectExplorer::Project *p
void ModelManagerSupportClang::onProjectPartsRemoved(const QStringList &projectPartIds)
{
if (!projectPartIds.isEmpty())
if (!projectPartIds.isEmpty()) {
unregisterTranslationUnitsWithProjectParts(projectPartIds);
m_ipcCommunicator.unregisterProjectPartsForEditor(projectPartIds);
}
}
static QVector<ClangEditorDocumentProcessor *>
clangProcessorsWithProjectParts(const QStringList &projectPartIds)
{
QVector<ClangEditorDocumentProcessor *> result;
foreach (auto *editorDocument, cppModelManager()->cppEditorDocuments()) {
auto *processor = editorDocument->processor();
auto *clangProcessor = qobject_cast<ClangEditorDocumentProcessor *>(processor);
if (clangProcessor && clangProcessor->hasProjectPart()) {
if (projectPartIds.contains(clangProcessor->projectPart()->id()))
result.append(clangProcessor);
}
}
return result;
}
static QVector<ClangBackEnd::FileContainer>
processorToFileContainer(ClangEditorDocumentProcessor *processor)
{
QTC_ASSERT(processor, return QVector<ClangBackEnd::FileContainer>());
const QString filePath = processor->baseTextDocument()->filePath().toString();
const QString projectPartId = processor->projectPart()->id();
return {ClangBackEnd::FileContainer(filePath, projectPartId)};
}
void ModelManagerSupportClang::unregisterTranslationUnitsWithProjectParts(
const QStringList &projectPartIds)
{
const auto processors = clangProcessorsWithProjectParts(projectPartIds);
foreach (ClangEditorDocumentProcessor *processor, processors) {
m_ipcCommunicator.unregisterTranslationUnitsForEditor(processorToFileContainer(processor));
processor->clearProjectPart();
processor->run();
}
}
#ifdef QT_TESTLIB_LIB