forked from qt-creator/qt-creator
CppTools: Do not wait in GUI thread for the parsed document
...when collecting data for the semantic highlighting recalculation. Task-number: QTCREATORBUG-11037 Change-Id: Ibed73a2916df0a91aedef166de2c8c6bb5df309c Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
committed by
Erik Verbruggen
parent
0e8ec18561
commit
e7904caf0b
@@ -261,10 +261,10 @@ CppCompletionAssistProvider *CppEditorSupport::completionAssistProvider() const
|
||||
|
||||
QSharedPointer<SnapshotUpdater> CppEditorSupport::snapshotUpdater()
|
||||
{
|
||||
QSharedPointer<SnapshotUpdater> updater = m_snapshotUpdater;
|
||||
QSharedPointer<SnapshotUpdater> updater = snapshotUpdater_internal();
|
||||
if (!updater || updater->fileInEditor() != fileName()) {
|
||||
updater = QSharedPointer<SnapshotUpdater>(new SnapshotUpdater(fileName()));
|
||||
m_snapshotUpdater = updater;
|
||||
setSnapshotUpdater_internal(updater);
|
||||
|
||||
QSharedPointer<CppCodeModelSettings> cms = CppToolsPlugin::instance()->codeModelSettings();
|
||||
updater->setUsePrecompiledHeaders(cms->pchUsage() != CppCodeModelSettings::PchUse_None);
|
||||
@@ -518,14 +518,12 @@ SemanticInfo::Source CppEditorSupport::currentSource(bool force)
|
||||
int line = 0, column = 0;
|
||||
m_textEditor->convertPosition(m_textEditor->editorWidget()->position(), &line, &column);
|
||||
|
||||
const Snapshot snapshot = snapshotUpdater()->snapshot();
|
||||
|
||||
QByteArray code;
|
||||
if (force || m_lastSemanticInfo.revision != editorRevision())
|
||||
code = contents(); // get the source code only when needed.
|
||||
|
||||
const unsigned revision = editorRevision();
|
||||
SemanticInfo::Source source(snapshot, fileName(), code, line, column, revision, force);
|
||||
SemanticInfo::Source source(Snapshot(), fileName(), code, line, column, revision, force);
|
||||
return source;
|
||||
}
|
||||
|
||||
@@ -552,9 +550,13 @@ void CppEditorSupport::recalculateSemanticInfoNow(const SemanticInfo::Source &so
|
||||
}
|
||||
|
||||
if (semanticInfo.doc.isNull()) {
|
||||
semanticInfo.snapshot = source.snapshot;
|
||||
if (source.snapshot.contains(source.fileName)) {
|
||||
Document::Ptr doc = source.snapshot.preprocessedDocument(source.code, source.fileName);
|
||||
const QSharedPointer<SnapshotUpdater> snapshotUpdater = snapshotUpdater_internal();
|
||||
QTC_ASSERT(snapshotUpdater, return);
|
||||
semanticInfo.snapshot = snapshotUpdater->snapshot();
|
||||
|
||||
if (semanticInfo.snapshot.contains(source.fileName)) {
|
||||
Document::Ptr doc = semanticInfo.snapshot.preprocessedDocument(source.code,
|
||||
source.fileName);
|
||||
if (processor)
|
||||
doc->control()->setTopLevelDeclarationProcessor(processor);
|
||||
doc->check();
|
||||
@@ -593,6 +595,18 @@ void CppEditorSupport::recalculateSemanticInfoDetached_helper(QFutureInterface<v
|
||||
recalculateSemanticInfoNow(source, true, &processor);
|
||||
}
|
||||
|
||||
QSharedPointer<SnapshotUpdater> CppEditorSupport::snapshotUpdater_internal() const
|
||||
{
|
||||
QMutexLocker locker(&m_snapshotUpdaterLock);
|
||||
return m_snapshotUpdater;
|
||||
}
|
||||
|
||||
void CppEditorSupport::setSnapshotUpdater_internal(const QSharedPointer<SnapshotUpdater> &updater)
|
||||
{
|
||||
QMutexLocker locker(&m_snapshotUpdaterLock);
|
||||
m_snapshotUpdater = updater;
|
||||
}
|
||||
|
||||
void CppEditorSupport::onMimeTypeChanged()
|
||||
{
|
||||
m_highlighter.cancel();
|
||||
|
||||
@@ -197,6 +197,9 @@ private:
|
||||
void recalculateSemanticInfoDetached_helper(QFutureInterface<void> &future,
|
||||
SemanticInfo::Source source);
|
||||
|
||||
QSharedPointer<SnapshotUpdater> snapshotUpdater_internal() const;
|
||||
void setSnapshotUpdater_internal(const QSharedPointer<SnapshotUpdater> &updater);
|
||||
|
||||
private:
|
||||
Internal::CppModelManager *m_modelManager;
|
||||
QPointer<TextEditor::BaseTextEditor> m_textEditor;
|
||||
@@ -225,6 +228,7 @@ private:
|
||||
mutable QMutex m_lastSemanticInfoLock;
|
||||
SemanticInfo m_lastSemanticInfo;
|
||||
QFuture<void> m_futureSemanticInfo;
|
||||
mutable QMutex m_snapshotUpdaterLock;
|
||||
QSharedPointer<SnapshotUpdater> m_snapshotUpdater;
|
||||
|
||||
// Highlighting:
|
||||
|
||||
Reference in New Issue
Block a user