Commit f92b1428 authored by Roberto Raggi's avatar Roberto Raggi

Fixed the refactoring engine.

It was not working for files opened while indexing the project.
parent 8ad31cba
......@@ -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;
......
......@@ -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;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment