C++: Fix navigation for macros

Task-number: QTCREATORBUG-6399

Change-Id: Ic259d6cfed10e650d2eb7e07bdfacbc9038e51d0
Reviewed-by: Christian Kamm <christian.d.kamm@nokia.com>
This commit is contained in:
Leandro Melo
2011-11-08 14:26:05 +01:00
parent e465a1763b
commit 36deb6b060

View File

@@ -1225,12 +1225,6 @@ CPPEditorWidget::Link CPPEditorWidget::findLinkAt(const QTextCursor &cursor,
return link;
const Snapshot &snapshot = m_modelManager->snapshot();
Document::Ptr doc = m_lastSemanticInfo.doc;
if (!doc) {
doc = snapshot.document(file()->fileName());
if (!doc)
return link;
}
QTextCursor tc = cursor;
QChar ch = characterAt(tc.position());
@@ -1239,17 +1233,28 @@ CPPEditorWidget::Link CPPEditorWidget::findLinkAt(const QTextCursor &cursor,
ch = characterAt(tc.position());
}
if (doc->translationUnit() && doc->translationUnit()->ast()) {
// Initially try to macth decl/def. For this we need the semantic doc with the AST.
if (m_lastSemanticInfo.doc
&& m_lastSemanticInfo.doc->translationUnit()
&& m_lastSemanticInfo.doc->translationUnit()->ast()) {
int pos = tc.position();
while (characterAt(pos).isSpace())
++pos;
if (characterAt(pos) == QLatin1Char('(')) {
link = attemptFuncDeclDef(cursor, doc, snapshot);
link = attemptFuncDeclDef(cursor, m_lastSemanticInfo.doc, snapshot);
if (link.isValid())
return link;
}
}
// Now we prefer the doc from the snapshot with macros expanded.
Document::Ptr doc = snapshot.document(file()->fileName());
if (!doc) {
doc = m_lastSemanticInfo.doc;
if (!doc)
return link;
}
int lineNumber = 0, positionInBlock = 0;
convertPosition(cursor.position(), &lineNumber, &positionInBlock);
const unsigned line = lineNumber;