forked from qt-creator/qt-creator
Fixed the refactoring engine.
It was not working for files opened while indexing the project.
This commit is contained in:
@@ -549,6 +549,7 @@ CPPEditor::CPPEditor(QWidget *parent)
|
|||||||
, m_inRename(false)
|
, m_inRename(false)
|
||||||
, m_allowSkippingOfBlockEnd(false)
|
, m_allowSkippingOfBlockEnd(false)
|
||||||
{
|
{
|
||||||
|
m_initialized = false;
|
||||||
qRegisterMetaType<SemanticInfo>("SemanticInfo");
|
qRegisterMetaType<SemanticInfo>("SemanticInfo");
|
||||||
|
|
||||||
m_semanticHighlighter = new SemanticHighlighter(this);
|
m_semanticHighlighter = new SemanticHighlighter(this);
|
||||||
@@ -700,6 +701,13 @@ void CPPEditor::onDocumentUpdated(Document::Ptr doc)
|
|||||||
if (doc->fileName() != file()->fileName())
|
if (doc->fileName() != file()->fileName())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (! m_initialized) {
|
||||||
|
m_initialized = true;
|
||||||
|
|
||||||
|
const SemanticHighlighter::Source source = currentSource(/*force = */ true);
|
||||||
|
m_semanticHighlighter->rehighlight(source);
|
||||||
|
}
|
||||||
|
|
||||||
m_overviewModel->rebuild(doc);
|
m_overviewModel->rebuild(doc);
|
||||||
OverviewTreeView *treeView = static_cast<OverviewTreeView *>(m_methodCombo->view());
|
OverviewTreeView *treeView = static_cast<OverviewTreeView *>(m_methodCombo->view());
|
||||||
treeView->sync();
|
treeView->sync();
|
||||||
@@ -1885,7 +1893,7 @@ void CPPEditor::updateSemanticInfo(const SemanticInfo &semanticInfo)
|
|||||||
setExtraSelections(CodeSemanticsSelection, allSelections);
|
setExtraSelections(CodeSemanticsSelection, allSelections);
|
||||||
}
|
}
|
||||||
|
|
||||||
SemanticHighlighter::Source CPPEditor::currentSource()
|
SemanticHighlighter::Source CPPEditor::currentSource(bool force)
|
||||||
{
|
{
|
||||||
int line = 0, column = 0;
|
int line = 0, column = 0;
|
||||||
convertPosition(position(), &line, &column);
|
convertPosition(position(), &line, &column);
|
||||||
@@ -1894,12 +1902,13 @@ SemanticHighlighter::Source CPPEditor::currentSource()
|
|||||||
const QString fileName = file()->fileName();
|
const QString fileName = file()->fileName();
|
||||||
|
|
||||||
QString code;
|
QString code;
|
||||||
if (m_lastSemanticInfo.revision != document()->revision())
|
if (force || m_lastSemanticInfo.revision != document()->revision())
|
||||||
code = toPlainText(); // get the source code only when needed.
|
code = toPlainText(); // get the source code only when needed.
|
||||||
|
|
||||||
const int revision = document()->revision();
|
const int revision = document()->revision();
|
||||||
const SemanticHighlighter::Source source(snapshot, fileName, code,
|
SemanticHighlighter::Source source(snapshot, fileName, code,
|
||||||
line, column, revision);
|
line, column, revision);
|
||||||
|
source.force = force;
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1974,14 +1983,14 @@ SemanticInfo SemanticHighlighter::semanticInfo(const Source &source)
|
|||||||
Snapshot snapshot;
|
Snapshot snapshot;
|
||||||
Document::Ptr doc;
|
Document::Ptr doc;
|
||||||
|
|
||||||
if (revision == source.revision) {
|
if (! source.force && revision == source.revision) {
|
||||||
m_mutex.lock();
|
m_mutex.lock();
|
||||||
snapshot = m_lastSemanticInfo.snapshot;
|
snapshot = m_lastSemanticInfo.snapshot;
|
||||||
doc = m_lastSemanticInfo.doc;
|
doc = m_lastSemanticInfo.doc;
|
||||||
m_mutex.unlock();
|
m_mutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!doc) {
|
if (! doc) {
|
||||||
const QByteArray preprocessedCode = source.snapshot.preprocessedCode(source.code, source.fileName);
|
const QByteArray preprocessedCode = source.snapshot.preprocessedCode(source.code, source.fileName);
|
||||||
|
|
||||||
snapshot = source.snapshot;
|
snapshot = source.snapshot;
|
||||||
|
|||||||
@@ -105,9 +105,10 @@ public:
|
|||||||
int line;
|
int line;
|
||||||
int column;
|
int column;
|
||||||
int revision;
|
int revision;
|
||||||
|
bool force;
|
||||||
|
|
||||||
Source()
|
Source()
|
||||||
: line(0), column(0), revision(0)
|
: line(0), column(0), revision(0), force(false)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
Source(const CPlusPlus::Snapshot &snapshot,
|
Source(const CPlusPlus::Snapshot &snapshot,
|
||||||
@@ -117,7 +118,7 @@ public:
|
|||||||
int revision)
|
int revision)
|
||||||
: snapshot(snapshot), fileName(fileName),
|
: snapshot(snapshot), fileName(fileName),
|
||||||
code(code), line(line), column(column),
|
code(code), line(line), column(column),
|
||||||
revision(revision)
|
revision(revision), force(false)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
void clear()
|
void clear()
|
||||||
@@ -128,6 +129,7 @@ public:
|
|||||||
line = 0;
|
line = 0;
|
||||||
column = 0;
|
column = 0;
|
||||||
revision = 0;
|
revision = 0;
|
||||||
|
force = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -240,7 +242,7 @@ private:
|
|||||||
TextEditor::ITextEditor *openCppEditorAt(const QString &fileName, int line,
|
TextEditor::ITextEditor *openCppEditorAt(const QString &fileName, int line,
|
||||||
int column = 0);
|
int column = 0);
|
||||||
|
|
||||||
SemanticHighlighter::Source currentSource();
|
SemanticHighlighter::Source currentSource(bool force = false);
|
||||||
|
|
||||||
void highlightUses(const QList<SemanticInfo::Use> &uses,
|
void highlightUses(const QList<SemanticInfo::Use> &uses,
|
||||||
QList<QTextEdit::ExtraSelection> *selections);
|
QList<QTextEdit::ExtraSelection> *selections);
|
||||||
@@ -285,6 +287,7 @@ private:
|
|||||||
|
|
||||||
SemanticHighlighter *m_semanticHighlighter;
|
SemanticHighlighter *m_semanticHighlighter;
|
||||||
SemanticInfo m_lastSemanticInfo;
|
SemanticInfo m_lastSemanticInfo;
|
||||||
|
bool m_initialized;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user