forked from qt-creator/qt-creator
CppTools: Also look up definitions for variables
... not just functions. This includes global variables and static members. Fixes: QTCREATORBUG-18828 Change-Id: Iee9f83a4f955a859c6fc4038c61997b30afdaec8 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -696,6 +696,7 @@ void CppEditorWidget::switchDeclarationDefinition(bool inNextSplit)
|
||||
// Find function declaration or definition under cursor
|
||||
Function *functionDefinitionSymbol = nullptr;
|
||||
Symbol *functionDeclarationSymbol = nullptr;
|
||||
Symbol *declarationSymbol = nullptr;
|
||||
|
||||
ASTPath astPathFinder(d->m_lastSemanticInfo.doc);
|
||||
const QList<AST *> astPath = astPathFinder(textCursor());
|
||||
@@ -707,9 +708,12 @@ void CppEditorWidget::switchDeclarationDefinition(bool inNextSplit)
|
||||
} else if (SimpleDeclarationAST *simpleDeclaration = ast->asSimpleDeclaration()) {
|
||||
if (List<Symbol *> *symbols = simpleDeclaration->symbols) {
|
||||
if (Symbol *symbol = symbols->value) {
|
||||
if (symbol->isDeclaration() && symbol->type()->isFunctionType()) {
|
||||
functionDeclarationSymbol = symbol;
|
||||
break; // Function declaration found!
|
||||
if (symbol->isDeclaration()) {
|
||||
declarationSymbol = symbol;
|
||||
if (symbol->type()->isFunctionType()) {
|
||||
functionDeclarationSymbol = symbol;
|
||||
break; // Function declaration found!
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -723,6 +727,11 @@ void CppEditorWidget::switchDeclarationDefinition(bool inNextSplit)
|
||||
->findMatchingDefinition(functionDeclarationSymbol, d->m_modelManager->snapshot());
|
||||
if (symbol)
|
||||
symbolLink = symbol->toLink();
|
||||
} else if (declarationSymbol) {
|
||||
Symbol *symbol = d->m_modelManager->symbolFinder()
|
||||
->findMatchingVarDefinition(declarationSymbol, d->m_modelManager->snapshot());
|
||||
if (symbol)
|
||||
symbolLink = symbol->toLink();
|
||||
} else if (functionDefinitionSymbol) {
|
||||
const Snapshot snapshot = d->m_modelManager->snapshot();
|
||||
LookupContext context(d->m_lastSemanticInfo.doc, snapshot);
|
||||
|
||||
Reference in New Issue
Block a user