OSDN Git Service

Fixed the refactoring engine.
authorRoberto Raggi <roberto.raggi@nokia.com>
Thu, 15 Oct 2009 10:30:27 +0000 (12:30 +0200)
committerRoberto Raggi <roberto.raggi@nokia.com>
Thu, 15 Oct 2009 10:31:40 +0000 (12:31 +0200)
It was not working for files opened while indexing the project.

src/plugins/cppeditor/cppeditor.cpp
src/plugins/cppeditor/cppeditor.h

index a9f9ea9..c3942e5 100644 (file)
@@ -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;
index 68159ee..f3489d8 100644 (file)
@@ -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;
 };