summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@digia.com>2014-03-12 12:40:33 -0300
committerNikolai Kosjar <nikolai.kosjar@digia.com>2014-03-17 14:39:19 +0100
commit18e6be55d7260a6f21e0021d6eba7da002125ab2 (patch)
treedc6994e749b6c5396ab7e9bdf6ea9ba90574173c
parent1f0fd959fa9c8f4de6b448671ec63746ff42299a (diff)
downloadqt-creator-18e6be55d7260a6f21e0021d6eba7da002125ab2.tar.gz
CppTools: Tag incomplete semantic info
...in order to be able to full-rehighlight on the next turn. The following sequence was problematic: 1. recalculateSemanticInfoDetached(true) * e.g. triggered by opening the document 2. recalculateSemanticInfoDetached(false) * e.g. triggered by moving the cursor * cancels 1. and leads to incompletely parsed/checked document - OK 3. startHighlighting() * triggered by 1.; starts highlighting on incomplete document - OK 4. startHighlighting() * gets a completely parsed/checked document - OK * not forced, so just compare revisions; they are the same, so skip/return - a partly highlighted document is left behind. Task-number: QTCREATORBUG-11367 Change-Id: Ic56e00e862ec4a1ffa197b2fc8b48be56a3562de Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
-rw-r--r--src/plugins/cpptools/cppsemanticinfo.cpp2
-rw-r--r--src/plugins/cpptools/cppsemanticinfo.h1
-rw-r--r--src/plugins/cpptools/cpptoolseditorsupport.cpp32
-rw-r--r--src/plugins/cpptools/cpptoolseditorsupport.h19
4 files changed, 34 insertions, 20 deletions
diff --git a/src/plugins/cpptools/cppsemanticinfo.cpp b/src/plugins/cpptools/cppsemanticinfo.cpp
index 1607251074..09407681c3 100644
--- a/src/plugins/cpptools/cppsemanticinfo.cpp
+++ b/src/plugins/cpptools/cppsemanticinfo.cpp
@@ -32,6 +32,6 @@
using namespace CppTools;
SemanticInfo::SemanticInfo()
- : revision(0), forced(false)
+ : revision(0), forced(false), complete(true)
{
}
diff --git a/src/plugins/cpptools/cppsemanticinfo.h b/src/plugins/cpptools/cppsemanticinfo.h
index f67e8717a0..c0968edb3a 100644
--- a/src/plugins/cpptools/cppsemanticinfo.h
+++ b/src/plugins/cpptools/cppsemanticinfo.h
@@ -79,6 +79,7 @@ public:
unsigned revision;
bool forced;
+ bool complete;
CPlusPlus::Snapshot snapshot;
CPlusPlus::Document::Ptr doc;
LocalUseMap localUses;
diff --git a/src/plugins/cpptools/cpptoolseditorsupport.cpp b/src/plugins/cpptools/cpptoolseditorsupport.cpp
index 084f4822e9..4a6f4351e9 100644
--- a/src/plugins/cpptools/cpptoolseditorsupport.cpp
+++ b/src/plugins/cpptools/cpptoolseditorsupport.cpp
@@ -120,6 +120,7 @@ CppEditorSupport::CppEditorSupport(CppModelManager *modelManager, BaseTextEditor
, m_fileIsBeingReloaded(false)
, m_initialized(false)
, m_lastHighlightRevision(0)
+ , m_lastHighlightOnCompleteSemanticInfo(true)
, m_highlightingSupport(modelManager->highlightingSupport(textEditor))
, m_completionAssistProvider(m_modelManager->completionAssistProvider(textEditor))
{
@@ -368,6 +369,7 @@ void CppEditorSupport::startHighlighting()
Document::Ptr doc;
unsigned revision;
bool forced;
+ bool complete;
{
QMutexLocker locker(&m_lastSemanticInfoLock);
@@ -375,16 +377,22 @@ void CppEditorSupport::startHighlighting()
doc = m_lastSemanticInfo.doc;
revision = m_lastSemanticInfo.revision;
forced = m_lastSemanticInfo.forced;
+ complete = m_lastSemanticInfo.complete;
}
if (doc.isNull())
return;
+
+ if (!m_lastHighlightOnCompleteSemanticInfo)
+ forced = true;
+
if (!forced && m_lastHighlightRevision == revision)
return;
- m_highlighter.cancel();
+ m_highlighter.cancel();
m_highlighter = m_highlightingSupport->highlightingFuture(doc, snapshot);
m_lastHighlightRevision = revision;
+ m_lastHighlightOnCompleteSemanticInfo = complete;
emit highlighterStarted(&m_highlighter, m_lastHighlightRevision);
} else {
const unsigned revision = currentSource(false).revision;
@@ -501,6 +509,7 @@ void CppEditorSupport::releaseResources()
snapshotUpdater()->releaseSnapshot();
QMutexLocker semanticLocker(&m_lastSemanticInfoLock);
m_lastSemanticInfo = SemanticInfo();
+ m_lastHighlightOnCompleteSemanticInfo = true;
}
SemanticInfo::Source CppEditorSupport::currentSource(bool force)
@@ -521,7 +530,7 @@ SemanticInfo::Source CppEditorSupport::currentSource(bool force)
void CppEditorSupport::recalculateSemanticInfoNow(const SemanticInfo::Source &source,
bool emitSignalWhenFinished,
- TopLevelDeclarationProcessor *processor)
+ FuturizedTopLevelDeclarationProcessor *processor)
{
SemanticInfo semanticInfo;
@@ -547,6 +556,8 @@ void CppEditorSupport::recalculateSemanticInfoNow(const SemanticInfo::Source &so
if (processor)
doc->control()->setTopLevelDeclarationProcessor(processor);
doc->check();
+ if (processor && processor->isCanceled())
+ semanticInfo.complete = false;
semanticInfo.doc = doc;
} else {
return;
@@ -576,21 +587,8 @@ void CppEditorSupport::recalculateSemanticInfoNow(const SemanticInfo::Source &so
void CppEditorSupport::recalculateSemanticInfoDetached_helper(QFutureInterface<void> &future, SemanticInfo::Source source)
{
- class TLDProc: public TopLevelDeclarationProcessor
- {
- QFutureInterface<void> m_theFuture;
-
- public:
- TLDProc(QFutureInterface<void> &aFuture): m_theFuture(aFuture) {}
- virtual ~TLDProc() {}
- virtual bool processDeclaration(DeclarationAST *ast) {
- Q_UNUSED(ast);
- return !m_theFuture.isCanceled();
- }
- };
-
- TLDProc tldProc(future);
- recalculateSemanticInfoNow(source, true, &tldProc);
+ FuturizedTopLevelDeclarationProcessor processor(future);
+ recalculateSemanticInfoNow(source, true, &processor);
}
void CppEditorSupport::onMimeTypeChanged()
diff --git a/src/plugins/cpptools/cpptoolseditorsupport.h b/src/plugins/cpptools/cpptoolseditorsupport.h
index 278c3a78f4..b4f950712d 100644
--- a/src/plugins/cpptools/cpptoolseditorsupport.h
+++ b/src/plugins/cpptools/cpptoolseditorsupport.h
@@ -35,6 +35,7 @@
#include "cppsemanticinfo.h"
#include "cppsnapshotupdater.h"
+#include <cplusplus/Control.h>
#include <cplusplus/CppDocument.h>
#include <QFuture>
@@ -43,7 +44,10 @@
#include <QSharedPointer>
#include <QTimer>
-namespace CPlusPlus { class AST; }
+namespace CPlusPlus {
+class AST;
+class DeclarationAST;
+} // namespace CPlusPlus
namespace TextEditor {
class BaseTextEditor;
@@ -171,9 +175,19 @@ private:
};
private:
+ class FuturizedTopLevelDeclarationProcessor: public CPlusPlus::TopLevelDeclarationProcessor
+ {
+ public:
+ FuturizedTopLevelDeclarationProcessor(QFutureInterface<void> &future): m_future(future) {}
+ bool processDeclaration(CPlusPlus::DeclarationAST *) { return !isCanceled(); }
+ bool isCanceled() { return m_future.isCanceled(); }
+ private:
+ QFutureInterface<void> m_future;
+ };
+
SemanticInfo::Source currentSource(bool force);
void recalculateSemanticInfoNow(const SemanticInfo::Source &source, bool emitSignalWhenFinished,
- CPlusPlus::TopLevelDeclarationProcessor *processor = 0);
+ FuturizedTopLevelDeclarationProcessor *processor = 0);
void recalculateSemanticInfoDetached_helper(QFutureInterface<void> &future,
SemanticInfo::Source source);
@@ -209,6 +223,7 @@ private:
// Highlighting:
unsigned m_lastHighlightRevision;
+ bool m_lastHighlightOnCompleteSemanticInfo;
QFuture<TextEditor::HighlightingResult> m_highlighter;
QScopedPointer<CppTools::CppHighlightingSupport> m_highlightingSupport;