Commit e7904caf authored by Nikolai Kosjar's avatar Nikolai Kosjar Committed by Erik Verbruggen

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's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent 0e8ec185
...@@ -261,10 +261,10 @@ CppCompletionAssistProvider *CppEditorSupport::completionAssistProvider() const ...@@ -261,10 +261,10 @@ CppCompletionAssistProvider *CppEditorSupport::completionAssistProvider() const
QSharedPointer<SnapshotUpdater> CppEditorSupport::snapshotUpdater() QSharedPointer<SnapshotUpdater> CppEditorSupport::snapshotUpdater()
{ {
QSharedPointer<SnapshotUpdater> updater = m_snapshotUpdater; QSharedPointer<SnapshotUpdater> updater = snapshotUpdater_internal();
if (!updater || updater->fileInEditor() != fileName()) { if (!updater || updater->fileInEditor() != fileName()) {
updater = QSharedPointer<SnapshotUpdater>(new SnapshotUpdater(fileName())); updater = QSharedPointer<SnapshotUpdater>(new SnapshotUpdater(fileName()));
m_snapshotUpdater = updater; setSnapshotUpdater_internal(updater);
QSharedPointer<CppCodeModelSettings> cms = CppToolsPlugin::instance()->codeModelSettings(); QSharedPointer<CppCodeModelSettings> cms = CppToolsPlugin::instance()->codeModelSettings();
updater->setUsePrecompiledHeaders(cms->pchUsage() != CppCodeModelSettings::PchUse_None); updater->setUsePrecompiledHeaders(cms->pchUsage() != CppCodeModelSettings::PchUse_None);
...@@ -518,14 +518,12 @@ SemanticInfo::Source CppEditorSupport::currentSource(bool force) ...@@ -518,14 +518,12 @@ SemanticInfo::Source CppEditorSupport::currentSource(bool force)
int line = 0, column = 0; int line = 0, column = 0;
m_textEditor->convertPosition(m_textEditor->editorWidget()->position(), &line, &column); m_textEditor->convertPosition(m_textEditor->editorWidget()->position(), &line, &column);
const Snapshot snapshot = snapshotUpdater()->snapshot();
QByteArray code; QByteArray code;
if (force || m_lastSemanticInfo.revision != editorRevision()) if (force || m_lastSemanticInfo.revision != editorRevision())
code = contents(); // get the source code only when needed. code = contents(); // get the source code only when needed.
const unsigned revision = editorRevision(); 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; return source;
} }
...@@ -552,9 +550,13 @@ void CppEditorSupport::recalculateSemanticInfoNow(const SemanticInfo::Source &so ...@@ -552,9 +550,13 @@ void CppEditorSupport::recalculateSemanticInfoNow(const SemanticInfo::Source &so
} }
if (semanticInfo.doc.isNull()) { if (semanticInfo.doc.isNull()) {
semanticInfo.snapshot = source.snapshot; const QSharedPointer<SnapshotUpdater> snapshotUpdater = snapshotUpdater_internal();
if (source.snapshot.contains(source.fileName)) { QTC_ASSERT(snapshotUpdater, return);
Document::Ptr doc = source.snapshot.preprocessedDocument(source.code, source.fileName); semanticInfo.snapshot = snapshotUpdater->snapshot();
if (semanticInfo.snapshot.contains(source.fileName)) {
Document::Ptr doc = semanticInfo.snapshot.preprocessedDocument(source.code,
source.fileName);
if (processor) if (processor)
doc->control()->setTopLevelDeclarationProcessor(processor); doc->control()->setTopLevelDeclarationProcessor(processor);
doc->check(); doc->check();
...@@ -593,6 +595,18 @@ void CppEditorSupport::recalculateSemanticInfoDetached_helper(QFutureInterface<v ...@@ -593,6 +595,18 @@ void CppEditorSupport::recalculateSemanticInfoDetached_helper(QFutureInterface<v
recalculateSemanticInfoNow(source, true, &processor); 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() void CppEditorSupport::onMimeTypeChanged()
{ {
m_highlighter.cancel(); m_highlighter.cancel();
......
...@@ -197,6 +197,9 @@ private: ...@@ -197,6 +197,9 @@ private:
void recalculateSemanticInfoDetached_helper(QFutureInterface<void> &future, void recalculateSemanticInfoDetached_helper(QFutureInterface<void> &future,
SemanticInfo::Source source); SemanticInfo::Source source);
QSharedPointer<SnapshotUpdater> snapshotUpdater_internal() const;
void setSnapshotUpdater_internal(const QSharedPointer<SnapshotUpdater> &updater);
private: private:
Internal::CppModelManager *m_modelManager; Internal::CppModelManager *m_modelManager;
QPointer<TextEditor::BaseTextEditor> m_textEditor; QPointer<TextEditor::BaseTextEditor> m_textEditor;
...@@ -225,6 +228,7 @@ private: ...@@ -225,6 +228,7 @@ private:
mutable QMutex m_lastSemanticInfoLock; mutable QMutex m_lastSemanticInfoLock;
SemanticInfo m_lastSemanticInfo; SemanticInfo m_lastSemanticInfo;
QFuture<void> m_futureSemanticInfo; QFuture<void> m_futureSemanticInfo;
mutable QMutex m_snapshotUpdaterLock;
QSharedPointer<SnapshotUpdater> m_snapshotUpdater; QSharedPointer<SnapshotUpdater> m_snapshotUpdater;
// Highlighting: // Highlighting:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment