CppEditor: Allow force highlighting if using clang

...so we can rehighlight if it's requested by the editor. This is e.g.
necessary if the font size changes.

Task-number: QTCREATORBUG-11502
Change-Id: I608921899fc37fcf1394db9ff041e6b378196bdd
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
Nikolai Kosjar
2014-03-11 14:00:57 -03:00
parent 18e6be55d7
commit cbf98ba819
3 changed files with 22 additions and 11 deletions

View File

@@ -1591,8 +1591,12 @@ bool CPPEditorWidget::openCppEditorAt(const Link &link, bool inNextSplit)
void CPPEditorWidget::semanticRehighlight(bool force) void CPPEditorWidget::semanticRehighlight(bool force)
{ {
if (m_modelManager) if (m_modelManager) {
m_modelManager->cppEditorSupport(editor())->recalculateSemanticInfoDetached(force); const CppEditorSupport::ForceReason forceReason = force
? CppEditorSupport::ForceDueEditorRequest
: CppEditorSupport::NoForce;
m_modelManager->cppEditorSupport(editor())->recalculateSemanticInfoDetached(forceReason);
}
} }
void CPPEditorWidget::highlighterStarted(QFuture<TextEditor::HighlightingResult> *highlighter, void CPPEditorWidget::highlighterStarted(QFuture<TextEditor::HighlightingResult> *highlighter,

View File

@@ -237,7 +237,7 @@ Document::Ptr CppEditorSupport::lastSemanticInfoDocument() const
return m_lastSemanticInfo.doc; return m_lastSemanticInfo.doc;
} }
void CppEditorSupport::recalculateSemanticInfoDetached(bool force) void CppEditorSupport::recalculateSemanticInfoDetached(ForceReason forceReason)
{ {
// Block premature calculation caused by CppEditorPlugin::currentEditorChanged // Block premature calculation caused by CppEditorPlugin::currentEditorChanged
// when the editor is created. // when the editor is created.
@@ -245,12 +245,13 @@ void CppEditorSupport::recalculateSemanticInfoDetached(bool force)
return; return;
m_futureSemanticInfo.cancel(); m_futureSemanticInfo.cancel();
const bool force = forceReason != NoForce;
SemanticInfo::Source source = currentSource(force); SemanticInfo::Source source = currentSource(force);
m_futureSemanticInfo = QtConcurrent::run<CppEditorSupport, void>( m_futureSemanticInfo = QtConcurrent::run<CppEditorSupport, void>(
&CppEditorSupport::recalculateSemanticInfoDetached_helper, this, source); &CppEditorSupport::recalculateSemanticInfoDetached_helper, this, source);
if (force && m_highlightingSupport && !m_highlightingSupport->requiresSemanticInfo()) if (force && m_highlightingSupport && !m_highlightingSupport->requiresSemanticInfo())
startHighlighting(); startHighlighting(forceReason);
} }
CppCompletionAssistProvider *CppEditorSupport::completionAssistProvider() const CppCompletionAssistProvider *CppEditorSupport::completionAssistProvider() const
@@ -352,14 +353,14 @@ void CppEditorSupport::onDocumentUpdated(Document::Ptr doc)
|| m_lastSemanticInfo.doc->translationUnit()->ast() == 0 || m_lastSemanticInfo.doc->translationUnit()->ast() == 0
|| m_lastSemanticInfo.doc->fileName() != fileName()))) { || m_lastSemanticInfo.doc->fileName() != fileName()))) {
m_initialized = true; m_initialized = true;
recalculateSemanticInfoDetached(/* force = */ true); recalculateSemanticInfoDetached(ForceDueToMissingSemanticInfo);
} }
// notify the editor that the document is updated // notify the editor that the document is updated
emit documentUpdated(); emit documentUpdated();
} }
void CppEditorSupport::startHighlighting() void CppEditorSupport::startHighlighting(ForceReason forceReason)
{ {
if (!m_highlightingSupport) if (!m_highlightingSupport)
return; return;
@@ -395,8 +396,8 @@ void CppEditorSupport::startHighlighting()
m_lastHighlightOnCompleteSemanticInfo = complete; m_lastHighlightOnCompleteSemanticInfo = complete;
emit highlighterStarted(&m_highlighter, m_lastHighlightRevision); emit highlighterStarted(&m_highlighter, m_lastHighlightRevision);
} else { } else {
const unsigned revision = currentSource(false).revision; const unsigned revision = editorRevision();
if (m_lastHighlightRevision == revision) if (forceReason != ForceDueEditorRequest && m_lastHighlightRevision == revision)
return; return;
m_highlighter.cancel(); m_highlighter.cancel();

View File

@@ -119,11 +119,17 @@ public:
CPlusPlus::Document::Ptr lastSemanticInfoDocument() const; CPlusPlus::Document::Ptr lastSemanticInfoDocument() const;
enum ForceReason {
NoForce,
ForceDueToMissingSemanticInfo,
ForceDueEditorRequest
};
/// Recalculates the semantic info in a future, and will emit the /// Recalculates the semantic info in a future, and will emit the
/// semanticInfoUpdated() signal when finished. /// semanticInfoUpdated() signal when finished.
/// Requires that initialized() is true. /// Requires that initialized() is true.
/// \param force do not check if the old semantic info is still valid /// \param forceReason the reason to force, if any
void recalculateSemanticInfoDetached(bool force = false); void recalculateSemanticInfoDetached(ForceReason forceReason);
CppCompletionAssistProvider *completionAssistProvider() const; CppCompletionAssistProvider *completionAssistProvider() const;
@@ -148,7 +154,7 @@ private slots:
void updateDocumentNow(); void updateDocumentNow();
void onDocumentUpdated(CPlusPlus::Document::Ptr doc); void onDocumentUpdated(CPlusPlus::Document::Ptr doc);
void startHighlighting(); void startHighlighting(ForceReason forceReason = NoForce);
void onDiagnosticsChanged(); void onDiagnosticsChanged();