C++: Move preprocessor settings handling to the document.

This cleans up the handling of those settings, and makes sure that the
C++ document is setting those settings before parsing. This also
prevents lock contention in the parser, because before this patch the
document would kick of the initial parse (after opening a document),
after which the editor would come in and try to set the preprocessor
settings, resulting in the UI thread locking until the initial parse was
done.

Change-Id: Ia2e18a9667e10279f045c1c5849046ec4cfe85ae
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
Erik Verbruggen
2014-09-09 16:02:31 +02:00
committed by Nikolai Kosjar
parent 914adeab82
commit cc6a9babe0
5 changed files with 52 additions and 37 deletions

View File

@@ -32,6 +32,7 @@
#include "cppeditorconstants.h"
#include "cpphighlighter.h"
#include <cpptools/baseeditordocumentparser.h>
#include <cpptools/builtineditordocumentprocessor.h>
#include <cpptools/cppcodeformatter.h>
#include <cpptools/cppcodemodelsettings.h>
@@ -40,6 +41,8 @@
#include <cpptools/cpptoolsconstants.h>
#include <cpptools/cpptoolsplugin.h>
#include <projectexplorer/session.h>
#include <utils/qtcassert.h>
#include <utils/runextensions.h>
@@ -206,6 +209,7 @@ void CppEditorDocument::onFilePathChanged(const QString &oldPath, const QString
m_editorDocumentHandle.reset(new CppEditorDocumentHandle(this));
resetProcessor();
updatePreprocessorSettings();
m_processorRevision = document()->revision();
processDocument();
}
@@ -237,6 +241,34 @@ void CppEditorDocument::resetProcessor()
processor(); // creates a new processor
}
void CppEditorDocument::updatePreprocessorSettings()
{
if (filePath().isEmpty())
return;
const QString prefix = QLatin1String(Constants::CPP_PREPROCESSOR_PROJECT_PREFIX);
const QString &projectFile = ProjectExplorer::SessionManager::value(
prefix + filePath()).toString();
const QString directivesKey = projectFile + QLatin1Char(',') + filePath();
const QByteArray additionalDirectives = ProjectExplorer::SessionManager::value(
directivesKey).toString().toUtf8();
setPreprocessorSettings(mm()->projectPartForProjectFile(projectFile), additionalDirectives);
}
void CppEditorDocument::setPreprocessorSettings(const CppTools::ProjectPart::Ptr &projectPart,
const QByteArray &defines)
{
CppTools::BaseEditorDocumentParser *parser = processor()->parser();
QTC_ASSERT(parser, return);
if (parser->projectPart() != projectPart || parser->editorDefines() != defines) {
parser->setProjectPart(projectPart);
parser->setEditorDefines(defines);
emit preprocessorSettingsChanged(!defines.trimmed().isEmpty());
}
}
unsigned CppEditorDocument::contentsRevision() const
{
return document()->revision();