From ba2d7a4fa7c29ea2d62da3d6f6835a091f604656 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Mon, 19 Aug 2013 16:05:29 +0200 Subject: C++: Only parse with appropriate defines for open editors. If two files from different (sub-)projects include the same header file, and the defined macros differ for both files, the header file will be parsed with only the appropriate macros for the including file. Task-number: QTCREATORBUG-9802 Task-number: QTCREATORBUG-1249 Change-Id: I560490afa287b3bb1e863bce1bb4f57af36ad56e Reviewed-by: Nikolai Kosjar --- src/plugins/cpptools/cpptoolseditorsupport.cpp | 37 +++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'src/plugins/cpptools/cpptoolseditorsupport.cpp') diff --git a/src/plugins/cpptools/cpptoolseditorsupport.cpp b/src/plugins/cpptools/cpptoolseditorsupport.cpp index fc4d64b3c9..c33a4241b9 100644 --- a/src/plugins/cpptools/cpptoolseditorsupport.cpp +++ b/src/plugins/cpptools/cpptoolseditorsupport.cpp @@ -169,6 +169,8 @@ QString CppEditorSupport::fileName() const QByteArray CppEditorSupport::contents() const { + QMutexLocker locker(&m_cachedContentsLock); + const int editorRev = editorRevision(); if (m_cachedContentsEditorRevision != editorRev && !m_fileIsBeingReloaded) { m_cachedContentsEditorRevision = editorRev; @@ -215,6 +217,13 @@ SemanticInfo CppEditorSupport::recalculateSemanticInfo(bool emitSignalWhenFinish return m_lastSemanticInfo; } +Document::Ptr CppEditorSupport::lastSemanticInfoDocument() const +{ + QMutexLocker locker(&m_lastSemanticInfoLock); + + return m_lastSemanticInfo.doc; +} + void CppEditorSupport::recalculateSemanticInfoDetached(bool force) { // Block premature calculation caused by CppEditorPlugin::currentEditorChanged @@ -236,6 +245,16 @@ CppCompletionAssistProvider *CppEditorSupport::completionAssistProvider() const return m_completionAssistProvider; } +QSharedPointer CppEditorSupport::snapshotUpdater() +{ + QSharedPointer updater = m_snapshotUpdater; + if (!updater) { + updater.reset(new SnapshotUpdater(fileName())); + m_snapshotUpdater = updater; + } + return updater; +} + void CppEditorSupport::updateDocument() { m_revision = editorRevision(); @@ -246,6 +265,19 @@ void CppEditorSupport::updateDocument() m_updateDocumentTimer->start(m_updateDocumentInterval); } +static void parse(QFutureInterface &future, CppEditorSupport *support) +{ + future.setProgressRange(0, 1); + + CppModelManager *cmm = qobject_cast(CppModelManager::instance()); + QSharedPointer updater = support->snapshotUpdater(); + + updater->update(cmm->workingCopy()); + cmm->finishedRefreshingSourceFiles(QStringList(updater->document()->fileName())); + + future.setProgressValue(1); +} + void CppEditorSupport::updateDocumentNow() { if (m_documentParser.isRunning() || m_revision != editorRevision()) { @@ -259,8 +291,7 @@ void CppEditorSupport::updateDocumentNow() if (m_highlightingSupport && !m_highlightingSupport->requiresSemanticInfo()) startHighlighting(); - const QStringList sourceFiles(m_textEditor->document()->filePath()); - m_documentParser = m_modelManager->updateSourceFiles(sourceFiles); + m_documentParser = QtConcurrent::run(&parse, this); } } @@ -429,7 +460,7 @@ SemanticInfo::Source CppEditorSupport::currentSource(bool force) int line = 0, column = 0; m_textEditor->convertPosition(m_textEditor->editorWidget()->position(), &line, &column); - const Snapshot snapshot = m_modelManager->snapshot(); + const Snapshot snapshot = m_snapshotUpdater->snapshot(); QByteArray code; if (force || m_lastSemanticInfo.revision != editorRevision()) -- cgit v1.2.1