diff options
author | Leandro Melo <leandro.melo@nokia.com> | 2011-11-08 14:26:05 +0100 |
---|---|---|
committer | Leandro Melo <leandro.melo@nokia.com> | 2011-11-08 15:11:44 +0100 |
commit | 36deb6b060d1b553bbb2aede573581464f57e031 (patch) | |
tree | f8556927ee855c5a7da6f2fc2f84197c26d33626 | |
parent | e465a1763b652dc8afa5348001af48e5d6e7fc00 (diff) | |
download | qt-creator-36deb6b060d1b553bbb2aede573581464f57e031.tar.gz |
C++: Fix navigation for macros
Task-number: QTCREATORBUG-6399
Change-Id: Ic259d6cfed10e650d2eb7e07bdfacbc9038e51d0
Reviewed-by: Christian Kamm <christian.d.kamm@nokia.com>
-rw-r--r-- | src/plugins/cppeditor/cppeditor.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index f5ac04be13..088b6d1241 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -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; |