diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index a9f9ea958823f676433aa0571273dfa5416a6f00..c3942e5794b0f0d73f57e33b8c645476d4246531 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -549,6 +549,7 @@ CPPEditor::CPPEditor(QWidget *parent) , m_inRename(false) , m_allowSkippingOfBlockEnd(false) { + m_initialized = false; qRegisterMetaType<SemanticInfo>("SemanticInfo"); m_semanticHighlighter = new SemanticHighlighter(this); @@ -700,6 +701,13 @@ void CPPEditor::onDocumentUpdated(Document::Ptr doc) if (doc->fileName() != file()->fileName()) return; + if (! m_initialized) { + m_initialized = true; + + const SemanticHighlighter::Source source = currentSource(/*force = */ true); + m_semanticHighlighter->rehighlight(source); + } + m_overviewModel->rebuild(doc); OverviewTreeView *treeView = static_cast<OverviewTreeView *>(m_methodCombo->view()); treeView->sync(); @@ -1885,7 +1893,7 @@ void CPPEditor::updateSemanticInfo(const SemanticInfo &semanticInfo) setExtraSelections(CodeSemanticsSelection, allSelections); } -SemanticHighlighter::Source CPPEditor::currentSource() +SemanticHighlighter::Source CPPEditor::currentSource(bool force) { int line = 0, column = 0; convertPosition(position(), &line, &column); @@ -1894,12 +1902,13 @@ SemanticHighlighter::Source CPPEditor::currentSource() const QString fileName = file()->fileName(); QString code; - if (m_lastSemanticInfo.revision != document()->revision()) + if (force || m_lastSemanticInfo.revision != document()->revision()) code = toPlainText(); // get the source code only when needed. const int revision = document()->revision(); - const SemanticHighlighter::Source source(snapshot, fileName, code, - line, column, revision); + SemanticHighlighter::Source source(snapshot, fileName, code, + line, column, revision); + source.force = force; return source; } @@ -1974,14 +1983,14 @@ SemanticInfo SemanticHighlighter::semanticInfo(const Source &source) Snapshot snapshot; Document::Ptr doc; - if (revision == source.revision) { + if (! source.force && revision == source.revision) { m_mutex.lock(); snapshot = m_lastSemanticInfo.snapshot; doc = m_lastSemanticInfo.doc; m_mutex.unlock(); } - if (!doc) { + if (! doc) { const QByteArray preprocessedCode = source.snapshot.preprocessedCode(source.code, source.fileName); snapshot = source.snapshot; diff --git a/src/plugins/cppeditor/cppeditor.h b/src/plugins/cppeditor/cppeditor.h index 68159ee9100dbcb828c695f6d5feb16ddb71ce35..f3489d8b99806ea347ad54577a9ee755972b32c0 100644 --- a/src/plugins/cppeditor/cppeditor.h +++ b/src/plugins/cppeditor/cppeditor.h @@ -105,9 +105,10 @@ public: int line; int column; int revision; + bool force; Source() - : line(0), column(0), revision(0) + : line(0), column(0), revision(0), force(false) { } Source(const CPlusPlus::Snapshot &snapshot, @@ -117,7 +118,7 @@ public: int revision) : snapshot(snapshot), fileName(fileName), code(code), line(line), column(column), - revision(revision) + revision(revision), force(false) { } void clear() @@ -128,6 +129,7 @@ public: line = 0; column = 0; revision = 0; + force = false; } }; @@ -240,7 +242,7 @@ private: TextEditor::ITextEditor *openCppEditorAt(const QString &fileName, int line, int column = 0); - SemanticHighlighter::Source currentSource(); + SemanticHighlighter::Source currentSource(bool force = false); void highlightUses(const QList<SemanticInfo::Use> &uses, QList<QTextEdit::ExtraSelection> *selections); @@ -285,6 +287,7 @@ private: SemanticHighlighter *m_semanticHighlighter; SemanticInfo m_lastSemanticInfo; + bool m_initialized; };