Commit 76ebb464 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Fixed: "Follow symbol" on constructor or destructor always jumps to class definition

Task-number: QTCREATORBUG-1776
parent d209bd72
......@@ -703,25 +703,17 @@ public:
};
} // end of anonymous namespace
Symbol *Snapshot::findMatchingDefinition(Symbol *symbol) const
Symbol *Snapshot::findMatchingDefinition(Symbol *declaration) const
{
if (! symbol->identifier())
if (! (declaration && declaration->identifier()))
return 0;
Document::Ptr thisDocument = document(QString::fromUtf8(symbol->fileName(), symbol->fileNameLength()));
Document::Ptr thisDocument = document(QString::fromUtf8(declaration->fileName(), declaration->fileNameLength()));
if (! thisDocument) {
qWarning() << "undefined document:" << symbol->fileName();
qWarning() << "undefined document:" << declaration->fileName();
return 0;
}
LookupContext thisContext(thisDocument, *this);
const QList<Symbol *> declarationCandidates = thisContext.lookup(symbol->name(), symbol->scope());
if (declarationCandidates.isEmpty()) {
qWarning() << "unresolved declaration:" << symbol->fileName() << symbol->line() << symbol->column();
return 0;
}
Symbol *declaration = declarationCandidates.first();
Function *declarationTy = declaration->type()->asFunctionType();
if (! declarationTy) {
qWarning() << "not a function:" << declaration->fileName() << declaration->line() << declaration->column();
......
......@@ -1238,7 +1238,20 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor,
const QList<LookupItem> resolvedSymbols = typeOfExpression(expression, scope, TypeOfExpression::Preprocess);
if (!resolvedSymbols.isEmpty()) {
const LookupItem result = skipForwardDeclarations(resolvedSymbols);
LookupItem result = skipForwardDeclarations(resolvedSymbols);
foreach (const LookupItem &r, resolvedSymbols) {
if (Symbol *d = r.declaration()) {
if (d->isDeclaration() || d->isFunction()) {
if (file()->fileName() == QString::fromUtf8(d->fileName(), d->fileNameLength())) {
if (unsigned(line) == d->line() && unsigned(column) >= d->column()) { // ### TODO: check the end
result = r; // take the symbol under cursor.
break;
}
}
}
}
}
if (Symbol *symbol = result.declaration()) {
Symbol *def = 0;
......
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