forked from qt-creator/qt-creator
CppEditor: Fix the lookUpDefinition() function
... that tells us whether we need to offer the "add #include" quickfix. If we encounter a forward declaration, we cannot return yet, as a proper declaration might still show up. Fixes: QTCREATORBUG-29883 Change-Id: Ie1b831b9414043c3fc0d5d1e914b6096957757e6 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -1953,25 +1953,30 @@ LookupResult lookUpDefinition(const CppQuickFixInterface &interface, const NameA
|
|||||||
// Try to find the class/template definition
|
// Try to find the class/template definition
|
||||||
const Name *name = nameAst->name;
|
const Name *name = nameAst->name;
|
||||||
const QList<LookupItem> results = interface.context().lookup(name, scope);
|
const QList<LookupItem> results = interface.context().lookup(name, scope);
|
||||||
|
LookupResult best = LookupResult::NotDeclared;
|
||||||
for (const LookupItem &item : results) {
|
for (const LookupItem &item : results) {
|
||||||
if (Symbol *declaration = item.declaration()) {
|
if (Symbol *declaration = item.declaration()) {
|
||||||
if (declaration->asClass())
|
if (declaration->asClass())
|
||||||
return LookupResult::Declared;
|
return LookupResult::Declared;
|
||||||
if (declaration->asForwardClassDeclaration())
|
if (declaration->asForwardClassDeclaration()) {
|
||||||
return LookupResult::ForwardDeclared;
|
best = LookupResult::ForwardDeclared;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (Template *templ = declaration->asTemplate()) {
|
if (Template *templ = declaration->asTemplate()) {
|
||||||
if (Symbol *declaration = templ->declaration()) {
|
if (Symbol *declaration = templ->declaration()) {
|
||||||
if (declaration->asClass())
|
if (declaration->asClass())
|
||||||
return LookupResult::Declared;
|
return LookupResult::Declared;
|
||||||
if (declaration->asForwardClassDeclaration())
|
if (declaration->asForwardClassDeclaration()) {
|
||||||
return LookupResult::ForwardDeclared;
|
best = LookupResult::ForwardDeclared;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return LookupResult::Declared;
|
return LookupResult::Declared;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return LookupResult::NotDeclared;
|
return best;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString templateNameAsString(const TemplateNameId *templateName)
|
QString templateNameAsString(const TemplateNameId *templateName)
|
||||||
|
Reference in New Issue
Block a user